【发布时间】:2016-08-26 17:02:57
【问题描述】:
我需要将一个没有宽度的 div 元素居中(它的宽度来自内部 div。
<html>
<head>
<title></title>
<style type="text/css">
.outer {
padding: 10px;
/*margin: auto; (doesn´t work)*/
background-color: #000;
display: inline-block;
}
.inner {
width: 400px;
height: 400px;
text-align: center;
background-color: #CCC;
}
</style>
</head>
<body>
<div class="outer">
<div class="inner"></div>
</div>
</body>
</html>
任何想法如何在不设置宽度的情况下解决此问题?
【问题讨论】:
-
body { text-align: center }