html - Writing media queries for mobile devices, low-res desktop and hi-res desktop -
this question has answer here:
i'm using both screen width , screen height detect difference between mobile , desktops , detect high resolution desktops vs. low resolution desktops.
i have javascript use load different css files. looks this:
javascript
<script> if (screen.width > 800) { if (screen.height < 900) { document.write('<link href="/lowres.css" type="text/css" />'); } else { document.write('<link href="/hires.css" type="text/css" />'); } } else { document.write('<meta name="viewport" content="width=device-width,initial-scale=1">'); document.write('<link href="/mobile.css" type="text/css" />'); } </script>
i want change , use media queries, , have:
css
<link media="screen , (min-device-width: 801px) , (min-device-width: 801px)" href="low.css" rel="stylesheet" /> <link media="screen , (min-device-height: 901px)" href="hi.css" rel="stylesheet" /> <link media="screen , (max-device-width: 800px) , (orientation : portrait), screen , (max-device-height: 800px) , (orientation : landscape)" href="mobile.css" rel="stylesheet" />
this allows mobile stylesheet downloaded regardless of orientation. however, desktop stylesheet set hi-res if it's low-res.
as can see, i've got desktop mode on height 800px, media query set min-device-height:901px
, yet it's downloading hi-res stylesheet. why that?
thanks.
include css files <head>
. alternatively, can combine them single css file.
<meta name="viewport" content="width=device-width,initial-scale=1"> <link href="/mobile.css" type="text/css" /> <link href="/lowres.css" type="text/css" /> <link href="/hires.css" type="text/css" />
then change files wrapping contents media queries.
@media (max-width: 800px) { // contents of mobile.css } @media (min-width: 801px) , (max-height:900px) { // contents of lowres.css } @media (min-width: 801px) , (min-height:901px) { // contents of hires.css }
take here css media queries. alternative use nested media queries old browsers might not support them.
Comments
Post a Comment