gpt4 book ai didi

html - 子菜单导航不向左浮动

转载 作者:行者123 更新时间:2023-11-28 17:14:40 24 4
gpt4 key购买 nike

我正在尝试创建导航菜单然后下拉和进一步的子菜单我面临的问题是子菜单不是 float 在左边而是它向下倾斜

我写的html代码

.mainmenu {
background: rgba(0, 0, 0, 0) url("img/mainmenu_area_bg.png") repeat-x scroll 0 0;
height: 53px;
}
.mainmenu ul#nav {
list-style: outside none none;
margin: 0;
padding: 0;
text-align: left;
}
.mainmenu ul#nav li {
display: inline-block;
}

.mainmenu ul#nav li a {
color: #fff;
display: block;
margin: 0 -2px;
padding: 17px 20px;
text-transform: uppercase;
}
.mainmenu ul#nav li:hover> a,
.mainmenu ul#nav li.current{
background: #11c3f1 none repeat scroll 0 0;
}
/*=================
DropDown Menu
===================*/
#nav > li {
position: relative;
}
#nav > li:hover ul {
opacity: 1;
z-index:9999;top: 100%;
visibility:visible;
}
#nav > li ul {
background: #fff none repeat scroll 0 0;
opacity: 0;
left: -2px;
list-style: outside none none;
margin: 0;
padding: 0;
position: absolute;
text-align: left;
transition: all 0.5s ease 0s;
width: 204px;
padding-left: 2px;
z-index:-99999;
top: 150%;
visibility:hidden
}
#nav > li ul li {
display: block;
width: 200px;

}
.mainmenu ul#nav li ul li a:hover {
color: #fff;
border-radius: 0 0 80px 0;
border-left: 4px solid #000;
padding-left: 10px;
}
.mainmenu ul#nav li ul li a {
border-bottom: 1px solid #ddd;
color: #000;
padding: 10px 10px;
}


#nav ul .subNav ul {
display: none;
width: 100%;
list-style: outside none none;
}
#nav ul .subNav:hover ul{
display: block;

}
#nav ul .subNav ul li {
background-repeat: repeat-x;
border-top: 1px solid #999;
float: left;
list-style: none;
}
#nav ul .subNav ul li a {
color: #fff;
display: block;
margin: 0 -2px;
padding: 17px 20px;
text-transform: uppercase;
float: left;
width:100%;
}
#nav li.subNav ul li a:link, #nav li.subNav ul li a:visited {
color: #333;
}
#nav li.subNav ul li a:hover, #nav li.subNav ul li a:active {
color: #F34B2B;
}
 <div class="mainmenu nav">
<nav>
<ul id="nav">
<li><a href="services.php">Service</a>
<ul>
<li><a href="#">Menu</a></li>
<li class="subNav"><a href="#">Menu2</a>
<ul class="subNav">
<li><a href="#">Piano</a></li> <li><a href="#"> Couch</a></li>
<li><a href="#">Appliances</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</nav>
</div>

将光标移到结果页面中,您将看到输出,我希望有人将光标移至 MENU2,它应该 float 到左侧而不是向下。

提前致谢。

最佳答案

你开始吧,你需要让包含子导航的 li 相对显示,这样子导航菜单可以绝对定位在左边 200px 和引用 li 的 0 顶部。

.mainmenu {
background: rgba(0, 0, 0, 0) url("img/mainmenu_area_bg.png") repeat-x scroll 0 0;
height: 53px;
}
.mainmenu ul#nav {
list-style: outside none none;
margin: 0;
padding: 0;
text-align: left;
}
.mainmenu ul#nav li {
display: inline-block;
position:relative;
}

.mainmenu ul#nav li a {
color: #fff;
display: block;
margin: 0 -2px;
padding: 17px 20px;
text-transform: uppercase;
}
.mainmenu ul#nav li:hover> a,
.mainmenu ul#nav li.current{
background: #11c3f1 none repeat scroll 0 0;
}
/*=================
DropDown Menu
===================*/
#nav > li {
position: relative;
}
#nav > li:hover ul {
opacity: 1;
z-index:9999;top: 100%;
visibility:visible;
}
#nav > li ul {
background: #fff none repeat scroll 0 0;
opacity: 0;
left: -2px;
list-style: outside none none;
margin: 0;
padding: 0;
position: absolute;
text-align: left;
transition: all 0.5s ease 0s;
width: 204px;
padding-left: 2px;
z-index:-99999;
top: 150%;
visibility:hidden
}
#nav > li ul li {
display: block;
width: 200px;

}
.mainmenu ul#nav li ul li a:hover {
color: #fff;
border-radius: 0 0 80px 0;
border-left: 4px solid #000;
padding-left: 10px;
}
.mainmenu ul#nav li ul li a {
border-bottom: 1px solid #ddd;
color: #000;
padding: 10px 10px;
}


#nav ul .subNav ul {
display: none;
width: 100%;
list-style: outside none none;
}
#nav ul .subNav:hover ul{
display: block;
left:200px;
top:0;
}
#nav ul .subNav ul li {
background-repeat: repeat-x;
border-top: 1px solid #999;
float: left;
list-style: none;
}
#nav ul .subNav ul li a {
color: #fff;
display: block;
margin: 0 -2px;
padding: 17px 20px;
text-transform: uppercase;
float: left;
width:100%;
}
#nav li.subNav ul li a:link, #nav li.subNav ul li a:visited {
color: #333;
}
#nav li.subNav ul li a:hover, #nav li.subNav ul li a:active {
color: #F34B2B;
}
<div class="mainmenu nav">
<nav>
<ul id="nav">
<li><a href="services.php">Service</a>
<ul>
<li><a href="#">Menu</a></li>
<li class="subNav"><a href="#">Menu2</a>
<ul class="subNav">
<li><a href="#">Piano</a></li> <li><a href="#"> Couch</a></li>
<li><a href="#">Appliances</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</nav>
</div>

关于html - 子菜单导航不向左浮动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44567805/

24 4 0