简体   繁体   English

CSS媒体查询未加载

[英]CSS Media Query Not Loading

I'm writing a static website and testing it locally. 我正在编写一个静态网站,并在本地对其进行测试。 I have written a media query to change the layout a little bit so that it is much nicer to look at on a smartphone. 我编写了一个媒体查询来稍微更改布局,以便在智能手机上查看效果更好。 With the media query my aim is to change the text and the profile photo from being side by side to being one followed by the other. 通过媒体查询,我的目标是将文字和个人资料照片从一个并排更改为一个接着一个。

My issue is that when I load the HTML file on Chrome or Firefox and resize the window, the layout does not change and I cannot figure out how to fix it. 我的问题是,当我在Chrome或Firefox上加载HTML文件并调整窗口大小时,布局不会更改,并且我不知道如何解决它。 Any help would be much appreciated. 任何帮助将非常感激。 Find my code below. 在下面找到我的代码。

For my standard CSS I have this (a small snippet): 对于我的标准CSS,我有以下内容(一个小片段):

#about-text {
    /*A div containing paragraphs and a table*/
    display: inline-block;
    width: 50%;
}

#profile-photo {
    /*An img tag after the closing about-text div*/
    border: 4px solid #1abc9c;
    display: inline;
    float: right;
    margin: 8% 0% 0% 0%;
    max-width: 40%;
}

And then I have a media query and the corresponding CSS: 然后我有一个媒体查询和相应的CSS:

@media (min-device-width : 320px) and (max-device-width : 480px) {

#about-text {
    /*A div containing paragraphs and a table*/
    display: block;
    width: 50%;
}

#profile-photo {
    /*An img tag after the closing about-text div*/
    border: 4px solid #1abc9c;
    display: block;
    float: right;
    margin: 8% 0% 0% 0%;
    max-width: 40%;
}
}

You are using min-device-width and max-device-width which only takes into the account the device's screen size. 您正在使用的最小设备宽度和最大设备宽度仅考虑了设备的屏幕尺寸。 Use min-width and max-width and it will work in your browser when you resize. 使用min-width和max-width,当您调整大小时,它将在您的浏览器中工作。

Example: 例:

.testDiv {
    color: green;
}

@media (min-width : 320px) and (max-width : 480px) {
    .testDiv {
       color: red;
   }
}

http://jsfiddle.net/ZUPD2/ http://jsfiddle.net/ZUPD2/

也许是因为媒体查询块没有结尾括号?

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

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