<分区>
我正在尝试将 div
垂直对齐到视口(viewport)的 50%
,无论文档有多长。
你可以在这里看到一个例子http://fancyapps.com/fancybox/#examples
标签 javascript jquery css
最佳答案
可以使用盒子偏移属性来获得这种效果。
This property specifies how far an absolutely positioned box's top margin edge is offset below the top edge of the box's containing block.
来源:http://www.w3.org/TR/CSS2/visuren.html#position-props
#centered {
position: fixed;
top: 0;
bottom: 0;
right: 0;
left: 0;
margin: auto;
height: 200px; /* arbitrary */
width: 600px; /* arbitrary */
background-color: grey;
}
关于javascript - 垂直对齐视口(viewport)的 50%,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18519215/