gpt4 book ai didi

html - 标题不会定位 : Absolute

转载 作者:行者123 更新时间:2023-11-28 06:40:41 25 4
gpt4 key购买 nike

我试图找到一个简单的修复方法让我的标题保持在固定位置,但是当我将“position:fixed”应用到我的标题类时没有任何反应。我也在标题中使用 h1 标签进行了尝试。如果有人能告诉我我做错了什么,以及当您向下滚动屏幕时让标题保持固定的最简单方法是什么,我将不胜感激。我在下面粘贴了标题部分。

感谢您的所有建议!

 <header class="logo">
<h1>The Loch Ness Monster Report</h1>
<ul id="nav-menu">
<li><a class="selected" href="index.html">Latest Sightings</a></li>
<li><a href="history.html">History</a></li>
<li><a href="contact.html">Report a Sighting</a></li>
<li><a href="donations.html">Donate</a></li>
</ul>
</header>

CSS 可以正常工作,因为其他元素已连接。这就是我为标题元素使用的 CSS。

.logo {
position: fixed;
z-index: 1;
}

最佳答案

你可以这样做。

header{
width: 100vw; //set header width equal to viewport width.

}
.logo {
position: fixed; //set header fix to top
z-index: 1;
display: flex; // displays logo content horizontally
justify-content: flex-start; // set logo content
flex-direction: row;
height: auto;
background: #000000;
color: white;
}
#nav-menu{
display: flex;
flex-direction: row; //display lost horizontally
}
h1{
font-size: 140%;
}
li{
padding: 5px;
list-style: none;
}
a{
text-decoration: none;
color: white
}
li:hover{
background-color: white;
border-radius: 5px;
}
a:hover{
color: red;


}

body{
// reset body properties
padding: 0;
margin: 0;
}
.container{
padding-top: 60px;
}
section{
height: 500px;
width: 960px;
}
.section1{
background-color: blue;
}
.section2{
background-color: orange;
}
.section3{
background-color: red;
}
<body>
<header class="logo">
<h1>The Loch Ness Monster Report</h1>
<ul id="nav-menu">
<li><a class="selected" href="index.html">Latest Sightings</a></li>
<li><a href="history.html">History</a></li>
<li><a href="contact.html">Report a Sighting</a></li>
<li><a href="donations.html">Donate</a></li>
</ul>

</header>
<div class="container">
<Section class="section1">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</Section>
<Section class="section2">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</Section>
<Section class="section3">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</Section>
</div>
</body>

关于html - 标题不会定位 : Absolute,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34305243/

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