gpt4 book ai didi

css - 试图将容器 div 中的 div 居中

转载 作者:太空宇宙 更新时间:2023-11-03 23:42:45 25 4
gpt4 key购买 nike

这是我的 CSS:

#main {
background: #eae8dc;
margin: 0 auto;
width: 790px;
height: 900px;
position: relative;
display: block;
}
#header-container {
display: inline-block;
height: 118px;
width: 648px;
background: #9ed5de;
margin: 11px auto;
}

这是 HTML

<div id="main">
<header>
<h1 id="header-container">
</h1>
</header>
</div>

这个问题有助于解决我的边距问题,但现在我似乎无法将标题容器居中。 Why does this CSS margin-top style not work?

最佳答案

Text-align 应该可以帮助您将其居中:

#main {
background: #eae8dc;
margin: 0 auto;
width: 790px;
height: 900px;
position: relative;
display: block;
text-align: center;
}
#header-container {
display: inline-block;
height: 118px;
width: 648px;
background: #9ed5de;
margin: 11px auto;
}

这是 JS fiddle http://jsfiddle.net/RBkmv/

关于css - 试图将容器 div 中的 div 居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22397169/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com