贴纸
我按照一些指南进行操作,使div可以在垂直和水平方向上居中,但这是行不通的。
http://jsfiddle.net/ony80a5d/
<div class="c">center</div>
html, body {
height: 100%;
}
.c {
background: grey;
width: 50%;
height: 50%;
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
}
乔什·克罗齐耶(Josh Crozier)
一种选择是将添加margin: auto
到元素。在现代浏览器中,这将使元素水平/垂直居中。
有关将元素水平/垂直居中的更多方法,请参见此答案。
更新的例子
html, body {
height: 100%;
}
body {
margin: 0;
}
.c {
background: grey;
width: 50%;
height: 50%;
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin: auto
}
<div class="c">center</div>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
编辑于
我来说两句