gpt4 book ai didi

html - 如何防止下拉菜单拉伸(stretch)导航栏

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

如何防止下拉菜单拉伸(stretch)导航栏?我试图基本上找到一种方法将交易选项卡与下拉列表的其余部分隔离开来,这样它就不会影响整个导航栏。顺便说一句,我是网页设计的新手。

XHTML:

<div id="nav-bar">
<ul>
<li><a href="#home-pge">home</a></li>

<li class="navbar-drop">
<a class="navbar-edit">deals</a>
<div class="navbar-drop-content">
<a href="#opt1">option 1</a>
<a href="#opt2">option 2</a>
<a href="#opt3">option 3</a>
</div>
</li>

<li><a href="#about-us-pge">about us</a></li>
<li><a href="#contact-pge">contact</a></li>
<li><a href="#howto-pge">how to</a></li>
</ul>
</div>

CSS:

 #nav-bar ul{
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #666666;
width: 100%;
position: fixed;
top: 80px;

#nav-bar li{
float: left;
border-right: 3px inset gray;
}
#nav-bar li a{
display: block;

height: 25px;
width: 150px;

text-decoration: none;
text-transform: capitalize;
text-align: center;

color: white;
padding: 15px 15px 10px 15px;
}
#nav-bar li a:hover{
background-color: #C4BCB9;
}
#nav-bar li:last-child{
border-right: none;
}

css的下拉部分:

#nav-bar li a, .navbar-edit{/*edits the "Deals" tab if needed*/
cursor: pointer;
}

.navbar-drop:hover .navbar-drop-content{/*Displays the "dropdown box" when the navbar element is hovered over*/
display: block;
}

.navbar-drop-content{/*this edits the dropdown card itself*/
display: none;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);/*to make the dropdown menu look like a "card"*/
width: 100%;
}
#nav-bar li .navbar-drop-content a{/*edits the links in the drop down*/
color: black;
background-color: #F5F3EF;
text-decoration: none;
text-align: left;
}
#nav-bar li .navbar-drop-content a:hover{/*edits the links in the dropdown when hovered*/
background-color: red;
cursor: url("1note.png"), crosshair;
}

最佳答案

  1. #nav-bar ul 中移除 overflow:hidden
  2. navbar-drop position: relative
  3. navbar-drop-content position: absolute 并相对于导航栏定位它(50px 似乎是正确的)

codepen

#nav-bar ul {
list-style-type: none;
margin: 0;
padding: 0;
/*overflow: hidden;*/
background-color: #666666;
width: 100%;
position: fixed;
top: 80px;
}

#nav-bar li {
float: left;
border-right: 3px inset gray;
}

#nav-bar li a {
display: block;
height: 25px;
width: 150px;
text-decoration: none;
text-transform: capitalize;
text-align: center;
color: white;
padding: 15px 15px 10px 15px;
}

#nav-bar li a:hover {
background-color: #C4BCB9;
}

#nav-bar li:last-child {
border-right: none;
}

#nav-bar li a,
.navbar-edit {
/*edits the "Deals" tab if needed*/
cursor: pointer;
}

.navbar-drop {
position: relative;
}

.navbar-drop:hover .navbar-drop-content {
/*Displays the "dropdown box" when the navbar element is hovered over*/
display: block;
}

.navbar-drop-content {
/*this edits the dropdown card itself*/
display: none;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
/*to make the dropdown menu look like a "card"*/
width: 100%;
position: absolute;
top: 50px;
z-index: 1000;
}

#nav-bar li .navbar-drop-content a {
/*edits the links in the drop down*/
color: black;
background-color: #F5F3EF;
text-decoration: none;
text-align: left;
}

#nav-bar li .navbar-drop-content a:hover {
/*edits the links in the dropdown when hovered*/
background-color: red;
cursor: url("1note.png"), crosshair;
}
<div id="nav-bar">
<ul>
<li><a href="#home-pge">home</a></li>

<li class="navbar-drop">
<a class="navbar-edit">deals</a>
<div class="navbar-drop-content">
<a href="#opt1">option 1</a>
<a href="#opt2">option 2</a>
<a href="#opt3">option 3</a>
</div>
</li>

<li><a href="#about-us-pge">about us</a></li>
<li><a href="#contact-pge">contact</a></li>
<li><a href="#howto-pge">how to</a></li>
</ul>
</div>

关于html - 如何防止下拉菜单拉伸(stretch)导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42632251/

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