雖然很多帖子我搜索了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