想知道是否有人可以帮助我我正在尝试在 HTML 页面上将一个 div 与另一个 div 居中。第一个 div 会很好地居中,但无论我如何处理父 div 中的 div,都不会在我的 CSS 中使用“margin:auto”居中。
下面是我的 HTML:-
<div class="jumbotron">
<div class="container">
</div>
</div>
这是我的 CSS:-
.jumbotron {
position: relative;
margin: 0 auto;
width: 1000px;
height: 600px;
background-color: #5a9a9a;
}
.jumbotron .container {
position: absolute;
margin: auto;
background-color: #5a5a5a;
width: 500px;
height: 500px;
}
最佳答案
从 .jumbotron .container
中移除 position: absolute;
这是一个JSFiddle进行演示。
关于html - margin : Auto wont work in HTML/CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31300594/