gpt4 book ai didi

html - CSS 和 HTML 编码

转载 作者:行者123 更新时间:2023-11-28 17:55:48 25 4
gpt4 key购买 nike

我正在尝试制作一个子级下拉菜单。我已经成功获得了第一个菜单,但是当您将鼠标悬停在第一个下拉菜单上时,无论发生什么情况,第二个菜单都会突出显示。我想要它,以便仅当您将鼠标悬停在第一级上时才会出现第二级。任何帮助将不胜感激。以下是我的html代码:

HTML

<nav>
<ul>
<li><a href="#"><span></span> Home </a></li>
<li>
<a href="#"><span></span> Jwewlry </a>
<ul>
<li>
<a href="#"><span></span> Rings </a>
<ul>
<li><a href="#">Silver</a></li>
<li><a href="#">Copper</a></li>
<li><a href="#">Bronze</a></li>
</ul>
</li>
<li><a href="#"><span></span> Pendants </a></li>
<li><a href="#"><span></span> Bracelets </a></li>
<li><a href="#"><span></span> Necklaces </a></li>
<li><a href="#"><span></span> Other </a></li>
</ul>
</li>
<li><a href="#"><span></span> Testimonials </a></li>
<li><a href="#"><span></span> Latest Offers </a></li>
<li><a href="#"><span></span> News </a></li>
<li><a href="#"><span></span> Contact Us </a></li>
</ul>
</nav>

CSS

nav {
/* Repeating background image */
background: url(texture.png);
width: 210px;
margin: 20px;
}

nav ul {
/* Remove bullet points */
list-style: none;
margin: 0;
padding: 0;
}

nav ul li {
/* Any child positioned absolutely will be positioned relative to this */
position: relative;
}

nav ul li ul li ul li {
position: block;
}

nav a {
color: #e8e8e8;
padding: 12px 0px;
/* Fill all available horizontal space */
display: block;
/* Remove underline */
text-decoration: none;
/* New CSS3 animations: apply transition to background property, taking 1s to change it */
transition: background 1s;
-moz-transition: background 1s;
-webkit-transition: background 1s;
-o-transition: background 1s;
font-family: tahoma;
font-size: 13px;
text-transform: uppercase;
padding-left: 20px;
}

nav a:hover {
/* RGBA background for transparancy: last number(0.05) is the transparency */
background: RGBA(255,255,255,0.05);
color: #fff;
}

nav ul li:hover ul {
/* When list item is hovered, display UL nested within. */
display: block;
}

nav ul ul {
/* Remove element from document flow */
position: absolute;
/* Position relative to its parent &lt;li&gt; */
left: 210px;
top: 0;
border-top: 1px solid #e9e9e9;
display: none;
}

nav ul ul li {
width: 200px;
background: #f1f1f1;
border: 1px solid #e9e9e9;
border-top: 0;
}

nav ul ul li a {
color: #a8a8a8;
font-size: 12px;
text-transform: none;
}

nav ul ul li a:hover {
color: #929292;
}

nav span {
width: 12px;
height: 12px;
background: #fff;
display: inline-block;
float: left;
margin-top: 3px;
margin-right: 20px;
position: relative;
transition: all 0.5s;
-moz-transition: all 0.5s;
-o-transition: all 0.5s;
-webkit-transition: all 0.5s;
}

nav a:hover span {
background: #7d2c41;
transform: rotate(90deg);
-moz-transform: rotate(90deg);
-webkit-transform: rotate(90deg);
}

/* Horizontal line */
nav span:before {
content: "";
width: 12px;
height: 2px;
background: #3a3b3b;
position: absolute;
left: 0px;
top: 5px;
}

/* Vertical line */

nav span:after {
content: "";
width: 2px;
height: 12px;
background: #3a3b3b;
position: absolute;
left: 5px;
position: top;
}

最佳答案

只需将悬停选择器更改为:

nav ul li:hover > ul

这样只有第一个子元素 ul 是可见的。

关于html - CSS 和 HTML 编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21368470/

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