我正在尝试像 stackoverflow 那样在我的页面顶部创建一个栏,顶部的黑色栏。
我正在尝试在其下方创建一个标题。
<html>
<style>
.top{
background-color: black;
position:fixed;
height: 50px;
width: 110%;
float: top;
margin-left: -10px;
margin-top: -10px;
}
h1{
text-align: center;
margin-top: 100px;
}
</style>
<body>
<div class = "top">
asdfad
fasdfasdf
</div>
<h1> lol </h1>
</body>
</html>
但是,当我在 Chrome 中创建它时,div 顶部会附加到 H1,就像占据其一半大小一样。怎么了?
最佳答案
我假设您希望您的菜单栏具有固定
位置,所以只需将top:0
添加到此类:
.top{
background-color: black;
position:fixed;
height: 50px;
width: 110%;
/*float: top; remove this*/
margin-left: -10px;
margin-top: -10px;
top:0 /*add this*/
}
另外没有float:top
。看这里css float property
关于html - Div 附加到 chrome 中的 h1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24725350/