无论屏幕分辨率或用户的窗口大小,这里有没有人知道如何使div转到页面的中心(垂直)?例如,Instagram的登录页面.如果你让你的窗口变小,div将保持浮动在中心,直到它到达顶部.我做到了,但问题是,当用户继续缩小窗口时,div实际上已经离开用户窗口(到顶部).
以下是该示例的Instagram登录页面:https: //instagram.com/accounts/login/
以下是另一个例子的页面:http: //wwwtar.com
会很感激答案=)
编辑:这是我的主要代码:
#wrapper2{
width: 960px;
height: 530px;
top: 50%;
margin-top: -280px;
margin-right: auto;
margin-left: auto;
position: fixed;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
border: 1px solid #dcdcdc;
box-shadow: 0px 0px 5px 3px #f0f0f0;
background: -webkit-gradient(linear, left top, left bottom, from(#fafafa), to(#efefef));
background: -moz-linear-gradient(top, #fafafa, #efefef);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fafafa', endColorstr='#efefef');
}
Run Code Online (Sandbox Code Playgroud)
这适用于任何大小的div.
HTML:
<div></div>
Run Code Online (Sandbox Code Playgroud)
CSS:
div {
width: 100px;
height: 100px;
background-color: #cc333;
position: absolute;
top:0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}
Run Code Online (Sandbox Code Playgroud)
更新:
CSS:
#wrapper {
width: 200px;
height: 200px;
background-color: #ccc333;
position: absolute;
top:0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}
@media only screen and (max-height : 200px) {
#wrapper {
position: relative;
}
}
Run Code Online (Sandbox Code Playgroud)
where max-height=身高.wrapper
| 归档时间: |
|
| 查看次数: |
209 次 |
| 最近记录: |