gpt4 book ai didi

html - 导航菜单下拉不会垂直显示

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

我不明白为什么第一层(图片和视频)下拉菜单水平显示。我尝试了很多不同的东西,但就是想不通。第二层(肖像、风景、抽象)垂直显示。

我对这一切还很陌生,所以我相信这很容易解决。任何帮助将不胜感激。

/* Navigation Menu */
.nav {
list-style-type: none;
margin: 0;
padding: 0 15px;
float: right;
width: 100%;
background-color: rgba(256, 256, 256,.25);
}
li{
float: right;
list-style-type: none;
padding-top: 10px;
}


li a {
display: block;
color: rgb(0,0,0);
padding: 5px 16px 15px 16px;
font-family: 'Abel', sans-serif;
text-decoration: none;
}

li a:hover {
color: #000000;
padding-bottom: 10px;
border-bottom: 4px solid #000000;
}
li > .gallerydrop, .picturesdrop {
display: none;
}
li:hover > .gallerydrop {
display:block;
position: absolute;
padding: 0;
background-color: rgba(256, 256, 256,.25);
}
li:hover > .picturesdrop {

display:block;
position: absolute;
padding: 0;
background-color: rgba(256, 256, 256,.25);
}
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="nav.css" type="text/css">
<title>Nav</title>
<meta charset="utf-8">
</head>
<nav>
<ul class="nav">
<li><a href="contact.html">Contact</a></li>
<li><a href="aboutme.html">About Me</a></li>
<li><a href="details.html">Details</a></li>
<li><a href="gallery.html">Gallery</a>
<ul class="gallerydrop">
<li><a href="videos.html">Videos</a></li>
<li><a href="pictures.html">Pictures</a>
<ul class="picturesdrop">
<li><a href="portraits.html">Portraits</a></li>
<li><a href="landscapes.html">Landscapes</a></li>
<li><a href="abstract.html">Abstract</a></li>
</ul>
</li>
</ul>
</li>

<li class="li"><a href="home.html">Home</a></li>
</ul>
</nav>
</html

最佳答案

您正在将 float: right 应用于所有 li 元素,但您显然不希望这样。所以诀窍是只针对顶级 li,使用类似 .nav>li {float:right;} 的东西。

/* Navigation Menu */
.nav {
list-style-type: none;
margin: 0;
padding: 0 15px;
float: right;
width: 100%;
background-color: rgba(256, 256, 256,.25);
}

.nav>li {float:right;}
li{
list-style-type: none;
padding-top: 10px;
}


li a {
display: block;
color: rgb(0,0,0);
padding: 5px 16px 15px 16px;
font-family: 'Abel', sans-serif;
text-decoration: none;
}

li a:hover {
color: #000000;
padding-bottom: 10px;
border-bottom: 4px solid #000000;
}
li > .gallerydrop, .picturesdrop {
display: none;
}
li:hover > .gallerydrop {
display:block;
position: absolute;
padding: 0;
background-color: rgba(256, 256, 256,.25);
}
li:hover > .picturesdrop {

display:block;
position: absolute;
padding: 0;
background-color: rgba(256, 256, 256,.25);
}
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="nav.css" type="text/css">
<title>Nav</title>
<meta charset="utf-8">
</head>
<nav>
<ul class="nav">
<li><a href="contact.html">Contact</a></li>
<li><a href="aboutme.html">About Me</a></li>
<li><a href="details.html">Details</a></li>
<li><a href="gallery.html">Gallery</a>
<ul class="gallerydrop">
<li><a href="videos.html">Videos</a></li>
<li><a href="pictures.html">Pictures</a>
<ul class="picturesdrop">
<li><a href="portraits.html">Portraits</a></li>
<li><a href="landscapes.html">Landscapes</a></li>
<li><a href="abstract.html">Abstract</a></li>
</ul>
</li>
</ul>
</li>

<li class="li"><a href="home.html">Home</a></li>
</ul>
</nav>
</html

关于html - 导航菜单下拉不会垂直显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36670745/

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