Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My media query doesn't work on my android device

My media query works fine in pc's browser when i re-size it, but when i access my website through localhost with my android device, my media query doesn't work? What can the problem be? My device has 480 x 800 pixels resolutions.

Here is my media query:

@media (max-width: 480px) {
#main{width:90%;position:relative;}
div.itemRelated ul li {float: left;width: 20%;}
div.itemRelated ul li a img{width:90%;}
div.itemRelated ul li a{text-align:center;}
.maincontent{width:90%;font-size:.7em;}
#base{width:100%;}
h2, h2 a:link, h2 a:visited{font-size:.7em;}
#container_header{width:96%;}
#container_slideshow{display:none;}
#container_main{width:90%;margin: 0 auto;}
.wrapper960{margin:0 auto;}/*ova treba da se cepne*/
#sidecol_b, #sidecol_a{display:none;}
#content_remainder{width:96%;clear:both;top:0;}
#container_bottom_modules{display:none;}
#container_spacer3{display:none;}
#jazik{float:left;}
.sigProContainer sigProClassic sigProClassic{margin-left:10%;}
#hornav{padding-left:5px;}
#hornav ul li a{font-size:1em;padding: 0 5px;width:8%}
#container_header{width:100%;}
#socialmedia{display:none;}
#search {clear:both;top: 20%;left: 15%;}
.content{width:66%;}
}
like image 624
Worker123 Avatar asked Nov 30 '22 13:11

Worker123


2 Answers

The width of Android devices is often not the actual screensize. If you want to have the width of the screen you need a viewport meta tag.

 <meta id="viewport" name="viewport" content ="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />

Use this meta tag in your HTML

Update:

The code above also disables the scaling (zooming), which is not nice for users. So you can do it without disabling scaling to:

<meta id="viewport" name="viewport" content ="width=device-width" />
like image 60
Felix G. Avatar answered Dec 10 '22 07:12

Felix G.


If you are specifically targeting android device, or any device with 480x800 try this

@media only screen and (min-device-width: 480px) {
  /* Style goes here */
}

A pretty good article if you like to read

like image 21
Mr. Alien Avatar answered Dec 10 '22 06:12

Mr. Alien