我有以下HTML:
<div id="hasToBeAbsolute">
<a></a>
<a></a>
<a></a>
</div>
样式如下:
#hasToBeAbsolute {
position: absolute;
display: table;
margin: 10px auto 0;
}
#hasToBeAbsolute a {
background: rgba(200, 200, 200, 0.8);
margin-left: 10px;
width: 12px;
display: block;
float: left;
height: 12px;
font-size: 0;
border-radius: 50%;
}
我想将div“like this
中的3”a“标签居中但是我有以下限制:
这可能吗?
答案 0 :(得分:1)
将此添加到您的代码中它将起作用:
#hasToBeAbsolute {
...
left: 0;
right: 0;
margin-left: auto;
margin-right: auto;
width: 100px;
}
(您也可以选择较小的宽度)
演示:http://codepen.io/anon/pen/jWVbQy
来自:https://stackoverflow.com/a/8273750/4339170
没有固定width
的其他选项:
#hasToBeAbsolute {
...
left: 50%;
transform: translate(-50%, 0);
}