html - 为父菜单点着色

标签 html css menu hover dropdown

我的问题是,如果我将鼠标悬停在子菜单上,则上级菜单不会。我想悬停新闻和子点(例如补丁)。但是,如果我将 Patches 悬停在 News 上,则不会。我希望你能帮助我

这些是我的代码。

nav  .aktuell > a{
    background-color: #576574;
}
nav {
    width: 100%;
    height: 48px;
    background-color: #8395A7;
}
nav ul {
    list-style: none;
    margin: 0;
    padding: 0;
}
nav > ul > li {
    float: left;
}
nav > ul > li > ul {
    display: none;
}
nav > ul a {
    display: block;
    white-space: nowrap;
    padding: 15px;
    background: #8395A7;
    text-decoration: none;
}
nav ul > li > ul > li a {
    background: #8395A7;
    color: white;
}
nav > ul > li:hover > ul {
    display: block;
    position: absolute;
}
nav > ul > li > ul > li {
    position: relative;
}
nav ul li a:hover {
    background-color: #576574;
}
nav ul li a {
    color: white;
}
    	<nav>
    		<ul>
    			<li class="aktuell"><a href="index.html">Startseite</a></li>
    			<li><a>News</a>
    				<ul>
    					<li><a href="news-patches.html">Patches</a></li>
    					<li><a href="news-champions.html">Champions</a></li>
        			</ul>
    			</li>
    			<li><a href="guides.html">Guides</a></li>
    			<li><a href="kontakt.html">Kontakt</a></li>
    			<li><a href="impressum.html">Impressum</a></li>
    		</ul>
    	</nav>

谢谢你的帮助:)

最佳答案

你需要改变

nav ul li a:hover {
    background-color: #576574;
}

nav ul li:hover > a {
    background-color: #576574;
}

nav  .aktuell > a{
    background-color: #576574;
}
nav {
    width: 100%;
    height: 48px;
    background-color: #8395A7;
}
nav ul {
    list-style: none;
    margin: 0;
    padding: 0;
}
nav > ul > li {
    float: left;
}
nav > ul > li > ul {
    display: none;
}
nav > ul a {
    display: block;
    white-space: nowrap;
    padding: 15px;
    background: #8395A7;
    text-decoration: none;
}
nav ul > li > ul > li a {
    background: #8395A7;
    color: white;
}
nav > ul > li:hover > ul {
    display: block;
    position: absolute;
}
nav > ul > li > ul > li {
    position: relative;
}
nav ul li:hover > a {
    background-color: #576574;
}
nav ul li a {
    color: white;
}
<nav>
    		<ul>
    			<li class="aktuell"><a href="index.html">Startseite</a></li>
    			<li><a>News</a>
    				<ul>
    					<li><a href="news-patches.html">Patches</a></li>
    					<li><a href="news-champions.html">Champions</a></li>
        			</ul>
    			</li>
    			<li><a href="guides.html">Guides</a></li>
    			<li><a href="kontakt.html">Kontakt</a></li>
    			<li><a href="impressum.html">Impressum</a></li>
    		</ul>
    	</nav>

关于html - 为父菜单点着色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53547560/

相关文章:

twitter-bootstrap - 集成 css 框架仅在指定类或 id 中工作

升级到 Ubuntu 13.10 后菜单未显示

HTML - 如何将 float 元素的宽度设置为其父 div 的 100%?

html - 使用 htaccess 隐藏文件夹或路径 css js 文件

javascript - 谷歌应用脚​​本: Calling a function from menu with a spreadsheet range as the parameter

CSS:固定水平菜单,可变宽度选项卡,使用 ul

html - 如何在 CSS 中水平拉伸(stretch)图像并在 HTML 中显示 3 个单独的图像

JavaScript 链接在 Chrome 中有效,但在 Firefox 中无效

javascript - 文本 slider 在每次迭代后从左侧增加偏移量

html - 如何更改YouTube订阅小部件的显示属性?