Emerald Emerald - 5 days ago 4
CSS Question

Dropdown menu background-color

I am trying to fill up the background-color of the dropdown as red but my coding isn't working. Below are coding that I currently use.

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;}


As the result, refer image as follow :

enter image description here

Answer

.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>

Comments