我正在尝试做的应该是这样的:
...但是我的inner_top
div(带有红色背景)不是 水平居中的,最终看起来像这样:
冲突似乎display: inline-block'
在inner_top
div 上使用,这就是出现的情况使它垂直居中,除了两个 div 之间的奇怪间距。
这是我的代码:
<!DOCTYPE html>
<html>
<head>
<title>
CSS sucks!!!
</title>
<style type = "text/css">
#outer {
width: 250px;
height: 500px;
border: 5px solid black;
/* for vertically-centering inner divs: */
display: table-cell;
vertical-align: middle;
}
#inner_top {
width: 75px;
height: 175px;
background-color: red;
/* horizontally-centered: */
margin: 0 auto;
/* vertically-center both this and the bottom div:
(but now horizontal-alignment doesn't work on this div!) */
display: inline-block;
}
#inner_bottom {
width: 150px;
height: 150px;
background-color: blue;
/* horizontally-centered: */
margin: 0 auto;
}
</style>
</head>
<body>
<div id = "outer">
<div id = "inner_top">
</div> <!-- end of inner top -->
<div id = "inner_bottom">
</div> <!-- end of inner_bottom -->
</div> <!-- end of outer div -->
</body>
</html>