Aut*_*umn 3 html css vertical-alignment
我尝试使用flexbox方法,表格方法和其他一些方法垂直居中一个未知高度的div,但我的div没有正确居中.我希望居中div的宽度为窗口宽度的50%或最小宽度为200px.
.content {
background-color: violet;
min-width: 200px;
width: 50%;
margin-left: auto;
margin-right: auto;
box-shadow: 0px 1px 7px 1px rgba(0, 0, 0, 1);
}
.outer-container {
display: table;
width: 100%;
background-color: violet;
}
.container {
display: table-cell;
text-align: center;
vertical-align: middle;
}Run Code Online (Sandbox Code Playgroud)
<body>
<div class="outer-container">
<div class="container">
<div class="content">
<div class="title-class">
Hello there
</div>
</div>
</div>
</div>
</body>Run Code Online (Sandbox Code Playgroud)
使用flexbox,这里是您需要的所有代码:
HTML
<div class="container">
<div class="content">
<div class="title-class">Hello there</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS
html, body { height: 100%; }
.container {
display: flex;
justify-content: center;
align-items: center;
background-color: violet;
height: 100%;
}
.content {
background-color: violet;
width: 50%;
text-align: center;
box-shadow: 0px 1px 7px 1px rgba(0, 0, 0, 1);
}
Run Code Online (Sandbox Code Playgroud)
作为替代方案,这是表方法:
| 归档时间: |
|
| 查看次数: |
1770 次 |
| 最近记录: |