PHP if语句屏幕宽度 [英] PHP if-statement screen width

查看:285
本文介绍了PHP if语句屏幕宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查屏幕宽度是否高于1024像素,设置侧边栏+ 50px

I want to check if the screen width is higher than 1024 pixels, to set sidebar + 50px

我尝试了这段代码(但侧边栏没有加载1024 +):

I tried this piece of code (but the sidebar doesnt load on 1024+):

<?php $arjunaOptions = arjuna_get_options(); ?>
<?php
//calculate sidebar and content area ratio
if ($arjunaOptions['sidebarDisplay'] != 'none') {
    $available = 920;
    $available2 = 970;
    $contentArea = $arjunaOptions['contentAreaWidth'];
    $sidebar = $available - $contentArea;
    $sidebarlarge = $available2 - $contentArea ;
    $sidebarLeftRight = floor(($sidebar - 50) / 2);

    print '<style type="text/css">
    @media screen and (max-width: 1024px) {
    .contentWrapper .contentArea {width:'.$contentArea.'px;}
    .contentWrapper .sidebars {width:'.$sidebar.'px;}
    .contentWrapper .sidebarLeft, .contentWrapper .sidebarRight {width:'.$sidebarLeftRight.'px;}  
    }

    @media screen and (min-width: 1025px) {
    .contentWrapper .contentArea {width:'.$contentArea.'px;}
    .contentWrapper .sidebars {width:'.$sidebarlarge.'px;}
    .contentWrapper .sidebarLeft, .contentWrapper .sidebarRight {width:'.$sidebarLeftRight.'px;}
    }

    </style>';

}
?>


推荐答案

您不应该在PHP中动态执行此操作,因为PHP没有屏幕大小的概念(没有客户端cookie或类似的东西的帮助)。

You should not be doing this dynamically in PHP, since PHP has no concept of the size of the screen (without help from client side cookies or something similar).

你应该使用CSS媒体查询。例如:

You should use a CSS media query for this. For example:

@media screen and (max-width: 1024px) {
  /* CSS for up to 1024px width */   
}

@media screen and (min-width: 1025px) {
  /* CSS for over 1024px width */
}

您还可以使用javascript修改元素的CSS属性。事实上,您的示例似乎尝试在PHP中使用jQuery语法,这当然不起作用。

You can also use javascript to modify the CSS properties of an element. In fact your example seems to try to use jQuery syntax in PHP, which of course won't work.

这篇关于PHP if语句屏幕宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆