gpt4 book ai didi

html - 下拉菜单背景颜色

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

我正在尝试将下拉菜单的背景色 填充为红色,但我的编码不起作用。以下是我目前使用的编码。

HTML

<div class="divMenu">
<ul class="menu">
<li><a href="index.html">HOME</a></li>
<li>
<a href="brands.html">BRANDS</a>
<ul>
<li><a>Brand 1</a></li>
<li><a>Brand 2</a></li>
<li><a>Brand 3</a></li>
</ul>
</li>
<li>
<a href="categories.html">CATEGORIES</a>
<ul>
<li><a>Category 1</a></li>
<li><a>Category 2</a></li>
<li><a>Category 3</a></li>
</ul>
</li>
<li><a href="new_arrivals.html">NEW ARRIVALS</a></li>
<li><a href="contact.html">CONTACT</a></li>
</ul>
</div>

CSS

.divMenu ul.menu > li {list-style: none; color: #000; font-weight: bold; float: left; padding: 5px 25px;}
.divMenu ul.menu > li a {text-decoration: none; color: #000;}
.divMenu ul.menu > li:hover {background-color: #f44336; cursor: pointer;}
.divMenu ul.menu > li a:hover {background-color: #f44336; color: #fff!important; cursor: pointer;}
.divMenu ul.menu ul {display: none; list-style-type: none; background-color: #f44336;}
.divMenu ul.menu > li:hover ul {display: block; padding: 0; margin: 0; z-index: 10; position: absolute;}

结果,引用图片如下:

enter image description here

最佳答案

.divMenu ul.menu > li {list-style: none; color: #000; font-weight: bold; float: left; position: relative;}
.divMenu ul.menu > li a {text-decoration: none; color: #000;padding: 5px 25px;display: block;}
.divMenu ul.menu > li:hover {background-color: #f44336; cursor: pointer;}
.divMenu ul.menu > li a:hover {background-color: #f44336; color: #fff!important; cursor: pointer;}
.divMenu ul.menu ul {display: none; list-style-type: none; background-color: #f44336;padding: 0;width: 100%;}
.divMenu ul.menu > li:hover ul {display: block; padding: 0; margin: 0; z-index: 10; position: absolute;}
<div class="divMenu">
<ul class="menu">
<li><a href="index.html">HOME</a></li>
<li>
<a href="brands.html">BRANDS</a>
<ul>
<li><a>Brand 1</a></li>
<li><a>Brand 2</a></li>
<li><a>Brand 3</a></li>
</ul>
</li>
<li>
<a href="categories.html">CATEGORIES</a>
<ul>
<li><a>Category 1</a></li>
<li><a>Category 2</a></li>
<li><a>Category 3</a></li>
</ul>
</li>
<li><a href="new_arrivals.html">NEW ARRIVALS</a></li>
<li><a href="contact.html">CONTACT</a></li>
</ul>
</div>

关于html - 下拉菜单背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40829329/

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