【发布时间】:2014-07-11 00:40:47
【问题描述】:
希望有一个简单的解决方案。基本上我想要做的是在浏览器的垂直中心放置一个 div (#hello) 并 使用固定定位,这样它就不会在滚动时移动。到目前为止,这是我的 HTML:
<section id="home">
<div id="home-container">
<div id="hello"></div>
</div>
</section>
还有 CSS:
#home {
display: table;
overflow: hidden;
margin: 0px auto;
}
*:first-child+html #home {
position: relative;
}
* html #home {
position: relative;
}
#home-container {
display: table-cell;
vertical-align: middle;
}
*:first-child+html #home-container {
position: absolute;
top: 50%;
}
* html #home-container {
position: absolute;top:50%;
}
*:first-child+html #hello {
position: relative;
top: -50%;
}
* html #hello {
position: relative;
top: -50%;
}
#home {
height: 100%;
}
现在 div 在“home”部分垂直居中,但在滚动时移动。我尝试将#home 和#home-container 更改为固定定位,但它不起作用。
我已经搜索了很多,如果已经存在类似的线程,我深表歉意。希望有人能指出我正确的方向。提前致谢!
【问题讨论】:
-
*对于所有内容?例如* html?你不知道它是做什么的,所以先了解一下…… -
是的,这是教程中使用的代码。我会尝试删除它们,看看是否有帮助。
-
现在不要再参考那个教程了...你能提供链接吗
-
太疯狂了..不要提到那个
标签: html css css-position vertical-alignment