垂直使用CSS 3将 [英] Align vertically using CSS 3
本文介绍了垂直使用CSS 3将的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用CSS 3,有没有什么办法可以垂直对齐的块级元素?你有一个例子吗? 谢谢你。
With CSS 3, are there any way to vertically align an block element? Do you have an example? Thank you.
推荐答案
最近在研究这个问题,并尝试:
Was looking at this problem recently, and tried:
HTML:
<body>
<div id="my-div"></div>
</body>
CSS:
#my-div {
position: absolute;
height: 100px;
width: 100px;
left: 50%;
top: 50%;
background: red;
transform: translate(-50%, -50%);
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
这里的小提琴:
Here's the Fiddle:
它甚至用宽/高:汽车工程时,在固定尺寸的地方。 测试对火狐,Chrome和IE(*喘气*)。
It even works when using "width/height: auto", in the place of fixed dimensions. Tested on the latest versions on Firefox, Chrome, and IE (* gasp *).
这篇关于垂直使用CSS 3将的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文