虽然很多帖子我搜索了Stackoverflow,但我没有找到解决方案。使用margin的CSS边距折叠:auto;
我想垂直对齐我的文本,使用margin:auto;
似乎有一种缘崩溃的问题,如果你想查询这个例子:
// HTML
<div class="outer">
<div class="inner">Hello</div>
</div>
<div class="outer2">
<div class="inner">Trying to center this text vertically</div>
</div>
// CSS
.inner {
margin: auto 0;
height: 20px;
color: white;
}
.outer {
background-color: red;
}
.outer2 {
background-color: blue;
height: 200px;
}
If you want to play on my code, click here