在个人网页设计项目上取得了进展,但我一直陷在section
的垂直居中p
标记中。以响应式方式垂直居中文本
https://jsfiddle.net/dowp4rv3/1/
我想这个部分里面的文字垂直居中,但我不希望失去任何响应。我已经尝试了一些可能的解决方案,但我一直在搞这个。你们有没有专家看到一个快速解决?
HTML
<div class="box">
<section>
<p>Some text</p>
</section>
</div>
CSS
body {
background-color: white;
margin: 0;
overflow: auto;
}
.box {
display: block;
float: left;
height: 100vh;
width: 100vw;
background-color: green;
position: relative;
}
.box section {
display: block;
text-align: center;
height: 20%;
width: 70%;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
border: solid .2em white;
}
.box section p {
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
position: absolute;
}
}
}
肯定有多余的CSS在那里(部分是由于从我拿了这一点的项目文物),但这个问题我有能可见。
哪来的问题,它的中心? – Johannes
我希望文本在节中垂直居中。所以距顶部和底部边界的距离相等。 – Inkidu616
啊对不起,我想过这个款本身... – Johannes