【发布时间】:2011-06-26 05:11:25
【问题描述】:
我这里有一个工作代码:http://jsfiddle.net/WVm5d/(您可能需要将结果窗口放大才能看到居中对齐效果)
问题
代码运行良好,但我不喜欢display: table;。这是我可以使 wrap-class 对齐中心的唯一方法。我认为如果有办法使用display: block; 或display: inline-block; 会更好。是否可以通过其他方式解决对齐中心问题?
给容器添加一个固定的 with 不是我的选择。
如果将来 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>
【问题讨论】:
标签: css