【发布时间】:2018-05-02 05:09:05
【问题描述】:
我正在尝试垂直对齐两个 div 中的文本。我已经尝试了许多在这里找到的解决方案,但都没有产生所需的结果。
我已经制作了一个 sjFiddle:
#outer {
position: relative;
}
#inner1 {
position: absolute;
align-items: center;
top: 10%;
bottom: 10%;
width: 100%;
height: 40%;
}
#inner2 {
position: absolute;
align-items: center;
top: 50%;
bottom: 10%;
width: 100%;
height: 40%;
}
html,
body {
height: 100%;
}
#outer {
background-color: purple;
width: 50%;
height: 50%;
}
#inner1 {
background-color: yellow;
}
#inner2 {
background-color: red;
}
<div id="outer">
<div id="inner1">
Test text 1
</div>
<div id="inner2">
Test text 1
</div>
</div>
任何人都可以根据我的小提琴中的代码看到我如何做到这一点。 非常感谢您抽出宝贵时间。
【问题讨论】:
标签: html css flexbox centering