I have a responsive website and I need some PHP conditions depending on the windows width (or media queries).
Example:
if ($window_width > 1400px) {
echo 'Your window is wider than 1400px';
}
elseif ($window_width > 1000px) AND ($window_width < 1399px) {
echo 'Your window is between 1000px and 1399px';
}
else {
echo 'Your window is narrower than 1000px.';
}
Thanks for your help!
Setting a particular "width-range" isn't any different from the way media queries are created. The only difference is the addition of more media feature expressions (that is, the screen width sizes). Take a look: @media only screen and (min-width: 360px) and (max-width: 768px) { // do something in this width range. }
Combining media query expressions Max-width and min-width can be used together to target a specific range of screen sizes. @media only screen and (max-width: 600px) and (min-width: 400px) {...} The query above will trigger only for screens that are 600-400px wide.
They cannot be used to refer to a certain element on a page. If you need to apply styles depending on the size of a certain div element on your page, you'll have to use JavaScript to observe changes in the size of that div element instead of media queries.
The @media rule is used in media queries to apply different styles for different media types/devices. Media queries can be used to check many things, such as: width and height of the viewport. width and height of the device. orientation (is the tablet/phone in landscape or portrait mode?)
check this
Goolgle Mobile Detect
Try to use http://www.php.net/get_browser and check for isMobileDevice field. It might help only, of course, if the path to browscap.ini is set up in php.ini. If not, you can use php classes like https://github.com/garetjax/phpbrowscap
Nope you can not do it with php. php is strictly server side
user javascript instead. Below is my code to get device resolution using javascript
<script>
screenWidth = window.screen.width,
screenHeight = window.screen.height;
console.log(screenWidth);
console.log(screenHeight);
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With