[英]How to center in div without text-align?
如何在不使用text-align:center
情况下将wrapper
方块text-align:center
?
我需要这个,因为它也将所有文本都放在正方形中,但我不需要这个。
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 square *宽度为1平方))/ #of square + 1 - >(960-(250 * 3))/ 4
#wrapper{
...
padding-left:52px;
}
.square {
...
margin: 10px 52px 10px 0;
}
你可以试试:
.squares {
margin-left:auto;
margin-right:auto;
}
由于它是正方形内的文本,因此您可以在文本周围放置H
或P
标记,然后使用text-align: left;
他们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.