简体   繁体   English

刷新浏览器窗口后,css媒体样式不起作用

[英]css media styles does not work after browser window was refreshed

#wrap {
    background: white;
    margin: 20px 15px;
    padding: 10px;  
}
@media screen and (max-width: 600px) {
    #wrap {
        margin: 0;
        padding: 0
    }
}

These styles seems to be working if I open new browser window and try to resize it. 如果我打开新的浏览器窗口并尝试调整其大小,则这些样式似乎有效。 But if I refresh windows once then @media does not work. 但是,如果我刷新一次Windows,则@media无法正常工作。 Then I need to close the browser and open it againe to open the same site to re-enable @media styles. 然后,我需要关闭浏览器并再次打开它,以打开同一站点以重新启用@media样式。 What is going on here? 这里发生了什么?

@media only screen and (max-width: 600px) {
    #wrap {
        margin: 0;
        padding: 0
    }
}

I find it works best when you have the word "ONLY" in the media query. 当您在媒体查询中使用单词“仅”时,我发现它的效果最佳。 Heres an example of the bootstrap media queries. 这是引导媒体查询的示例。

https://scotch.io/tutorials/default-sizes-for-twitter-bootstraps-media-queries https://scotch.io/tutorials/default-sizes-for-twitter-bootstraps-media-queries

If that doesnt work try a hard refresh to clear your browser cache. 如果这样不起作用,请尝试进行强制刷新以清除浏览器缓存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM