gpt4 book ai didi

html - 试图在我的页面顶部创建一个固定的导航栏,但是当我向下滚动时,导航栏正上方有一个间隙

转载 作者:太空宇宙 更新时间:2023-11-04 03:36:09 25 4
gpt4 key购买 nike

导航栏不在浏览器窗口的最顶部。我该如何解决这个问题?

我鼓励您输入我的代码并运行它以进行预览。

HTML 代码:

<!DOCTYPE html>
<html>
<head>
<link href='http://fonts.googleapis.com/css?family=Crimson+Text' rel='stylesheet' type='text/css'>
<link href="http://s3.amazonaws.com/codecademy-content/courses/ltp/css/shift.css" rel="stylesheet">
<link rel="stylesheet" href="Website(CSS).css" type="text/css" media="screen" title="no title" charset="utf-8">
<title>Hunter's Website</title>
</head>
<body>
<div class="nav">
<div class="container">
<ul class="nav-left">
<li id="twitter">
<a href="http://twitter.com/#"><img src="Twitter.png" width="75" height="75" alt="Twitter" /></a>
</li>
<li id="instagram">
<a href="http://instagram.com/#"><img src="Instagram.png" width="75" height="75" alt="Instagram"/></a>
</li>
<li id="quora">
<a href="http://quora.com/#"><img src="Quora.jpg" width="125" height="54" alt="Quora" /></a>
</li>
</ul>
<ul class="nav-right">
<li id="future-plans">
<a href="insert link">Future Plans</a>
</li>
<li ="contact">
<a href="inset link">Contact</a>
</li>
</ul>
</div>
</div>

<div class="jumbotron">
<div class="layer"></div>
<div class="container">
<h1>Learn more about me.</h1>
<p>
Click <a href="insert link">here</a> to learn more about my future.
</p>
</div>
</div>
...
</body>
</html>

CSS 代码:您可以忽略注释,它们只是提醒我需要做什么。

/* Get the individual social media links to be pretty spaced out from each other, 
get the whole box of social image links to be closer to the left border. Get the nav header to be positioned as absolute. Get the -
.nav-right to have better font. To be bigger font, and to pushed a little more to the left of the nav box. */

body {
border: 2px solid green;
}

.nav {
/* Play around with height, try and get edges curved
Try making .jumbotron image to be full sized w/o cropping & 1110 width or whatever */
background-color: red;
height: 11%;
width: 98%;
position: fixed;
z-index: 10;
border: 2px solid black;
}

.nav ul {
display: inline;
border: 2px solid black;
}

.nav li {
display: inline;
border: 2px solid black;
}

.nav .nav-left {
float: left;
clear: both;
margin-top: 0px;
margin-left: 0px;
margin-right: 0px;
border: 2px solid black;
}

.nav .nav-right {
float: right;
margin-top: 15px;
margin-right: 20px;
margin-bottom: 15px;
margin-left: 20px;
border: 2px solid black;
}

.jumbotron {
height: 515px;
width: 1110px;
background-image: url('Website .jumbotron.jpeg');
background-repeat: no-repeat;
position: relative;
margin-top: 120px;
border: 2px solid black;
}

.layer {
background-color: rgba(76,76,76, 0.3);
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border: 2px solid black;
}

.jumbotron .container {
position: relative;
top: 240px;
left: 26px;
}

.jumbotron h1 {
color: white;
font-family: 'Shift', serif;
font-weight: bold;
font-size: 36px;
}
.jumbotron p {
color: white;
font-family: 'Crimson Text';
font-size: 20px;
}

最佳答案

要将导航栏固定在顶部而不留空隙,请将以下代码添加到您的 css 文件中:

.nav {
position: absolute;
top: 0px;
}

关于html - 试图在我的页面顶部创建一个固定的导航栏,但是当我向下滚动时,导航栏正上方有一个间隙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25541121/

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