gpt4 book ai didi

html - 媒体查询不会在 chrome 上的简单网站中工作,但在 firefox 中可以

转载 作者:行者123 更新时间:2023-11-28 06:42:00 25 4
gpt4 key购买 nike

大家好,我用几个 div 和一个背景图片制作了一个简单的网页。基本上,如果设备的宽度较小,我希望背景图像消失。

但是当我将浏览器的宽度最小化到小于 500px 时,媒体查询仅适用于 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>

最佳答案

更新 jumbotron 的背景时使用的是 background 而不是 background-color:

.jumbotron{
background: #E6E6FA;
background-size: cover;
height:800px;
}

关于html - 媒体查询不会在 chrome 上的简单网站中工作,但在 firefox 中可以,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34232996/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com