【发布时间】:2020-12-29 22:28:37
【问题描述】:
所以我已经在<header> 部分创建了一个导航栏,并在我的网站上创建了一个页脚。我的<main> 部分中还有一个<div class="UUDiv">,其中包含一个段落和一个标题。现在,我想将<div class="UUDiv"> 水平和垂直居中,但只在主要部分。使用下面的代码,我只将它集中在整个页面的中心,所以我的 Div 与我的页脚重叠......这是我的代码:\
html {
height: 100%;
}
body {
margin: 0;
min-height: 100%;
display: flex;
flex-direction: column;
}
.UUDiv {
text-align: center;
position: absolute;
right: 50%;
bottom: 50%;
transform: translate(50%, 50%);
}
<header class="RestHeader">
<nav class="navigation">Navigation...with
<ul>
<li> List </li>
</ul>etc.</nav>
</header>
<main>
<div class="UUDiv">
<h1>Headline</h1>
<p>Text</p>
</div>
</main>
<footer>
<div class="footer">Footer...with
<ul>
<li> Another List </li>
</ul> etc.</div>
</footer>
感谢您的帮助!
【问题讨论】:
-
如果你使用
position: absolute,你也需要设置页脚的位置 -
@RicardoPontual 好的,我尝试将页脚相对定位,但它就在我的主要内容之上。我也尝试定位我的
相对位置,但随后内容走出了我的窗口......我的窗口顶部只有几行......这有点奇怪,我是 html 和 css 的新手所以我真的不知道该怎么办。