【问题标题】:css media query didn't workCSS媒体查询不起作用
【发布时间】:2013-05-30 10:51:34
【问题描述】:

我想让我的博客具有响应性,但我的媒体查询效果不佳。 css 代码在最大宽度 600px 下工作,但它不适用于较小的宽度。 这是css代码(最大宽度:600px);

@media only screen and (max-width: 600px) {
.container{
    height:100%;
}

#header{
    max-height:162px;
}

#header #logo{
    padding-bottom: 63px;
}


.nav {
max-width:599px;
position: relative;
float:center;
padding-bottom:120px;
top:159px;
left:-60px;
min-height: 40px;
padding-top:0;
} 

.nav ul {
/*width: 599px;*/
padding: 5px 0;
position: absolute;
/*top: -13px;
left: -95px;*/
border: solid 1px #2FB8C8;
background: #2FB8C8 url(../images/icon-menu.png) no-repeat 10px 11px;
}

.nav li {
display: none; /* hide all <li> items */
margin: 0;
opacity:0.8;
}

.nav .current {
display: block; /* show only current <li> item */
}

.nav a {
display: block;
padding: 5px 5px 5px 32px;
text-align: left;
width:599px;
}

.nav .current a {
background: none;
color: #666;
}

/* on nav hover */
.nav ul:hover {
opacity:1;
}

.nav ul:hover li {
display: block;
margin: 0 0 5px;
}

.nav ul:hover .current {
background: url(../images/icon-check.png) no-repeat 10px 7px;
}

/* right nav */
.nav.right ul {
left: auto;
right: 0;
}

/* center nav */
.nav.center ul {
left: 50%;
margin-left: -90px;
}

.end-post-right{
font-family:'RobotoLight' ;
display:block;
width:400px;
/*padding-left:10px;*/
font-weight:normal;
letter-spacing: 0.8px;
}

.end-post-right li{
display:block;
margin-right: 15px;
float:left;
}

.end-post-right li p{
font-size:100%;
}

.end-post-right span{
font-size:100%;
}
}

这是另一个不起作用的媒体查询的示例。我在 iphone 5 上试了试;

/* Iphone <5 */
@media screen and (device-aspect-ratio: 2/3) {
.end-post-right{
font-family:'RobotoLight' ;
display:block;
/*width:400px;
padding-left:10px;*/
font-weight:normal;
letter-spacing: 0.8px;
}

.end-post-right li{
display:block;
/*margin-right: 15px;*/
float:left;
}

.end-post-right li p{
font-size:100%;
}

.end-post-right span{
font-size:100%;
}
}

提前感谢您的帮助

【问题讨论】:

    标签: css responsive-design media-queries


    【解决方案1】:

    在head 部分下添加此代码。

    &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;

    【讨论】:

      【解决方案2】:

      尝试将您的移动 css 和桌面 css 文件分开。然后,将此链接包含在 head 标签中...

      <link rel="stylesheet" href="style/desktop.css" type="text/css" media="screen,tv" />
      <link rel='stylesheet' href='style/mobile.css' media='only screen and (min-width: 240px) and (max-width: 959px)' />
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-09
        • 1970-01-01
        • 2013-08-14
        • 2015-09-06
        • 2013-03-12
        • 2013-03-01
        • 2021-12-08
        相关资源
        最近更新 更多