`Background color for the dropdown menu`

I've been attempting to change the background-color of the dropdown menu to red, but my code doesn't seem to be working properly. Here is the current code that I am using:

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

The result can be seen in the image below:

https://i.sstatic.net/ihd2r.png

Answer №1

.navMenu ul.menu > li {list-style: none; color: #000; font-weight: bold; float: left; position: relative;}
.navMenu ul.menu > li a {text-decoration: none; color: #000;padding: 5px 25px;display: block;}
.navMenu ul.menu > li:hover {background-color: #f44336; cursor: pointer;}
.navMenu ul.menu > li a:hover {background-color: #f44336; color: #fff!important; cursor: pointer;}
.navMenu ul.menu ul {display: none; list-style-type: none; background-color: #f44336;padding: 0;width: 100%;}
.navMenu ul.menu > li:hover ul {display: block; padding: 0; margin: 0; z-index: 10; position: absolute;}
<div class="navMenu">
<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>

Answer №2

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

.navMenu ul.menu > li a:hover {color: #fff!important;}

.navMenu ul.menu > li {
    display:    block;
}

.navMenu ul.menu > li ul {
    padding:            0px;
    margin:             0px;
    margin-top:         0px;
}

.navMenu ul.menu > li li {
    display:    block;
    padding:    0px;
    width:      100%;
    margin:     0px;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating a Functional Right Arrow on a Pure CSS Select Menu/Dropdown

I have implemented a custom select/dropdown menu by following the solution provided here: The functionality works well, but I am facing an issue where the dropdown options only appear when clicking on the box. Clicking on the 'arrow' located on ...

Creating an interactive map on an image using HTML and drawing circles

I've been experimenting with drawing circles on images using the map property in HTML. I have an image set up, and when clicking on the image in JavaScript, I'm adding the area coordinates for the map property. However, I keep encountering a null ...

Pseudo-element fails to display in React when applied to a paragraph tag, even with display block property set

I am experiencing an issue where the pseudo element ::after is not appearing in my browser. I am currently working with React.js and Material UI's makeStyles. Here is the code snippet causing the problem: modalTitle: { borderBottom: '2px sol ...

Interacting with an HTML menu using Three.js

I am currently developing an HTML menu to overlay onto the Three.js viewport. However, I am facing a challenge with achieving consistent interaction with the menu. While I can successfully click on my <input type="range"> sliders and other elements, ...

Obtaining user input from a content editable div in a React component

Get content from editable div const contentref=useRef() const handleclick=()=>{ setContent(contentref.current.value) console.log(contentref.current.value) } Element Properties <div name="textbox" ref ={contentref} cla ...

Using jQuery to hide an element when the script is invoked

I'm encountering an issue where I create a file containing HTML and JavaScript that is loaded later via AJAX. One of the files should hide an element after it is loaded, but for some reason, it is not working. I have tried various methods to hide the ...

Creating a repeating sequence in HTML: A step-by-step guide

I have an HTML file containing a portfolio. Each portfolio item is structured like this: <div class="item"> <div class="portfolio-item"> <a href="img/portfolio-item-1.jpg" data-lightbox="ima ...

Using jQuery to load content into a jQuery UI dialog box

I am looking to implement a pop-up that displays content from another asp page. To achieve this, I am using jquery.load to load the page into a div and jquery-ui.dialog. This is my code: <div id="dialog"></div> Inside the document ready fun ...

Guide to leveraging clsx within nested components in React

I am currently using clsx within a React application and encountering an issue with how to utilize it when dealing with mappings and nested components. For instance: return ( <div> <button onClick={doSomething}>{isOpened ? <Component ...

How can I align a fixed-width div beside a floating div that is in percentage?

Having encountered various challenges (not to come across as a complaining troublemaker), my current struggle lies in determining the most effective way to float two divs alongside each other. One with a fixed width and the other with a percentage width to ...

Methods for switching the visibility of table rows

In my XSLT (html) xml style sheets, I am currently toggling the visibility of some table rows. Initially, I hide 3 out of the 6 rows, and then upon clicking, I want to hide 1 row and reveal 3 others. Here is the initial setup: on load xml first row - T ...

Insert fresh div elements chronologically using jQuery

When a user clicks on the ".u-post-button" button, this script is triggered. It retrieves the content of the comment input field and posts it to the server as a JSON object. The returned data containing the comment information is then appended after the ...

Breaking apart a pipe-separated text and sending it through a JavaScript function

CSS: <div class="pageEdit" value="Update|1234567|CLOTHES=5678~-9876543?|5678"> <a href="https://host:controller">Update</a> </div> Trying to retrieve the data within the div and pass it into a JavaScr ...

How can I prevent the content on my page from adding padding to the body of the page?

I'm working on designing a simple interface similar to Slack. However, I'm facing an issue where the left navigation is creating some padding from the body, even though I have set the padding and margin to zero. .app { display: flex; flex- ...

Different methods for adjusting CSS properties that are dependent on other components

I'm currently working on a website using the React library. While I have made progress, I am stuck on how to adjust CSS properties that are interdependent. Specifically, I need help removing the blur filter from my text area .mirror-container which is ...

Encountered a data retrieval issue while accessing my post.html.erb file

Unfortunately, I am unable to provide specific details about my issue as I am unsure of the exact cause. /db/migrate/XXXXXX_create_restaurants.rb ... t.string :restaurant_name t.string :restaurant_addr ... /app/controllers/restaurant.rb def post @res ...

Is there an animated Google Contact Form in the works?

Is it possible to replicate the onclick animation featured on the Google login form? The animation involves the placeholder text shrinking and moving to the top left corner as you click the button box, while a border forms around the text. Click here to ...

What is the reason behind the CSS not rendering when async:false is used?

I find it peculiar and am actively seeking an explanation for this anomaly. In my code snippet, the AJAX call seems to be causing unexpected behavior: $('.edit-config').click(function() { var that = this; var msg; ip ...

Are there potential security vulnerabilities associated with AJAX form validation?

In the process of form validation, I am seeking a solution that does not involve reloading the entire page. Currently, I am utilizing JavaScript for this task, but I am aware of its security vulnerabilities. To address this concern, I am considering implem ...

What is the best way to achieve alignment of my div containers with CSS?

How do I horizontally align my containers inside another container and make them center-aligned when the window is resized? Every time I try, the containers end up in the wrong position. Please help me out. Below is the code: Index Page <html> < ...