css - Media Queries for Ratio not triggering -
i trying test ratio media queries:
for example:
@media screen , (min-aspect-ratio: 8/5) { ... }
see full code:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title></title> <style type="text/css"> .mq { border: 2px solid; padding: 20px; width: 300px; resize: both; overflow: auto; } @media screen , (min-aspect-ratio: 8/5) { .mq { background-color: red; } } </style> </head> <body> <div class="mq"> text here. div can resized. </div> </body> </html>
the problem code above supposed go red when ratio 18/5 it's red.
what wrong code?
your code fine, css says need ratio of @ least 8/5, if drag screen size around should see change when window taller wide.
if want have effect div, not window, you'll need handle javascript instead of media query.
var $div = $('.mq'); $div.change(function() { if ($div.width() / $div.height() < 1.6) { $div.css('background-color', 'white') } else { $div.css('background-color', 'red') } });
Comments
Post a Comment