我有一個為# background div設置的背景色。然后添加了一些顯示:網格到其他部分和背景顏色現在已經消失了。我的css仍然有# background元素,顏色也被選擇了,但是當我更新的時候它沒有出現在我的服務器上。有人能幫忙嗎?
@import url("https://fonts.google.com/");
div {
max-width: 1600px;
margin: 0 auto;
}
nav {
display: flex;
justify-content: space-around;
}
nav a {
text-align: center;
color: #00b4d8;
text-decoration: none;
padding: 35px;
}
nav a:hover {
background-color: black;
color: #00b4d8
}
.home-title {
background-color: #03045e;
color: white;
font-family: 'Merriweather', serif;
font-size: 2em;
margin-top: 10px;
}
h4 {
background-color: #03045e;
color: white;
}
#hero {
display: grid;
grid-template-columns: 1fr 3fr 1fr;
}
#hero-img {
width: 100%;
}
#hero-box {
grid-column: 1/4;
grid-row: 1/3;
}
#hero-msg h1,
#hero-msg h4 {
text-align: center;
}
#hero-msg {
grid-column: 2/3;
grid-row: 1/2;
}
.logo {
width: 80px;
}
#logo_link {
padding-top: 5px;
justify-self: center;
align-self: center;
}
.icon {
width: 80px;
padding-top: 10px;
}
.button-box {
text-align: center;
}
.home-grid {
display: grid;
grid-template-columns: repeat(10, 1fr);
}
main section {
text-align: center;
}
main section img {
box-sizing: border-box;
}
body {
background-color: white;
font-size: 22px;
margin: 0;
padding: 0;
}
h2 {
margin: 0;
}
header {
background-color: #03045e;
display: grid;
grid-template-columns: 150px auto;
}
.book,
.join {
background-color: #0077b6;
color: white;
text-decoration: none;
font-size: 18px;
padding: 15px 30px;
margin-top: 50px;
border-radius: 5px;
}
.book:hover,
.join:hover {
background-color: black;
color: #00b4d8;
}
.rivers-card,
.camping-card,
.rapids-card {
margin: 200px 0;
}
.rivers-card {
grid-column: 2/4;
grid-row: 2/3;
}
.camping-card {
grid-column: 5/7;
grid-row: 2/3;
}
.rapids-card {
grid-column: 8/10;
grid-row: 2/3;
}
.mountains {
width: 100%;
grid-column: 2/7;
grid-row: 5/8;
box-shadow: 5px 5px 10px #00b4d8;
}
.card-img {
width: 100%;
border: 10px solid black;
transition: transform .5s;
box-shadow: 5px 5px 10px #00b4d8;
}
.card-img:hover {
opacity: .6;
transform: scale(1.1);
}
#background {
height: 725px;
background-color: #0077b6;
grid-column: 1/11;
grid-row: 4/9;
}
.msg {
background-color: #03045e;
line-height: 1.5em;
padding: 35px;
grid-column: 6/10;
grid-row: 6/7;
box-shadow: 5px 5px 10px #00b4d8;
}
.msg h2 {
color: #00b4d8;
font-family: 'Roboto', serif;
}
.msg p {
color: #00b4d8;
font-size: .8em;
padding-bottom: 15px;
}
footer {
background-color: #03045e;
color: #00b4d8;
padding: 25px 50px;
margin-top: 200px;
display: flex;
justify-content: space-around;
align-items: center;
}
footer .social img {
padding-top: 15px;
}
footer p {
font-size: 1.2em;
padding: 25px;
}
footer p a:hover {
text-decoration: underline;
}
footer a {
color: #00b4d8;
text-decoration: none;
}
footer a:hover {
background-color: black;
color: #00b4d8;
}
@media screen and (max-width: 900px) {
#hero,
.home-grid {
display: block;
height: auto;
}
nav,
footer {
flex-direction: column;
}
nav a {
display: block;
padding: 15px;
}
#hero {
margin-top: 0;
}
#hero-msg {
margin-top: 0;
}
#hero-msg h4 {
display: none;
}
.home-title {
font-size: 25px;
color: #6f7364;
}
.rivers-card,
.camping-card,
.rapids-card {
margin: 50px auto;
width: 60%;
}
#background {
display: none;
}
.mountains,
.msg {
width: 80%;
display: block;
margin: 0 auto;
}
footer {
margin-top: 25px;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="preconnect" >
<link rel="preconnect" crossorigin>
<link rel="stylesheet">
<link rel="stylesheet" href="styles/style.css">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Whitewater Rafting Gathering | Dry Oar Boating | Home </title>
</head>
<body>
<div id="content">
<header>
<a id="logo_link" href="index.html">
<img class="logo" src="images/logo.png" alt="Dry Oar Logo">
</a>
<nav>
<a href="index.html">Home</a>
<a href="#">Page 2</a>
<a href="site-plan-rafting.html">Site Plan</a>
<a href="contactus.html">Contact Us</a>
</nav>
</header>
<div id="hero">
<div id="hero-box">
<img id="hero-img" src="images/hero.png" alt="People enjoying white water rafting">
</div>
<section id="hero-msg">
<h1 class="home-title">Have An Adventure</h1>
<h4>Make Memories with Dry Oar </h4>
<div class='button-box'>
<a class='book' href="contactus.html">Book Now</a>
</div>
</section>
</div>
<main class="home-grid">
<section class="rivers-card">
<img class="card-img" src="images/rivers.jpeg" alt="river in forest">
<img class="icon" src="images/river_icon.png" alt="river icon">
<h2>Rivers</h2>
</section>
<section class="camping-card">
<img class="card-img" src="images/camping.jpeg" alt="tent in mountains">
<img class="icon" src="images/fire_icon.png" alt="fire icon">
<h2>Camping</h2>
</section>
<section class="rapids-card">
<img class="card-img" src="images/rapids.jpeg" alt="rafting boat">
<img class="icon" src="images/oars.png" alt="oars icon">
<h2>Rapids</h2>
</section>
<div id="background"></div>
<img class="mountains" src="images/mountains.jpeg" alt="Misty mountains">
<section class="msg">
<h2>More Than Just The Thrill</h2>
<p>Enjoy the breathtaking scenery. From valleys, meadows, canyons, and high peaks; it's way more than just the rapids. It's a great way to get away from it all and relax amongst all the beauty of the great outdoors. </p>
<a class='join' href="rivers.html">Join Us</a>
</section>
</main>
<footer>
<p>Dry Oar © 2023 - Isileli Fiefia</p>
<p><a href="site-plan-rafting.html">Site Plan</a></p>
<p><a href="contactus.html">Contact Us</a></p>
<div class="social">
<a target="_blank">
<img src="images/facebook.png" alt="fb icon">
</a>
<a target="_blank">
<img src="images/twitter.png" alt="twitter icon">
</a>
<a target="_blank">
<img src="images/instagram.png" alt="instagram icon">
</a>
</div>
</footer>
</div>
</body>
</html>
你需要給你的元素增加一個寬度,這樣它就會占據網站的空間。
試試這個:
#background {
height: 725px;
width: 100%;
background-color: #0077b6;
grid-column: 1/11;
grid-row: 4/9;
}
還要記住,你是在用
#background {
display: none;
}
在@media屏幕上和(最大寬度:900像素)