gpt4 book ai didi

css - 如何使导航栏固定在页面顶部而不与表格重叠

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

所以我还是个初学者,我的问题对其他人来说可能听起来很傻,但是,我需要解决这个问题,所以这是我的html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Test</title>
<link href="test.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="first">
<h1>Test Page</h1>
<div id="header">
<ul id="nav">
<li class="head"><a href="http://">Home</a></li>
<li class="head"><a href="http://">about</a></li>
<li class="head"><a href="http://">Contact</a></li>
<li class="head"><a href="http://">Our products</a></li>
</ul>
</div>

</div>

<div id = "p">
<p>Libero cupiditate tempore autem animi iusto, expedita neque voluptatibus dolor sequi quia nihil quam magnam, magni praesentium nam aut ipsum soluta nulla et, eum sed? Explicabo modi similique nobis nesciunt!</p>
<p>Itaque, corrupti quae corporis excepturi eum vero, rem aliquam dolorem, adipisci maxime deleniti. Dicta beatae voluptatum maiores nesciunt, ducimus eveniet. Reprehenderit doloremque, laboriosam repellat rerum adipisci dolores quia sapiente cupiditate!</p>
<p>Voluptatibus tenetur sit tempore inventore optio nihil nostrum sapiente neque, odio ipsa atque? Tenetur earum voluptatum omnis dignissimos dolores reprehenderit sint quo ducimus, cumque inventore laboriosam asperiores laborum nemo perferendis.</p>
<p>Minima ab blanditiis, rerum voluptas dicta ducimus, voluptates itaque reprehenderit numquam mollitia possimus quod amet harum non eius perferendis iste saepe rem maiores est. Similique minus consequatur reiciendis voluptatem quibusdam.</p>
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Magni minus aspernatur ullam eligendi illum laboriosam, quas omnis facilis voluptatum quis iste ipsam ut aliquam praesentium dolorem. Fugit assumenda nobis distinctio.</p>
</div>
<footer> <p>Posted by: Hege Refsnes</p>
<p>Contact information: <a href="mailto:someone@example.com">
Personal Email</a>.</p>
</footer>
</body>
</html>

如您所见,导航栏与段落重叠 我将 #header 的位置设置为 fixed 并设置为 #first top:0;我无法弄清楚问题所在,如果我要制作侧边栏,如何防止它与其他元素重叠,甚至如何防止元素与其他元素重叠?

 #first{
top:0;
}
#header{
position: fixed;

}
#nav{

list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: lightcoral;

border: lightcoral solid;
border-top-left-radius: 0.5rem;
border-top-right-radius: 0.5rem;

}
#nav li{
float: left;
padding: 2rem 2rem;
}

#nav li a {

display: inline-block;
color: white;
text-align: center;
text-decoration: none;
}
#nav li a:hover {

color: dimgray;

}


#nav li:hover {
border: (214, 20, 124) solid;
background-color:rgb(214, 20, 124);
color: dimgray;
border-radius: 0.5rem;
}
#nav li:last-child{
float: right;
}

最佳答案

<nav class="navbar navbar-default"></nav> <!-- Dummy nav bar -->
<nav class="navbar navbar-default navbar-fixed-top"> <!-- Real nav bar -->
<!-- Nav bar details -->
</nav>

这是将解决您的问题的 Bootstrap 类。照原样使用

更多信息请阅读

Blockquote https://getbootstrap.com/docs/4.0/components/navbar/

关于css - 如何使导航栏固定在页面顶部而不与表格重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52155377/

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