Is there a way to show a different color background when hovering over text in a navigation bar using HTML and CSS?

My navigation bar is almost perfect, but there's one small issue: the opacity change when hovering doesn't reach all the way down to the bottom. It's a minor detail, but it bothers me. Here are some screenshots for reference: This: https://i.sstatic.net/j7Ilv.jpg shows the unselected state This: https://i.sstatic.net/6X2F8.jpg shows what happens when I hover over it

I'm not sure how to fix this issue in my HTML/CSS code:

HTML:

<div class="navbar center affix" role="navigation">
    <ul>
        <li><a href=# itemprop="url"><span itemprop="titlenav">Home</span></a></li></ul></div>

CSS:

 .navbar {
    background-color:#747A80;
    width:100%;
    height:auto;
    box-shadow: 0px 1px 10px #5E5E5E;
    top:0px;
    border-bottom:solid #000000;
}

.navbar li {
    display:inline-block;
    text-align: center;
    color: #FFFFFF;
}

.navbar li a{
    display: block;
    padding:15px;
    margin-bottom:-10px;
    line-height:20px;
    color:#F9F9F9;
}

.navbar li:hover {
    opacity:1;
    background:#575A5C
}

If anyone has any suggestions on how to fix this issue, I would greatly appreciate it! Thank you!

Answer №1

Demo

If you want to eliminate the default margin added by browsers, simply include this code:

.navbar > ul {
    margin: 0;
}

Be sure to also remove the following line of code:

.navbar li a{
    margin-bottom:-10px;
}

Answer №2

eliminate the ul's margin

.navigation ul{
    margin:0;
}

also, eliminate the margin on the a tag

http://example.com/abc123/

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 function that generates a random number of <div> elements and places them inside a <li> element is a great way to dynamically add

Hey there! I could really use your assistance with this. I am trying to dynamically generate a list of items, but instead of placing each item in a separate <li>, I would like to achieve the following structure: <ul> <li> <di ...

Concealing the print option while utilizing PDFObject in conjunction with PDF.js

When displaying a file using pdf.js, I encountered issues with the print button and other functionalities. I was able to hide the buttons using CSS for Chrome, but not for Internet Explorer, where I had to resort to using JavaScript. While the JavaScript ...

Having trouble with CSS transitions not showing up correctly in Chrome. Any suggestions on how to resolve this issue?

While working on a static website, I attempted to apply a background-color transition to a button. Despite reviewing my code multiple times, I discovered that the issue was not with my coding. It seems like the browser is having trouble displaying CSS tran ...

Using jQuery to Retrieve the Background Color of an HTML Element

Suppose I have an element with the background color set using HTML like this: <div id='foo' bgcolor='red'/> Is there a way to retrieve the background color using jQuery? When I attempt $('#foo').css( "background-color" ...

Error: Unable to access the property 'fontSize' as it is undefined

<!DOCTYPE HTML> <html> <head> <title>Interactive Web Page</title> <link id="mycss" rel="stylesheet" href="mycss.css"> <script> function resizeText(size) { va ...

Construct a structure containing the key/value pairs of cells within an HTML table row using JavaScript

I'm completely new to JavaScript so please be patient with me; I'm not even sure if I'm searching for the solution correctly. Despite spending hours googling and experimenting, I still can't get it to work. My issue is related to an HT ...

Design an interactive quarter-circle using CSS styling

My goal is to create this element using CSS, however, the content inside needs to be dynamic. I initially attempted to use border-radius, but realized it is unable to achieve the desired outcome. If anyone has a solution or can offer assistance, I would g ...

I'm looking for a solution to implement a vertical carousel in Google's Materialize CSS without the need for custom development

Looking to create a unique vertical scrolling "carousel" using Google's Materialize CSS library. I have a good understanding of the steps required to construct a carousel. # haml %ul.carousel %li.carousel-item Some Content %li.carousel-item ...

Guide on incorporating a Python script into a website using DJango

I am new to Django and looking for guidance. My goal is to have users input text in an HTML textbox, then process that text using Python and display it on the website. Despite going through documentation and tutorials, I have not been successful in gettin ...

Utilize jQuery to toggle the visibility of a div depending on the numerical quantity input

I would greatly appreciate any assistance with this request, please. Here is the input that I have: <input onchange="UpdateItemQuantity(this.value,1284349,0,10352185,2579246,'','AU'); return false;" type="number" class="form-contro ...

Implement a menu that can be scrolled through, but disable the ability to scroll on the body of the website

When viewed on a small screen, my website transforms its menu into a hamburger button. Clicking the button toggles a sidebar displaying a stacked version of the menu on top of the normal website (position: fixed; z-index: 5;). This sidebar also triggers a ...

Modify the appearance of the elements dynamically by applying styles from the CSS file without relying on the

In my CSS file, I have the following styles: .myClass { ... } .myClass:focus { ... } Am I able to modify these styles from my code? For instance, can I change the focused style of an input element when a button is pressed? ...

Unusual activity observed in HTML5 contenteditable functionality

Within a list item, I have a span element. <ul> <li>text part 1 <span class="note">this is a note</span> text part 2 </li> <li>text part 3</li> </ul> When you double click on th ...

Tips for concealing information that is scrolled beneath a translucent layer

In the scenario where you have two overlapping divs, with the top one being transparent, the goal is to have the bottom div hide as it goes under the top transparent div when scrolling. It's important that the bottom div's visibility is not compl ...

Angular 7: Finding the variance between array elements

How can I subtract the values from the first 3 rows of the table? The formula is TVA Collectée - TVA Déductible - TVA Déductible/immo If the result is positive, it should be displayed in the box labeled TVA à Payer. If it's negative, it should g ...

What is the best way to display three columns on a desktop computer but only one column on a mobile device?

I need help aligning my content in a way that it appears as one big column in the center, with two additional columns on the left and right sides (similar to the image provided). The background color is just for visual reference. https://i.sstatic.net/7a4 ...

ERROR: The Search function is not defined and cannot be accessed when the HTMLInputElement event is triggered

I am working on an app that utilizes Marvel's API, and I've been having trouble implementing a search bar in the application. Whenever I attempt to search for a name within this API, the function Search() is showing up as undefined in the HTML. ...

Tips on effectively managing sibling nodes with unique behavior on the initial one

Greetings and thank you for taking the time to read and assist. While I have gained a good understanding of how XSLT 1.0 processes XML, there is one issue that continues to baffle me. The problem arises from having a template that matches the first node ...

Error Encountered: Nested textarea not supported in HTML

Below is the code I am working with. The issue lies with the <textarea>. In my form, there is a textarea. When I insert another <textarea> within the ckeditor value (HTML), the inner textarea ends up closing the parent textarea. Is there a sol ...

Firefox is giving me trouble with my CSS/JS code, but Chrome seems to be working

Having some trouble with this code - it seems to be working fine in most browsers, but Firefox is giving me a headache. I've tried using the moz abbreviations in CSS and JS tweaks, but no luck. Is there a property that Mozilla Firefox doesn't sup ...