How can I maintain the

I have created a menu with left and right borders to separate each item. When I hover over the menu, the background color changes to a lighter shade, which is the desired effect. However, the hover effect covers up the left border. How can I prevent the border from disappearing? I tried searching for a solution but couldn't find one. Thank you in advance.

Visit this link for reference

Here is the HTML code:

<div id="header">
<div id="menu">
        <ul>
        <li><a href="index.html">HOME</a>

        </li>
        <li><a href="products.html">PRODUCTS</a>

        </li>
        <li><a href="videos.html">VIDEOS</a>

        </li>
        <li><a href="downloads.html">DOWNLOADS</a>

        </li>
        <li><a href="contact.html">CONTACT</a>

        </li>
        <li><a href="about.html">ABOUT</a>

        </li>
    </ul>
</div>
</div>

And the CSS code:

#header {
    width:960px;
    margin: 10px auto 5px auto;
    background-color: #727272;
}
#menu {
    max-width:828px;
    bottom:0;
    right:0;
    font: 12px/18px sans-serif;
}
#menu a {
    text-decoration: none;
    display:block;
    padding: 10px 32px;
    color:#FFF;
}
#menu ul {
    text-align: left;
    display: inline;
    margin: 0;
    padding: 15px 4px 17px 0;
    list-style: none;
}
#menu ul li {
    display: inline-block;
    margin-right: -4px;
    position: relative;
    cursor: pointer;
    -webkit-transition: all 0.2s;
    -moz-transition: all 0.2s;
    -ms-transition: all 0.2s;
    -o-transition: all 0.2s;
    transition: all 0.2s;
    border-right: 1px solid #FFF;
}
#menu ul li:first-child {
    border-left: 1px solid #FFF;
}
#menu ul li:hover {
    background-color:#818181;
}

Answer №1

Check out this method.

#header {
    width:960px;
    margin: 10px auto 5px auto;
}
#menu {
    max-width:828px;
    bottom:0;
    font: 12px/18px sans-serif;
    background-color: white;
}
#menu a {
    text-decoration: none;
    display:block;
    padding: 10px 32px;
    color:#FFF;
}
#menu ul {
    text-align: left;
    display: inline;
    margin: 0;
    padding: 15px 4px 17px 0;
    list-style: none;
}
#menu ul li {
    display: inline-block;
    position: relative;
    cursor: pointer;
    -webkit-transition: all 0.2s;
    -moz-transition: all 0.2s;
    -ms-transition: all 0.2s;
    -o-transition: all 0.2s;
    transition: all 0.2s;    
     background-color: #727272;
    margin:0;
}
#menu ul li:hover {
    background-color:#818181;
}

All I did was remove the right margin and set the background color to white for the menu section.

Answer №2

My approach is to define border and spacing attributes within the A tag instead of the LI tag, effectively treating the LI tag as an "invisible" element by transferring all properties to the A tag and utilizing display:inline-block.

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

Problem concerning the Script tag within Javascript coding

This link is supposed to show a Google ad. I've attempted all possible solutions, but it still doesn't seem to be functioning correctly. My suspicion is that the issue lies with the closing script tag - </script>. Could you please copy th ...

What is the best way to choose a specific checkbox with a ::before pseudo-element?

Having trouble selecting checkboxes in a table with a ::before tag using Selenium. Even after implementing implicit and explicit waits, as well as action class for a list of elements, I still receive an "element not visible" error. How can I select a speci ...

When a radio button is chosen, multiple text fields must be completed in order to validate the form

I am working with a set of 3 radio buttons. If the last option, labeled "In Home," is chosen, then all 4 of the text fields must be filled in for the form to validate. While I have found information on how to achieve this with checkboxes or a single text f ...

Cut out a passage by using a polyline shape

I am looking to create a unique effect by clipping a text like a heading1 using an svg polyline. The concept is to place the H1 text behind the polyline background and make it appear frosted or blurred. I have successfully achieved this in the past but see ...

Select element's width decreases by 2 pixels following the application of width adjustment via jQuery

After browsing through numerous pages, I finally managed to adjust the width of my textbox and select element using jQuery 2.0. Snippet of Code from my Project: $(document).ready(function(){ $("#Text2").css('width','20 ...

Allow the checkbox to only be functional for one use

Toggle the checkboxes between enable and disable based on user's choice to edit or cancel operation. This functionality has been tested on both my Android phone and tablet devices. Upon loading the page, the HTML code appears like this: <div class ...

Create a CSS menu that centers the links

Here is the CSS code I am using for my horizontal menu: nav { height: 40px; width: 100%; background: #F00; font-size: 11pt; font-family: Arial; font-weight: bold; position: relative; border-bottom: 2px solid # ...

How can you pinpoint a particular td using both col class and td class?

.col2 .positive { background:green; } .col2.positive { background:green; } .col3 .positive { background:blue; } td{ border:1px solid blue; padding:5px; } <table> <col class="col1" /> <col class="col2" /> <col class="co ...

Position the text to the left of the floating paragraph on the right

I am looking to align some text on the right side of the page with consistent starting positions. Each paragraph has two spans, one floated left and the other floated right. Here is an example with HTML and an image included for clarity. .card { ma ...

Looking to scan through a directory of .html files in Node.js to find specific element attributes?

Imagine trying to tackle this task - it's like reaching for a needle in a haystack. Picture a folder containing a static website, complete with images, stylesheets, and HTML files. My Node application needs to dive into this folder and extract only th ...

The first generation iPad, CSS3 transformations, and the constraints on image processing due to limited RAM

During my exploration of the original iPad on iOS 5.0.1, I stumbled upon some peculiar quirks that appear to be linked to the number of images being loaded into the browser simultaneously. I noticed certain things rendering at half resolution or even lowe ...

Trouble encountered with bootstrap toggling when multiple identical inputs are used

Problem with Bootstrap toggle not working on multiple identical inputs unless the first input is pressed. Even then, not all inputs are checked/unchecked. I've created a small example I want to ensure that when one input is toggled, all others have ...

I am facing an issue where my Javascript hide and show function is not working properly when clicked. Despite not giving

I am currently working on a Javascript onClick function to toggle the visibility of content in a lengthy table. I initially set part of the table's class to display: "none" and added a button to show the hidden content when clicked. However, nothing i ...

Conceal or eliminate redundant choices in dropdown menu

I am currently working with the WebForms framework and I have encountered an issue with my dropdownlist control in one of my Forms. The Select option is sometimes being added twice, causing duplication in my form. I am looking for a way to either remove th ...

Gradually appear with jQuery while maintaining current position

Exploring Display Options In my current setup, I have text that initially has a display:none property, and jQuery is applied to fadeIn() the content. The challenge lies in the fact that since the text is centered, as each word appears, the positioning on ...

I'm having trouble getting my button to work with addEventListener while using Ejs and Express. What could

Creating a Twitter-like platform where I can post tweets and have them display on the same page has been quite challenging. I've set up each post to have an Edit button initially hidden with 'display:none'. However, when I try to click on th ...

Error occurred while trying to access a file within the server using $_GET method

Struggling to access a URL within my folder, but encountering an error. I have attempted using file_get_contents without success. Warning: include(/home/vol2_3/*****/*****/htdocs/new/td.php?r=8&ids=309834): failed to open stream: No such file or direct ...

Dynamic resizing of elements/images using jQuery to maintain proportions

My goal is to create a design where images resize proportionally with their containing elements. The challenge I am facing is achieving the proportional resizing of each image container's height as its width changes upon window resize. Currently, the ...

Checking if children have certain text using jQuery

My task involves filtering an HTML table. In order to accomplish this, I have created an 'each' callback for all 'tr' elements and check if any of their children contain a specific pattern. $("#filter").keypress(function() { var fi ...

Tips for integrating Iftop into Django framework

I am facing an issue with integrating iftop into Django. Even though it works fine on the command line, I do not get any output when trying to incorporate it into Django. Strangely, there are no errors displayed either. views.py def packets(request, temp ...