css中垂直居中的div
我想居中对齐css中垂直居中的div,css,Css,我想居中对齐#容器以下代码: <div id="container"> <p>new</p> </div> 它没有正确对齐内容的中心,请帮助我。您想要一个100%的div和一个具有特定宽度和边距的子对象0 auto #主体{ 宽度:100%; } #容器{ 宽度:100px; 背景:红色; 填充:10px; 余量:0自动;/*用于定心*/ } p{ 文本对齐:居中; } 新的 试试这个- #container { position
#容器
以下代码:
<div id="container">
<p>new</p>
</div>
它没有正确对齐内容的中心,请帮助我。您想要一个100%的div和一个具有特定宽度和边距的子对象0 auto
#主体{
宽度:100%;
}
#容器{
宽度:100px;
背景:红色;
填充:10px;
余量:0自动;/*用于定心*/
}
p{
文本对齐:居中;
}
新的
试试这个-
#container {
position:relative;
width:100%;
background:red;
padding:10px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
p {
text-align: center;
}
可能重复的
#container {
position:relative;
width:100%;
background:red;
padding:10px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
p {
text-align: center;
}