javascript - 垂直对齐视口(viewport)的 50%

标签 javascript jquery css

<分区>

我正在尝试将 div 垂直对齐到视口(viewport)的 50%,无论文档有多长。

你可以在这里看到一个例子http://fancyapps.com/fancybox/#examples

最佳答案

可以使用盒子偏移属性来获得这种效果。

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


jsfiddle

CSS

#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/

相关文章:

c# - 如何在 javascript 和 ASP.NET 中返回项目的当前域?

javascript - jQuery 表单提交

jQuery 子>父>子

javascript - 暂停 Javascript 执行直到按下按钮

javascript - 在文本字段内移动插入符号位置

jquery - 如何使用 jQuery 将 min-height 应用于 DIV?

jquery - "this[0] is undefined"使用 jQuery 验证插件的消息

javascript - 在 jQuery 中运行其他代码之前确保循环已完全执行

css - Origami(facebook 的原型(prototype)框架)的用途和原因是什么?

CSS3 : change font size ratio