CSS Media Query don't working in css file

人盡茶涼 提交于 2019-12-11 08:57:45

问题


Added this line in index.html:

 <link href="css/style.css" media="all  "rel="stylesheet" type="text/css" />

And this is my Media Query CSS:

    /* Smartphones (portrait and landscape) ----------- */
    @media only screen 
    and (min-device-width : 320px) 
    and (max-device-width : 480px) {
     #mapArea .white span {
        width: 100px;
     }

}

But when i check it in browser, don't working. What's my problem? How can i fix it?

(Tested all modern browsers)


回答1:


@media only screen has different definition with @media screen.

The keyword ‘only’ can also be used to hide style sheets from older user agents. User agents must process media queries starting with ‘only’ as if the ‘only’ keyword was not present.

Source: http://www.w3.org/TR/css3-mediaqueries/

Maybe you can try change into this:

@media screen and (min-width : 320px) and (max-width : 480px) {
  .white span {
      width: 100px;
  }
}



回答2:


You are querying for device-width, which if your on a laptop or desktop isn't going to fire those queries. Change those to min-width and you should see the query work.

Also, make sure you have a viewport meta tag i.e. <meta name="viewport" content="width=device-width,initial-scale=1.0"> in the <head> of your HTML.



来源:https://stackoverflow.com/questions/17208218/css-media-query-dont-working-in-css-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!