Get rid of the background shade in the area separating the menu items within a CSS menu

Is there a way to add some spacing between the menu items without affecting the background color applied to the anchor tags?

I currently use a right margin of 13px for the spacing, but it also applies the background color, which is not the desired outcome. I want the background color to only be visible on the list and anchor elements, and not in the margin space between them.

HTML:

<body>
<div id="container">
    <div id="title">
        Vanneuville <br />
        Wielersport
    </div>

    <div id="menu">
        <ul id="nav">
            <li><a href="#">Home</a></li>
            <li>
                <a href="#">Fietsen</a>
                <ul>
                    <li><a href="#">Recreationeel</a></li>
                    <li><a href="#">Electrische fietsen</a></li>
                    <li><a href="#">Koersfietsen</a></li>
                    <li><a href="#">Mountainbikes</a></li>
                    <li><a href="#">Kinderfietsen</a></li>
                </ul>   
            </li>
            <li><a href="#">Kledij</a></li>
            <li><a href="#">Helmen</a></li>
            <li><a href="#">Tweedehands</a></li>
            <li><a href="#">Verhuur</a></li>
            <li><a href="#">Contact</a></li>
        </ul>
    </div>

    <div class="clear" id="content">
        <p>Some paragraph</p>
    </div>
</div>

CSS:

body
 {
background: url('../images/peloton.jpg') no-repeat center center fixed;
   -webkit-background-size: cover; /*for webKit*/
-moz-background-size: cover; /*Mozilla*/
-o-background-size: cover; /*opera*/
background-size: cover; /*generic*/
font-family: "Cambria";
}

#container{
width: 1000px;
margin-left: auto;
margin-right: auto
 }

#title{
display: inline-block;
font-size: 80px;
background-color: black;
color: white;
opacity: 0.8;
padding: 15px;
float:left;
}

#menu{
float:left;
padding-top: 10px;
font-size: 31px;
}

#content{
padding-top: 10px;
background-color: red;
background-clip: content-box;
}

.clear{
clear: both;
}

ul{
list-style-type: none;
padding:0;
margin:0;
}

ul#nav li{
background: grey;
float: left;
}

ul#nav li a{
display: block;
padding: 5px 10px;
color: #000;
text-decoration: none;
border: 1px solid #ccc;
margin-right: 13px;
}

ul#nav li a:hover{
background: #aaa;
}

ul#nav li ul li{
float: none;
}

ul#nav li ul{
position: absolute;
display: none;
}

ul#nav li:hover ul{
display: block;
}

Answer №1

Make sure to transfer the background color setting from the list item (li) to the anchor(a) element.

ul#nav li{
    float: left;
}

ul#nav li a{
    background: grey;
}

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

What is the best way to scale a div proportionally within a bootstrap grid?

Despite spending hours reading numerous online sources, I am still struggling to fully grasp the CSS/HTML box model. Specifically, I am attempting to create sections with a ratio of 3:2, where 3 represents the width and 2 represents the height. https://i.s ...

Creating a gap between two elements without using the space-between property

Currently working on creating a responsive menu, <div style={{ display: "flex", flexFlow: "row wrap" }}> {/* left side */} <div key="1">nav 1</div> <div key="2">n ...

Preventing Div items from rearranging during size transitions using toggleClass

When I click on an element with the ID "id", I use toggleClass to resize a div from 10px to 500px in width. This is done partly to show/hide content. However, the issue arises when the transition occurs and the contents of the div start rearranging, overfl ...

Enlarge the image to fill the entire screen

Currently, I am working on a webpage where I am displaying data fetched from a database using Laravel framework. The code snippet is shown below: Here is how the webpage looks like - image1 What I aim to achieve is to make the div go fullscreen upon clic ...

Excessive white space within a relative block div causing the content to appear smaller in comparison

Currently, I am developing a straightforward form that includes CSS-based help boxes. These help boxes are designed to appear when the user hovers over the corresponding row. After leaving my project untouched for a few days, I encountered some bugs upon ...

A surprise awaits in IE with the unusual appearance of a div display

body { background: #9cdcf9 url(/images/left_cloud.png) bottom left no-repeat; font-family:\"Trebuchet MS\"; padding:0; margin:0; border:0; } #cloud-container { width: 100%; background: url(/images/right_cloud.png) bott ...

Shift the image down to the bottom of the sidebar

This is the code for my sidebar HTML, with the side navigation bar positioned on the left: #main-container { display: table; width: 100%; height: 100%; } #sidebar { display: table-cell; width: ...

Extending the length of the list items and their contents

Take a look at this website. I'm struggling with expanding the submenu list items in IE7. It seems that when you hover over one of the LIs under Restaurants, the green does not fill the entire line. I attempted using {width: 100%}, but it did not sol ...

Div's background image displays flawlessly on Code Pen desktop, yet fails to appear when viewed on mobile devices

I am currently experiencing an issue with my background images not rendering properly on mobile devices, specifically safari and chrome on iPhone XR. Although they appear to work perfectly on Code Pen - resizing properly as the viewport shrinks and switchi ...

What could be causing my title (titulo) to be misaligned? Why aren't justify and align functions fixing the issue?

My attempt to center my title "Scream" is not working as expected. Here is how it looks: Visit this link for visualization. I have tried using justify, align, and text-align properties in my CSS code but the title (titulo) remains misaligned. Surprisingly ...

How can you make the coordinates of the cursor track the cursor when it hovers over a rectangle?

The code provided below will constantly display the cursor's coordinates right below the cursor: function displayCursorCoordinates(e) { var x = event.clientX; var y = event.clientY; var coordinates = "(" + x + ", " + y + ")"; document.getEl ...

Fully responsive header designed for optimal experience at any screen height

I am facing issues with the header and cannot seem to find a solution. My goal is to make the header span 100% of the window screen height. I need a responsive header that adjusts to 100% height, and when resizing for a smaller viewport, nothing should sho ...

Having an excessive amount of CSS Sprites or none at all can be detrimental to your website's performance

UPDATE: Attempted to adjust the height to 27px as recommended by kennypu, but still facing issues. I am working with a sprite containing multiple icons that I want to extract for navigation purposes. Unfortunately, I'm struggling to properly display ...

What is the best way to horizontally align and center the navigation menu?

I've been struggling to center and align the navigation links inside this div horizontally. I attempted a few methods, but none seem to work. I managed to fix the previous issue with #centermenu, but unfortunately it still isn't functioning as e ...

Swapping one div for another, all the while incorporating a limited number of buttons within the webpage

I'm faced with a dilemma on my HTML page. In the middle of the content, there's a div that contains 4 links with images and text inside. What I'm looking to achieve is for each link to trigger a complete change in the div when clicked, with ...

The cursor image fails to function when entering a specific area within the image

I have implemented a custom cursor using the code snippet below. $("div").css('cursor','url(../graphics/system/mybg.cur),auto'); However, I am experiencing an issue where the cursor reverts to the default pointer when hovering over a ...

Troubleshooting the Gutter Problem in jQuery Isotope and Masonry

Currently, I am utilizing the Isotope jQuery plugin. While it is a fantastic tool, I am encountering a minor issue with aligning items in masonry mode. The width of my container is 960px, and I aim to have 4 items perfectly aligned as if they were adhering ...

Create a unique custom design for your Mapbox GL control

When developing the website, we utilized Angular 8, Typescript, and SCSS. We are using mgl-map to display a map, and I wanted to create a custom control for it with unique styles. I added the custom control to the map using: const centerOnCoordinatesC ...

How can AngularJS focus on the last element using ng-repeat and md-focus?

, there is a code snippet that utilizes AngularJS ng-repeat directive to iterate through 'items' and 'md-autofocus' attribute to focus on the last element. The code is contained within an md-dialog with vertical scrolling functionality. ...

What is the best way to merge a card-deck with fixed-width cards?

Currently, I am using flex-mode and aiming to create a 'deck' of 'cards' with uniform height and width. My goal is to ensure that the width remains consistent across different breakpoints. Unfortunately, I have not been able to achieve ...