css - 为什么我的媒体查询不起作用?

标签 css media-queries

我尝试为移动设备和平板电脑创建媒体查询,当我使用普通浏览器时它们确实可以工作(在我的台式计算机上,我使屏幕变小),但当我使用普通浏览器时它们就不起作用实际的手机或平板电脑。我已经完成了 CSS 和 HTML 验证,所以我无法想象会是这样。

我的网站已在我的大学服务器上启动并运行,因此您可以从那里查看我的媒体查询:http://stc110.edu.csesalford.com/http://stc110.edu.csesalford.com/general.css

这些是我的媒体查询:

/*Styles for screen 600px and lower*/
@media handheld, screen and (max-width: 600px) {
    #navigation { 
        height: auto;
    }
    #navigation ul {
        width: 100%;
        display: block;
        height: auto;
    }
    #navigation li {
        width: 50%;
        float: left;
        position: relative;
    }
    #navigation li a {
        border-bottom: 1px solid #ff9999;
        border-right: 1px solid #ff9999;
    }
    #navigation a {
        text-align: left;
        width: 100%;
        text-indent: 25px;
    }
    header {
        padding-top: 30px; 
    }
}

/*Styles for screen 480px and lower*/
@media handheld, screen and (max-width : 480px) {
    #navigation {
        border-bottom: 0;
    }
    #navigation ul {
        display: none;
        height: auto;
    }
    #navigation a#pull {
        display: block;
        background-color: #ff6666;
        width: 100%;
        position: relative;
    }
    #navigation a#pull:after {
        content:"";
        background: url('images/nav-icon.png') no-repeat;
        width: 30px;
        height: 30px;
        display: inline-block;
        position: absolute;
        right: 15px;
        top: 10px;
    }
}

/*Smartphone*/
@media handheld {
    #navigation {
        border-bottom: 0;
    }
    #navigation ul {
        display: none;
        height: auto;
    }
    #navigation a#pull {
        display: block;
        background-color: #ff6666;
        width: 100%;
        position: relative;
    }
    #navigation a#pull:after {
        content:"";
        background: url('images/nav-icon.png') no-repeat;
        width: 30px;
        height: 30px;
        display: inline-block;
        position: absolute;
        right: 15px;
        top: 10px;
    }
}

最佳答案

请将以下代码放入头部

<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

关于css - 为什么我的媒体查询不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34589687/

相关文章:

css - "@media (min-width: 900px)"是看浏览器宽度还是显示器宽度?

html - 区分媒体查询中的纵向和横向版本

html - CSS 媒体查询(媒体屏幕)

css - 媒体查询仅在多浏览器的响应模式下有效

css - 媒体查询样式不覆盖原始样式

html - Chrome 复制文本尽管使用 "-webkit-user-select: none"

html - 水平导航栏中的不均匀列表元素。列表元素高度不同

javascript - 将所有 CSS 规则解析为 JavaScript 中内存文档的内联样式?

html - 流体布局 : aside element larger than main element

css - 在我使用 Inspect Element 之前,Chrome 中不显示文本