【发布时间】:2016-01-18 11:03:59
【问题描述】:
我正在尝试使高度未知的 div 居中。
当视口高度小于 div 高度时,我找不到允许滚动到 div 顶部的解决方案。
HTML
<div>
<p>This will be hidden when <br />
window_height < div_width</p>
<br />
<br />
<br />
How to make it scroll to the top?
</div>
CSS
body {
background: grey;
}
p{
background: green;
}
div {
position: absolute;
left: 50%;
top: 50%;
box-sizing: border-box;
transform: translate(-50%, -50%);
max-width: 500px;
width:100%;
height: 700px; /* Unknown*/
padding: 20px;
background: red;
color: white;
text-align: center;
}
http://codepen.io/Koopa/pen/GpypdX
谢谢
【问题讨论】:
-
“我找不到允许在 viewport_height
标签: css responsive-design centering