层不确定宽度,怎么让他在父层中居中呢?
b层不确定宽
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>无标题文档</title>
</head>
<style type="text/css">
.a{ width:1000px; text-align:center;}
.b{ background:red; width:50px; height:50px; margin:0 auto;}
</style>
<body>
<div class="a">
<div class="b"></div>
</div>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>无标题文档</title>
</head>
<style type="text/css">
.a{ width:1000px; text-align:center;border:1px solid;}
.b{ background:red; display:inline-block;max-width:800px; height:50px; margin:0 auto;border:1px solid;}
</style>
<body>
<div class="a">
<div class="b">我是B层的内容哦!</div>
</div>
</body>
</html>