如何在不使用 text-align:center
的情况下使 wrapper
中的方 block 居中?
我需要这个,因为它还会将所有文本置于正方形的中心,但我不需要这个。
HTML:
<div id="wrapper">
<div id="squares">
<div class="square">lol</div>
<div class="square">lol</div>
<div class="square">lol</div>
<div class="square">lol</div>
<div class="square">lol</div>
<div class="square">lol</div>
<div class="square">lol</div>
</div>
</div>
CSS:
html, body{
height: 100%;
}
body {
line-height: 18px;
}
#wrapper{
width: 960px;
height: 100%;
border: 1px solid red;
margin: 0 auto;
}
.square {
width:251px;
height:207px;
border: 1px solid #d6d6d6;
-webkit-box-shadow: 1px 1px 3px rgba(0,0,0,.1);
-moz-box-shadow: 1px 1px 3px rgba(0,0,0,.1);
box-shadow: 1px 1px 3px rgba(0,0,0,.1);
margin: 10px;
overflow:hidden;
position:relative;
background-color:#fff;
display: inline-block;
cursor: pointer;
}
最佳答案
#wrapper{
...
text-align: center;
}
.square {
...
text-align: left;
}
---- 另一种方式(我不推荐!)
如何找到 52px: (div 的宽度 - (#of squares * 一个正方形的宽度))/#of squares+1 -> (960-(250*3))/4
#wrapper{
...
padding-left:52px;
}
.square {
...
margin: 10px 52px 10px 0;
}
关于html - 如何在没有文本对齐的情况下在 div 中居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14031740/