我有这样的结构:
<style>
#main{
max-width: 500px;
margin: 0 auto;
overflow: hidden;
border: 1px solid red;
}
#container{
margin-right: -50px;
}
.block{
display: inline-block;
width: 100px;
height: 100px;
border: 1px solid grey;
margin-right: 30px;
}
</style>
<div id="main">
<div id="container">
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
</div>
</div>如果我有宽的,它看起来像http://i.stack.imgur.com/3I1yM.png,它是可以的。
但是如果我使用窄的,它很糟糕,我需要内部区块对齐到中心,就像这样
发布于 2013-11-29 22:10:33
您好,这里需要的是属性text-align:center
#container{
margin-right: -50px;
text-align:center;
}演示
发布于 2013-11-29 22:45:52
那这个呢?
删除块的边距,用户文本对齐对齐和添加单词间距,如果你想在最后一行为你的块一些固定的空间。
#container {
letter-spacing: 10px; //word-spacing: 10px; //to space blocks on last row
text-align: justify; //to align everything to the borders on the first lines
padding: 0px 10px; //to separate the blocks from the borders a little
}
.block {
margin-right: 0px;
}当宽度太小并且每行只适合一个块时,它看起来是错误的,但也许你需要一些媒体查询来使你的css响应在那个特殊情况下解决这个问题。
编辑:跨浏览器http://jsfiddle.net/ALR8P/5/使用字母间距效果更好,您可能需要字母间距: 30px;因为您的边距是30px
https://stackoverflow.com/questions/20287488
复制相似问题