The alignment of the horizontal menu items is off

Currently, I am working with asp.net and dealing with a horizontal menu issue. The alignment problem arises where the right side of Menu B appears higher than the left one (Menu A). I have included my code below for reference. Any suggestions or assistance would be greatly appreciated.

HTML:

<div id="head">

        <div id="exit"><span style="color:#222535">Exit</span></div>

         <ul id="navWrapper"> <!-- Top Nav-->
             <li><!-- Menu B--->
                <span style="color:#190d69;font-size:12px;font-style:normal;font-weight:bold;">Name Surname here</span>

                <ul>
                    <li><a href="#">Menu B, item 1</a></li>
                    <li><a href="#">Menu B, item 2</a></li>
                </ul>

            </li><!-- Menu B-->
            <li><!-- Menu A-->
                <a href="#">Menu A</a>
                <ul>
                    <li> <a href="#">Menu A, item 1</a></li>
                     <li> <a href="#">Menu A, item 2</a></li>
                </ul>
             </li><!-- Menu A -->

        </ul><!-- Top Nav-->

        </div>

CSS:

#exit {
float:right;
background-color:#d2f1e6;
color:#f2f9ff;
width:10%;
height:43px;
border-left:1px solid #ccc;
cursor:pointer;
}
    #exit span {
    float:right;
    font-family:Calibri;
    font-size:15px;
    color:#02012e;
    height:27px;
    margin-top:11px;
    margin-right:9px;
    }

/*Top menu style*/
a, a:hover {
      text-decoration: none;
    }

    /**********/

    ul#navWrapper {
        width:100%;
      border: 0 black solid;
      /*margin-left: -39px;*/
      /*float: right;*/
      margin-top:0px;
      margin-right:0px;
    }

    ul#navWrapper li {
        width:15%;
        height:42px;
      border: 0 red dashed;    
      float: right;
      list-style: none;
      margin-right: 0px;
      background-color: #DDD;
      padding: 0 0.25em;
      /*border-radius: 4px;*/
      /*box-shadow: 3px 3px 6px 1px #333;*/
    }

    ul#navWrapper li li {
        width:150px;
        height:40px;
      border: 0 blue dashed;    
      float: none;
      margin-left: -44px;
      margin-top: 2px;
      background-color:#fff;
      border-bottom:2px solid #fff;
    }

    ul#navWrapper li li:first-child { 
      margin-top: 23px;
    }

    ul#navWrapper ul {
      display: none;
      position: absolute;
      background-color: #FFF; /* For non-CSS3 browsers. */
      background-color: rgba(255, 255, 255, 0);
    }

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

    ul#navWrapper li img {
    width:33px;
    height:43px;
    float:left;
    margin-right:10px;
    background-color:#ccc;
}

    ul#navWrapper li span {
    font-family:Calibri;
    font-size:12px;
    color:#02012e;
    float:left;
    margin-right:5px;
    margin-top:4px;

    }

    ul#navWrapper li:hover {
      background-color: #8C8D61;
    }
        ul#navWrapper li li:hover {
            background-color:#fff;
        border-bottom:2px solid #0f1430;
        }

This is the corresponding Fiddle link: http://jsfiddle.net/a6u47sa2/

Answer №1

When utilizing float: left, I encountered no issues at higher resolutions. To address this, maintain the position as absolute and include top: 57px. Additionally, eliminate margin-top from ul#navWrapper li li:first-child:

#exit {
  float: right;
  background-color: #d2f1e6;
  color: #f2f9ff;
  width: 10%;
  height: 43px;
  border-left: 1px solid #ccc;
  cursor: pointer;
}
#exit span {
  float: right;
  font-family: Calibri;
  font-size: 15px;
  color: #02012e;
  height: 27px;
  margin-right: 9px;
}
/*Top menu style*/

a,
a:hover {
  text-decoration: none;
}
/**********/

ul#navWrapper {
  width: 100%;
  border: 0 black solid;
  /*margin-left: -39px;*/
  /*float: right;*/
  margin-top: 0px;
  margin-right: 0px;
}
ul#navWrapper li {
  width: 15%;
  height: 42px;
  border: 0 red dashed;
  float: right;
  list-style: none;
  margin-right: 0px;
  background-color: #DDD;
  padding: 0 0.25em;
}
ul#navWrapper li li {
  width: 150px;
  height: 40px;
  border: 0 blue dashed;
  float: none;
  margin-left: -44px;
  margin-top: 2px;
  background-color: #fff;
  border-bottom: 2px solid #fff;
}
ul#navWrapper li li:first-child {
  /* margin-top: 23px; */
}
ul#navWrapper ul {
  display: none;
  position: absolute;
  background-color: #FFF;
  /* For non-CSS3 browsers. */
  background-color: rgba(255, 255, 255, 0);
  top: 57px; /*add top*/
}
ul#navWrapper li:hover ul {
  display: block;
}

ul#navWrapper li img {
  width: 33px;
  height: 43px;
  float: left;
  margin-right: 10px;
  background-color: #ccc;
}
ul#navWrapper li span {
  font-family: Calibri;
  font-size: 12px;
  color: #02012e;
  float: left;
  margin-right: 5px;
  margin-top: 4px;
}
ul#navWrapper li:hover {
  background-color: #8C8D61;
}
ul#navWrapper li li:hover {
  background-color: #fff;
  border-bottom: 2px solid #0f1430;
}
<div id="head">
  <div id="exit"><span style="color:#222535">Exit</span>
  </div>
  <ul id="navWrapper">
    <!-- Top Nav-->
    <li>
      <!-- Menu B---> <span style="color:#190d69;font-size:12px;font-style:normal;font-weight:bold;">Name Surname here</span>

      <ul>
        <li><a href="#">Menu B, item 1</a>
        </li>
        <li><a href="#">Menu B, item 1</a>
        </li>
      </ul>
    </li>
    <!-- Menu B-->
    <li>
      <!-- Menu A--> <a href="#">Menu A</a>

      <ul>
        <li> <a href="#">Menu A, item 1</a>
        </li>
        <li> <a href="#">Menu A, item 1</a>
        </li>
      </ul>
    </li>
    <!-- Menu A -->
  </ul>
  <!-- Top Nav-->
</div>

Answer №2

Eliminate the float:left property from the ul#navWrapper li span selector

Answer №3

To ensure consistency in styling, it is recommended to use a div element instead of span when dealing with inline elements. Additionally, if the font size of an element is smaller than another element, adjusting the line-height can help match their heights.

<div style="color:#190d69;font-size:12px;font-style:normal;font-weight:bold;line-height:20px;">Enter Firstname Lastname here</div>

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

Adjustments to the positioning of masonry columns

Hello everyone, I'm in need of some assistance with editing this code. My goal is to make the effect clickable rather than activated by hovering. You can view the current code snippet here. Here is the existing code: $container.find('.shifty-i ...

Stop iPhone body scrolling when fullscreen overlay is opened

My goal is to prevent the body from scrolling when my fullscreen overlay navigation is open. I have added a class show-nav to the body with the CSS attribute overflow: hidden, which works perfectly on desktop but not on iPhones. After researching similar ...

The JQuery File-Upload plugin remains inactive even after a file has been chosen

I am currently working on integrating the JQuery File-Upload plugin (). The issue I'm facing is that it doesn't respond when a file is selected. Here are some potential problems to consider: No errors appear in the Chrome console. Selecting a ...

What is the method to obtain the content height of individual pages in Android, with or without the use of JavaScript?

I am facing an issue while trying to retrieve the content height of each webpage consecutively. When I load pages separately, I can successfully get the height of each page. However, when I attempt to fetch the content height continuously for webpages in a ...

I am struggling to align elements properly with Bootstrap, and I am encountering issues with the border radius of a specific div

I'm having trouble aligning all the elements in the center of my login form created with HTML and Bootstrap. The header appears to be center-aligned, but it is not vertically aligned with the other elements. I've been using the Grid system and ne ...

Tips for ensuring that flex-box children can scroll properly

I'm having trouble getting the content to scroll correctly while dealing with nested flex-box structures. Below is my CSS code: html,body,#root{ width:100%; height:100%; padding:0; margin:0; } .flex-fill{ height:100%; width:100%; ...

Leverage the input value from a text field within the same HTML document

Is it possible to utilize the input text value assigned to name='t0' within the same HTML document? Here's the code snippet you can refer to - <!DOCTYPE html> <head> <link rel="stylesheet" href="https://sta ...

I have been working on creating a hangman game, and although I have figured out the logic behind it, I am experiencing an issue where it is not functioning properly. After inspect

I am currently working on a basic hangman game using only HTML and JavaScript. I have the logic in place, but it doesn't seem to be functioning correctly. When I inspected the element, it showed an error saying 'undefined toUppercase.' As a ...

CSS styling on top points gets lost when scrolling

My screen displays an image with bubbles scattered randomly, each positioned using CSS styles for top and left. Strangely, when I scroll, all the bubbles lose their top style and reposition themselves to the bottom of the image. If anyone has insight into ...

Problematic situation concerning the lack of effectiveness of jQuery's .removeClass() function

I am encountering a strange issue with some code that adds and removes classes from an element in JavaScript. Despite my best efforts, I cannot replicate the odd behavior in a simple jsfiddle example. Below is the relevant section of JavaScript that is ca ...

Expanding the width of three floating divs in the center to match the width of the parent container div

In my design, I have a parent container with three inner divs that are floated. The left and right divs have fixed sizes, however, I need the center div to expand and fill the space available within the parent container. <div class="parent-container"&g ...

The CSS cubic-bezier fails to smoothly transition back to its initial position

I created an animation that works perfectly when hovering over the target elements, however, it doesn't smoothly transition back to its original position when the cursor moves outside of the target element. Instead, it snaps back abruptly and unattrac ...

Content positioned to the left with a clickable button aligned to the right all in one row

Can someone please assist me with this dilemma? I am trying to align text and a button on the same line, with the text on the left side and the button on the right. <div style="display: inline-block;"> <h2>Welcome ${faculty.getFirstName()} ...

execute the function based on the given ID

I've been attempting to dynamically add content using a function. My goal is for the content with the same anchor ID as the clicked anchor to be added, but it seems like nothing is happening. Is there a more effective approach to achieve this? $(&a ...

The visibility of a CSS class is rendered non-apparent when formed through the implementation

function retrieve_files(){ $.ajax({ type: "GET", url: "retrieve_files.php", cache: false, success: function(result){ $("#insideT").html(result); } }); } retrieve_files.php $dir = 'upload ...

How to enlarge the size of specific letters in HTML

I am looking to enhance the values of C and I. In addition, I am utilizing ::first-text{}. This is currently functioning well. Now, the question arises - how can I elevate the value of I. <p>Creating and Implementing</p> <center> < ...

Integrate the dForm plugin with a convenient time picker widget

Currently, I am attempting to integrate a time picker widget into a jQuery plugin called dForm. The specific timepicker widget can be found at the following link: https://github.com/jonthornton/jquery-timepicker Despite reviewing the dForm documentation, ...

What is the process for updating a collection in MongoDB database with PHP?

After writing a code snippet to gather user input through a form and update a collection based on the entered product ID, I am encountering issues with incorrect results. It seems that I am unable to fetch the correct product ID value, which is causing t ...

The collapsible section expands upon loading the page

Trying to implement Disqus as a plugin on my test webpage, I created a collapsible section with a "Show comments" button. The idea was to hide the plugin by default and reveal it only when users click on "Show comments". Despite using the w3schools example ...

A step-by-step guide on how to substitute document.write with document.getElementById('ElementID').innerHTML

As someone who is not a programmer, I often find myself attempting to grasp code and make adjustments through trial and error. Currently, I am faced with the challenge of modifying the document.write function in the function pausescroller within a Joomla m ...