0

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
hsz
  • 136,835
  • 55
  • 236
  • 297
niksos
  • 229
  • 1
  • 3
  • 7
  • 1
    Possible duplicate: http://stackoverflow.com/questions/1504459/getting-the-screen-resolution-using-php – unicorn80 Oct 09 '13 at 10:50

3 Answers3

1

PHP can't get screen width because there is no screen for PHP :) It only executes on server and returns HTML to the browser, so PHP got no direct contact with browser.

Elon Than
  • 8,984
  • 4
  • 22
  • 37
0

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.

acairns
  • 475
  • 3
  • 12
0

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+)

Pankucins
  • 1,670
  • 1
  • 16
  • 25