A small space underneath the <a> element nested within a <li> tag within a navigation bar

As a new programmer, I am currently working on creating a navbar. However, I have encountered an issue where there are small gaps underneath the user when my cursor hovers over it.

There is a white gap under the user element.

I expect that the hover background color will fill up the entire height without leaving any gaps.

https://i.sstatic.net/0fzs9kCY.png

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

nav {
  height: 50px;
  background-color: rgb(255, 255, 255);
  justify-content: space-between;
  align-self: center;
}

nav li {
  float: right;
  margin: 0;
}

nav>ul {
  list-style-type: none;
  display: block;
  padding: 0px;
  margin: 0px;
  overflow: hidden;
}

nav>ul>li>a {
  text-decoration: none;
  color: rgb(0, 0, 0);
  padding: 15px;
  display: block;
  text-align: center;
}

li a:hover {
  text-decoration: none;
  display: flex;
  transition: .0s;
  height: 100%;
  color: rgb(255, 255, 255);
  background-color: rgb(255, 178, 54);
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css" integrity="sha512-SnH5WK+bZxgPHs44uWIX+LLJAJ9/2PkPKZ5QiAj6Ta86w+fsb2TkcmfRyVX3pBnMFcV7oQPJkl9QevSCWr3W6A==" crossorigin="anonymous" referrerpolicy="no-referrer"
/>

<header class="header">
  <?php session_start(); ?>
  <nav>
    <ul>
      <?php if (isset($_SESSION['status']) && $_SESSION['status'] == "login") { ?>
      <li><a class="roboto-medium" href="#">STORE</a></li>
      <li><a class="roboto-medium" href="#">CONTACT</a></li>
      <li><a class="roboto-medium" href="#">HOME</a></li>
      <?php } else { ?>
      <li>
        <a class="fa fa-user" href="#"></a>
      </li>
      <li><a class="roboto-medium" href="#">REGISTER</a></li>
      <?php } ?>
    </ul>
  </nav>
</header>

Answer №1

Adjust the ul, li, and a elements to have a height of 100%

.navigation li {
  float: right;
  margin: 0;
  height: 100%;
}

.navigation > ul {
  list-style-type: none;
  display: block;
  padding: 0px;
  margin: 0px;
  overflow: hidden;
  height: 100%;
}

.navigation > ul > li > a{
  text-decoration: none;
  color: rgb(0, 0, 0);
  padding: 15px;
  display: block;
  text-align: center;
  height: 100%;
}

Answer №2

nav {
  height: 50px;
  background-color: rgb(255, 255, 255);
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

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

nav li {
  margin: 0;
}

nav li a {
  text-decoration: none;
  color: rgb(0, 0, 0);
  padding: 0 15px;
  display: flex;
  align-items: center;
  height: 50px;
  line-height: 50px;
  transition: background-color 0.3s;
}

nav li a:hover {
  color: rgb(255, 255, 255);
  background-color: rgb(255, 178, 54);
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css" integrity="sha512-SnH5WK+bZxgPHs44uWIX+LLJAJ9/2PkPKZ5QiAj6Ta86w+fsb2TkcmfRyVX3pBnMFcV7oQPJkl9QevSCWr3W6A==" crossorigin="anonymous" referrerpolicy="no-referrer"
/>

<header class="header">
  <?php session_start(); ?>
  <nav>
    <ul>
      <?php if (isset($_SESSION['status']) && $_SESSION['status'] == "login") { ?>
      <li><a class="roboto-medium" href="#">STORE</a></li>
      <li><a class="roboto-medium" href="#">CONTACT</a></li>
      <li><a class="roboto-medium" href="#">HOME</a></li>
      <?php } else { ?>
      <li>
        <a class="fa fa-user" href="#"></a>
      </li>
      <li><a class="roboto-medium" href="#">REGISTER</a></li>
      <?php } ?>
    </ul>
  </nav>
</header>

Give this a shot!

Customization to the nav element: - Added display: flex and align-items: center for vertical alignment of items. Enhanced styling of nav ul: - Utilized display: flex for precise horizontal arrangement with no gaps. Styling refinement for nav li a: - Incorporated display: flex and align-items: center for content centralization within the anchor element. Fine-tuned padding to 0 15px to eradicate excess space top and bottom. Defined height: 50px and line-height: 50px for full navbar coverage.

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

Gallery not responsive on HTML/CSS site

Hi there, I'm a newcomer to Stack Overflow and currently diving into the world of HTML/CSS. I've hit a roadblock with my latest project - I'm trying to create a gallery of album covers, but when I try to 'zoom in' on the webpage (n ...

Unable to get CSS Filter to function properly in Firefox

I'm having trouble with the CSS filter on my Firefox (15.0) browser. Here is the HTML code: <div class="google"> <img src="https://www.google.com/images/srpr/logo3w.png"> </div> And here is the CSS code: .google{ -moz ...

Update the text content in the specific span element when the class attribute matches the selected option in the

How can I dynamically update text inside a span based on matching classes and attributes without hardcoding them all? An ideal solution would involve a JavaScript function that searches for matches between span classes and select field options, updating t ...

Animating the background of a div element using jQuery

I am facing an issue with the code snippet below that I have written. It doesn't seem to be working as expected and I'm curious if anyone knows why. The problem is that I have set a background color on the DIV, but when hovering over it, I want ...

The total sum of various divs containing a mix of numbers and letters

I have a group of div elements with the same class, each containing a value in the format (X1), (X2),... I need to add up these numeric values only, like 1 + 2 + .... Since these divs are generated dynamically, I won't know how many there will be. How ...

Having trouble accessing certain nodes while extracting HTML text with R

I have numerous water extraction permits that are accessible online and I am looking to extract specific data from them. For example url <- "https://www.ecan.govt.nz/data/consent-search/consentdetails/CRC000002.1" While I don't have a strong know ...

(HTML) centralizing link storage

Hello, I am looking to create an HTML file but I am unsure of how to store links in a separate file. The code I currently have is: <a title="DESCR" href="LINK" target="_blank" style="color: white">NAME</a> ...

Tips for adjusting the width of Material UI TextField within a Table

I am utilizing a Material UI Table. This is how I construct it: tableValues.map((curRow, row) => { tableRows.push( <TableRow key={this.state.key + "_row_" + row}> {curRow.map((cellContent, col) => { let adHocProps ...

Is it possible to extract only the Bolded Text and store it in a String Array within a Spanned String

I need help with extracting bolded text from my paragraph-long stories that are saved as spanned strings in an EditText. The regular text is interspersed with a few bolded words here and there, and I want to be able to search through the spanned string a ...

A static iframe or an alternative solution that is not interactive

I specialize in creating websites for my clients. When they log in, they are presented with 5 different design ideas for their site - each showcasing a unique layout and color scheme. Currently, I manually upload 5 screenshots of the designs created by me ...

Svelte remains static and is not experiencing re-rendering

I am currently incorporating the history component in Svelte, where it should display when changes occur in the bids array. const bidsArray = [ { player: 0, bidType: 'pass' }, { player: 1, bidType: 'level', level: '1&apos ...

How can we effectively transform an HTML opening and closing tag into a function?

Dealing with a complex HTML tag can be challenging, especially when it appears in various parts of the code. For instance: <div class="blabla" data-test="blablabla" ... data-another-attribute="blabla" > <some complex html code ... > </ ...

Tips for creating a wide mobile menu

I am attempting to make the mobile menu full width, but so far my efforts have been unsuccessful. #menu-main-2 { background-color:#FFFFFF !important; padding-left:15px; max-width: unset; width: 100%; } view mobile menu ...

What could be causing the malfunction of Bootstrap Multiselect functionality?

I have been attempting to set up Bootstrap Multiselect but it simply refuses to work. Despite trying various solutions, I am unable to pinpoint the issue. My index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...

Adding a combination of HTML and Javascript to an element can result in unexpected behavior

http://jsfiddle.net/PeKdr/ Encountering an issue when having a JavaScript variable that contains both HTML and JavaScript, resulting in unexpected behavior in the output window. Neither of the buttons - one triggering the function appendTheString() or the ...

How can I center a Bootstrap modal vertically and make it responsive?

Is there a way to vertically center the bootstrap modal? I have been searching for a solution, but none seem to be responsive or effective. My website is using Bootstrap 3. The modal does not adjust properly on smaller screens or when the browser window i ...

What is the best way to showcase a list in three columns using PHP?

I've been struggling for hours to create a PHP code that will display a list in three columns with the following order: A D G B E H C F I Unfortunately, my current code only lists items in this order: A B C D E F G H I Here is the code I am curren ...

Is there a way to modify the form's style to show "none" without submitting the form?

Clicking the Close button will submit the form to Lcar.php. The goal is to hide the CSS and remain on the current page after clicking the button. The issue of the form being submitted to Lcar.php when the Close button is clicked arises despite the fact t ...

Position elements in the center of the page at 33.3333% width

I'm facing a challenge with centering elements that are floated left and have a width of 33.33333% on the page. I want the text inside these elements to remain aligned to the left, but I'm unsure how to go about centering the items: ul.home-pr ...

Leveraging Bootstrap grid system within AngularJS elements

I am currently working on wrapping grid element divs into Angular components in order to streamline the input process and establish a standard: <bootstrap-row> <bootstrap-input-text col=6 ng-model="$ctrl.model" label="hey!"& ...