gpt4 book ai didi

html - 垂直放置div?

转载 作者:行者123 更新时间:2023-11-28 01:57:05 25 4
gpt4 key购买 nike

大家好,我想将 .mission-banner 移动到 .mission div 的垂直中心。但是 margin: auto 0; 不会工作,而且 flex-box 也不会。那么我在这里没有看到什么?

html {
font-family: Helvetica;
font-size: 22px;
color: seashell;
background-color: black;
opacity: 0.9;
text-align: center;
}

header {
display: flex;
align-items: center;
justify-content: space-between;
height: 69px;
border-bottom: 1px solid seashell;
position: fixed;
width: 100%;
}

img {
height: 50px;
padding-left: 10px;
}

nav span {
color: seashell;
padding-right: 30px;
}

.mission-banner {
background-color: black;
}

.mission-banner h4 {
padding-bottom: 10px;
}

a {
cursor: pointer;
text-decoration-color: seashell;
}

.mission {
background-image: url(../images/img-mission-background.jpg);
position: relative;
margin: 0 auto;
top: 70px;
width: 1200px;
height: 700px;
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Tea Cozy | Home</title>
<link rel="stylesheet" href="./resources/css/style.css">
</head>
<body>
<header>
<img src="./resources/images/img-tea-cozy-logo.png" alt="our logo">
<nav>
<a href="#"><span>Mission</span></a>
<a href="#"><span>Featured Tea</span></a>
<a href="#"><span>Locations</span></a>
</nav>
</header>
<!-- main-content -->
<div class="mission">
<div class="mission-banner">
<h2>Our Mission</h2>
<h4>Handpicked, Artisanally Curated, Free Range, Sustainable, Small Batch, Fair Trade, Organic Tea</h4>
</div>
</div>

</body>
</html>

这是它的样子 rn: enter image description here

最佳答案

问题是您为任务和相对定位设置了固定的高度/宽度。您还需要为任务横幅设置固定高度,以将其定位在页面中央。

对于所有这一切可能有更技术性的解释,但很快我就能够通过以下 css 实现我相信你正在寻找的东西。您可能需要稍微调整一下才能完全按照您的需要调整,尤其是当您添加更多内容时任务横幅的高度:

    .mission {
background-image: url(../images/img-mission-background.jpg);
position: absolute;
top: 70px;
width: 100%;
height: 100%;
}
.mission-banner {
margin: auto;
top: 0;
bottom: 0;
left: 0;
right: 0;
position: absolute;
height: 200px;
background-color: black;
}

关于html - 垂直放置div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49562501/

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