Cra*_*ard 6 html css css-float centering fluid-layout
我有一个想要使用的布局的想法,但我不能让它正常工作.我希望这里有人可以提供帮助,因为我花了几个小时搜索.
布局就是这样.
一个包装div包含6个儿童div.这些孩子的div一定是在集中所有的时间,无论包装div的大小.
<html>
<head>
<title>Testing</title>
<style>
br.clear { clear:both; display:block; height:1px; margin:-1px 0 0 0; }
#wrapper { max-width: 960px; min-width: 320px; background: #444; margin: 0 auto; }
.box { width: 280px; padding: 10px; margin:10px; height: 260px; border: 0px; float: left; background: #fff; }
</style>
</head>
<body>
<div id="wrapper">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<br class="clear" />
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
问题是当浏览器调整得更小并且一个方框被撞到框下面的线上时会向左下方,而我希望它们始终居中.这可能是使用纯CSS还是我需要使用一些jquery?
小智 6
可能最简单的解决方案是,如果从框中删除float:left样式并将display属性更改为inline-block.然后你需要做的就是文本对齐:在包装器上居中.
<html>
<head>
<title>Testing</title>
<style>
br.clear { clear:both; display:block; height:1px; margin:-1px 0 0 0; }
#wrapper { max-width: 960px; min-width: 320px; background: #444; margin: 0 auto; text-align:center }
.box { width: 280px; padding: 10px; margin:10px; height: 260px; border: 0px; background: #fff; display:inline-block }
</style>
</head>
<body>
<div id="wrapper">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<br class="clear" />
</div>
</body>
Run Code Online (Sandbox Code Playgroud)
您可以在此处测试代码:http: //jsbin.com/uqamu4/edit