【发布时间】:2017-09-09 22:27:33
【问题描述】:
我刚开始编码,在尝试使用 position: fixed; 时遇到了一些问题在我的一次练习中使用 CSS。
这就是我想要的样子(受影响的区域以红色突出显示): 我想要的是
当用户向下滚动页面时,我希望红色标题处于固定位置,就像在 facebook 或 youtube 上一样。我已经应用了 z-index: 1; (因为目前它是页面上唯一的索引项)和位置:固定;。这导致标题被固定并按我想要的方式滚动,但它从页面顶部向下修复了 40-50px,这不是我想要的!在此处查看图片:
我得到了什么
显然我遗漏了一些明显的东西,但我正在努力寻找它!
谁能帮忙?
在下面查看我的 HTML 和 CSS 代码。
body{
margin: 0px;
background-color: #dddddd;
}
#container {
}
#header {
background-color: red;
width: 100%;
height: 50px;
position: fixed;
z-index: 10;
}
#video {
background-color: #ffffff;
width: 650px;
height: 400px;
float: left;
margin: 5px;
margin-left: 120px;
margin-top: 50px;
margin-bottom: 35px;
}
#description {
background-color: #ffffff;
width: 650px;
height: 200px;
float: left;
margin: 5px;
margin-left: 120px;
margin-bottom: 35px;
}
#comments {
background-color: #ffffff;
width: 650px;
height: 400px;
float: left;
margin: 5px;
margin-left: 120px;
margin-bottom: 35px;
}
#rightadbox {
background-color: #ffffff;
width: 350px;
height: 100px;
margin: 5px;
margin-top: 50px;
margin-left: 800px;
margin-bottom: 35px;
}
#right {
background-color: #ffffff;
width: 350px;
height: 1000px;
margin: 5px;
margin-left: 800px;
margin-bottom: 35px;
}
#footer {
background-color: blue;
width: 100%;
height: 100px;
clear: both;
}
<!DOCTYPE HTML>
<html>
<head>
<!--PUT CSS LINK HERE-->
<link rel="stylesheet" type="text/css" href="PracticeHTMLCSS.css"/>
<title>Practice HTML</title>
</head>
<body>
<div id="container">
<div id="header">
</div>
<div id="video">
</div>
<div id="description">
</div>
<div id="comments">
</div>
<div id="rightadbox">
</div>
<div id="right">
</div>
<div id="footer">
</div>
</div>
</body>
</html>
【问题讨论】:
-
如果我的回答有效,请接受我的回答:D