【发布时间】:2016-03-17 22:11:27
【问题描述】:
大家好,我制作了一个包含几个 div 和背景图片的简单网页。基本上,如果设备的宽度较小,我希望背景图像消失。
但是当我将浏览器的宽度最小化到小于 500 像素时,媒体查询仅适用于 firefox 而不适用于 chrome。
另外,http://pastebin.com/TZ1UwVmK 是代码的链接。您可以将背景图片替换为https://s3.amazonaws.com/codecademy-content/projects/broadway/bg.png。
enter code here
<code><pre>
<!DOCTYPE html>
<html>
<head>
<link href='https://fonts.googleapis.com/css?family=Raleway:400, 600' rel='stylesheet' type='text/css' />
<link href='testnew1.css' rel='stylesheet' type='text/css' />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <!-- used to give phones a background in place of image that doesn't show up for unknown reason -->
<style>
.container-in-headerdiv { max-width: 940px;
.container-in-headerdiv { max-width: 940px;
margin: 0 auto;
padding: 0 10px;}
.header {background-color: #333333;}
.nav{list-style-type:none;
margin:0;
padding: 20px 0;}
.jumbotron { background: url('images/projectbroadway-pic.png') no-repeat center center;
background-color: #333333; /* gives lavender color if image doesn't load */
background-size: cover;
height:800px;} /* not centered, or positioned except its properties as a div under normal flow */
@media (max-width: 500px) { /* relies on viewport to give width, gives lavender color if image doesnt load */
.jumbotron{
background-image:none;
background: #E6E6FA;
background-size: cover;
height:800px;}
}
}
.container-in-jumbotron{max-width: 940px;
margin: 0 auto;
padding: 0 10px;}
.main { position: relative; /* this class not working at all atm */
top: 180px;
text-align: center;}
.btn-main{ background-color: #333333;
color:#ffffff;
font-family: 'Raleway', sans-serif;
font-weight: 600;
font-size: 18px;
letter-spacing: 1.3px;
padding: 16px 40px;
text-transform: uppercase;
}
</style>
</head>
<body>
<div class="header">
<div class="container-in-headerdiv">
<ul class="nav">
<li>About</li>
<li>Work</li>
<li>Team</li>
<li>Contact</li>
</ul>
</div>
</div>
<div class="jumbotron">
<div class="container-in-jumbotron">
<div class="main">
<h1>We are Broadway</h1>
<a class="btn-main" href="#">Get started</a>
</div>
</div>
</div>
</body>
</html>
</pre></code>
【问题讨论】:
标签: html css width device viewport