css媒体查询不起作用

时间:2013-06-04 06:25:30

标签: css responsive-design media-queries

我想让我的博客响应,但我的媒体查询效果不佳。 css代码在max-width 600px中工作,但它的工作宽度不是很小。 这是css代码(max-width: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%;
}
}

提前感谢您的帮助

2 个答案:

答案 0 :(得分:0)

head部分下添加此代码。

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

答案 1 :(得分:0)

尝试将移动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)' />
相关问题