2013-06-04 101 views
0

我想使我的博客響應,但我的媒體查詢不能正常工作。該CSS代碼工作在最大寬度600px,但它不工作在較小的寬度。 這是css代碼(max-width:600px);css媒體查詢不起作用

@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%; 
} 
} 

在此先感謝您的幫助

回答

0

添加下head部分的代碼。

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

0

儘量分開你的手機CSS和桌面CSS文件。然後,在頭標籤中包含此鏈接...

<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)' />