CSS中心显示内联块?
我在这里有一个工作代码:http://jsfiddle.net/WVm5d/(你可能需要让结果窗口更大才能看到对齐中心效果)
题
代码工作正常,但我不喜欢display: table;。这是我制作包装类对齐中心的唯一方法。我认为如果有一种方法可以使用display: block;或更好display: inline-block;。是否有可能以另一种方式解决对中中心?
添加固定的容器对我来说不是一个选择。
如果JS Fiddle链接在未来被破坏,我也会在此处粘贴我的代码:
body {
background: #bbb;}.wrap {
background: #aaa;
margin: 0 auto;
display: table;
overflow: hidden;}.sidebar {
width: 200px;
float: left;
background: #eee;}.container {
margin: 0 auto;
background: #ddd;
display: block;
float: left;
padding: 5px;}.box {
background: #eee;
border: 1px solid #ccc;
padding: 10px;
margin: 5px;
float: left;}.box:nth-child(3n+1) {
clear: left;}<div class="wrap"> <div class="sidebar"> Sidebar </div> <div class="container"> <div class="box"> Height1 </div> <div class="box"> Height2<br /> Height2 </div> <div class="box"> Height3<br /> Height3<br /> Height3 </div> <div class="box"> Height1 </div> <div class="box"> Height2<br /> Height2 </div> <div class="box"> Height3<br /> Height3<br /> Height3 </div> </div> <div class="sidebar"> Sidebar </div></div>
炎炎设计
哆啦的时光机
蓝山帝景
随时随地看视频慕课网APP