简体   繁体   中英

php screen width if else statement (no css)

Any idea how to achieve this? Basically I need different div widths for different devices (its complicated and cannot be achieved through css)

if screen width < 786 {

echo div.span3

} else {

echo div.span6

PHP无法获得屏幕宽度,因为没有适用于PHP的屏幕:)它仅在服务器上执行,并将HTML返回给浏览器,因此PHP没有与浏览器直接联系。

Elon Than is correct - PHP doesn't know anything about the browser widths. Maybe what you are looking to achieve can be done with media queries: http://css-tricks.com/css-media-queries/ ?

Maybe you could display both divs and toggle the display depending upon the screen width?

Hope this helps.

PHP is a server side language, it has no interaction with users browser whatsoever.

Look into JavaScript to achieve what you're trying to do. It can detect screen width, and you can manipulate DOM with it to show the content that is needed.

If browser backwards compatibility is not important look into CSS media queries . (I am not really sure about the browser support, but I reckon it's IE9+)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM