gpt4 book ai didi

html - 滚动时我的 div 与标题重叠

转载 作者:太空宇宙 更新时间:2023-11-04 16:12:17 40 4
gpt4 key购买 nike

我这样做是为了让我的页眉在滚动时跟随页面。但是当我滚动时,我的 div(位于“colWrapper”部分)与标题重叠。我尝试搜索类似的主题,但没有适合我的解决方案。

enter image description here

<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href='https://fonts.googleapis.com/css?family=Oswald:400,300,700' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Iceland' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="test.css">
</head>

<body>
<header id="navbar">
<div id="loginDiv">
<a href="#"><button type="button" id="loginBtn"><span>LOGIN</span></button></a>
</div>
<div id="joinDiv">
<a href="#"><button type="button" id="joinBtn"><span>JOIN NOW</span></button></a>
</div>
</header>

<div id="toprow">
<div id="homeDiv">
<a href="#"><button type="button" id="homeBtn"><span>HOME</span></button></a>
</div>
</div>

<div id="sideNav">
<ul>
<li><a class="menu" href="#"><a></li><hr>
<li><a class="menu" href="#"> Account<a></li><hr>
<li><a class="menu" href="#"> Live Events <a></li><hr>
<li><a class="menu" href="#"> Football<a></li><hr>
<li><a class="menu" href="#"> Baseball<a></li><hr>
<li><a class="menu" href="#"> Soccer<a></li><hr>
<li><a class="menu" href="#"> Basketball<a></li><hr>
<li><a class="menu" href="#"> Hockey<a></li><hr>
<li><a class="menu" href="#"> MMA<a></li><hr>
<li><a class="menu" href="#"> eSports<a></li><hr>
<li><a class="menu" href="#"> Tennis<a></li><hr>
<li><a class="menu" href="#"> Cricket<a></li><hr>
<li><a class="menu" href="#"> Golf<a></li><hr>
<li><a class="menu" href="#"> Badminton<a></li><hr>
<li><a class="menu" href="#"> Handball<a></li><hr>
<li><a class="menu" href="#"> Rugby<a></li><hr>
<li><a class="menu" href="#"> Snooker<a></li><hr>
<li><a class="menu" href="#"> Table Tennis<a></li><hr>
<li><a class="menu" href="#"> Volleyball<a></li><hr>
<li><a id="lazy" href="#"><a><font color="#B31B34">LAZYSOLUTION</font></li><hr>
</ul>
</div>
<section id="colWrapper">
<div class="longColumns"; id="colOne";></div>
<div class="longColumns"; id="colTwo";></div>
<div class="longColumns"; id="colThree";></div>
</section>

</body>
</html>

CSS:

/* header and top bar */

header{
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 50px;
background-color: #B31B34;
}

#toprow{
position:fixed;
width: 100%;
height:35px;
top:0;
left:0;
margin:0;
padding:0;
background-color: #333333;
margin-top:50px;}

/* body */

body{
background-color:#fff;background-image:url('bk5.jpg');}

/* buttons */
a #homeBtn span{
background:url(home.png) no-repeat;
padding-left: 25px;
background-position: 0px 0px;
background-size: contain;}

#homeBtn{
font-size:1em;
outline:none;
background:none;
border:none;
cursor: pointer;
color:#fff;
}

#loginBtn, #joinBtn{
color:white;
display: inline-block;
outline: none;
cursor: pointer;
text-align: center;
text-decoration: none;
font: 20px;
padding: 0.5em 1.4em 0.5em;
-webkit-border-radius: .5em;
-moz-border-radius: .5em;
border-radius: .5em;
border-style:none;
float:right;
margin-top:10px;
background-color:red;
}

a #loginBtn span{
background:url(soccer.png) no-repeat;
padding-left: 25px;
background-position: 0px 0px;
background-size: contain;}

#loginBtn{ margin-right:150px;}
#joinBtn{margin-right:5px;}

#homeDiv{
float:left; margin-left:160px;}

/* sidebar */

ul{ list-style-type: none; margin:0; padding:0.5em;}
a{text-decoration: none; font-size:1.1em; }

.menu {
line-height:30px;
border-bottom: 1px solid black;
color:#fff;
border:1px initial black;
border-left: 1px solid black;
display:block;}

#sideNav{

width: 180px;
margin-left:60px;
float: left;
display: inline;
max-height:1900px;
background-color:#B31B34;

}

#lazy{line-height:108px;}

/* three columns for images */

#colWrapper{
margin-top:100px;
border: 1px dotted red;
height:750px;

width:2100px;}
.longColumns{

background-color:#fff;
background: url('col1.png');
opacity: 0.7;
filter: alpha(opacity=40);
border: 1px dotted black;
float:left;
width:375px;
height:750px;

}


/* footer */
#footer {
width: 1895px;
height: 350px;
background-color: #333333;
}

最佳答案

只需为 header#toprow 添加更高的 z-index

header{
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 50px;
background-color: #B31B34;
z-index:1000; /* just random high value for z-index will keep it on top */
}

#toprow{
position:fixed;
width: 100%;
height:35px;
top:0;
left:0;
margin:0;
padding:0;
background-color: #333333;
margin-top:50px;
z-index:1000; /* Also here */
}

关于html - 滚动时我的 div 与标题重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34367968/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com