Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想让一个块元素水平居中,垂直居中。这是我正在尝试的:
iframe { display: block; position: fixed; bottom: 5px; left: 50%; right: 50%; }
它显示在右下角,部分溢出屏幕。有没有办法做到这一点?
您需要设置一个负左边距等于元素宽度的一半,例如:
left: 50%; margin-left: -152px;
right: 50%什么都不做。
right: 50%
http://jsfiddle.net/ExplosionPIlls/VgPUZ/