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

Adjusting the style attributes for Material-UI Icons

I could use some assistance with changing the CSS property of MUI icons in order to assign a specific color when the icon is focused. I have implemented the icons in the header and am displaying different pages below them, so I would like to give each ac ...

Elegant Bootstrap 4 Carousel featuring a glimpse of the upcoming slide alongside the primary carousel item

I am in search of a straightforward Bootstrap 4 carousel that showcases a glimpse of the next slide on the right. Despite exploring similar questions, I have not found a suitable solution. The links to those questions are: 1)Bootstrap carousel reveal part ...

Changing the background color of the canvas using Javascript

I want to create a rect on a canvas with a slightly transparent background, but I don't want the drawn rect to have any background. Here is an example of what I'm looking for: https://i.stack.imgur.com/axtcE.png The code I am using is as follo ...

Guide on showcasing jQuery variable values in PHP on a single page

I have some JavaScript and PHP code that I need help with. I want to assign a jQuery variable value to a PHP variable called $nicks, and then echo the value of $nicks on the same page. <script type="text/javascript"> var axel = 131.5678466; < ...

Is it viable to create an onClick event for the text content within a text area?

I'm working on a project that involves displaying XML data in a textarea and creating an onClick event for the content within the textarea. For example: <textarea>Hello Web, This is a simple HTML page.</textarea> My goal here is to create an ...

A guide to replacing or customizing standard components in ReactJS

I need to modify the color property of a common component so I can use it elsewhere. const ViewAllIcon = (props) => ( <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 26 ...

Highlight the parent name in the menu when I am on the corresponding child page

Here is a snippet of a recursive function: function recursive($arrays, $out) { if (is_array($arrays)){ //$out .= "<ul>"; foreach($arrays as $parent => $data) { //if parent is empty if ($parent === '') { ...

What is the best way to create some distance between a div element and the bottom of the body?

Hello, I am attempting to center a div within my body. The div has a minimum height of 400px, but its size can expand based on the content it holds. When I add more content to the div, it grows accordingly, but it ends up touching the bottom of the div. I ...

What causes the accordion class to activate panels with varying names?

Why are some of my accordions triggering other accordions when they have different names? I've been working on resolving the issue where opening the second accordion in the second, third, or fourth panel closes the second accordion in the first panel ...

Duplicate the form field and add a button beneath the newly generated elements

Clicking the "Add New" button below will add new fields to the form. While everything is functioning properly, I would like the newly created fields to appear above the button instead of below it. How can this be achieved? (function($) { "use strict" ...

Receiving the [object HTMLInputElement] on the screen rather than a numerical value

I have an input box where a user can enter a number. When they click a button, I want that number to be displayed on the page. However, instead of seeing the number, I am getting the output as [object HTMLInputElement]. Below is my TypeScript code: let qu ...

What is the best way to align icons in the center alongside text or paragraphs using react?

I'm struggling with centering my icons like <GrTools size="30px"/> next to my text. It's causing some alignment issues with my styled components. Here is my JavaScript: <div id='paragraph' className="container"> ...

Steps for ensuring a div component appears on top of any other component (like h1 or p)

The outcome of the code below is displayed in this image: https://i.stack.imgur.com/CPDqC.png Is it possible to make the dropdown overlap on top of the 'HELLO's text, hiding the h1 and p tags? I have tried using z-index without success. Making ...

Use HTML to showcase an image that dynamically changes based on the outcome of a query function

Hello there, I hope my inquiry is clear enough. I apologize for reaching out as I am unsure where to begin and what exactly I should be focusing on. Currently, I have an image displayed in an HTML page like this: <div id="tag_sunrise_sunset"><p ...

Implementing CSS counter-increment with jQuery

Is there a way to use jQuery to set the CSS counter-increment attribute on ".demo:before" even though jQuery cannot access pseudo elements directly? I recall seeing a suggestion on Stack Overflow about using a data attribute and then referencing that value ...

Move the components over to the right

How can I vertically align the user and the search bar on the right side of the page? #search { float: right; margin-top: 9px; width: 250px; } .search { width: 230px; height: 30px; position: relative; line-height: 22px; } ...

Loop through the elements of a class in JavaScript and choose all except for the one that was

Imagine having 5 div elements, each with a similar onclick-function that hides the other divs when clicked. HTML: <div id="1" class="divs" onclick="hide()"></div> <div id="2" class="divs" onclick="hide()"></div> <div id="3" cla ...

- Determine if a div element is already using the Tooltipster plugin

I have been using the Tooltipster plugin from . Is there a way to check if a HTML element already has Tooltipster initialized? I ask because sometimes I need to update the text of the tooltip. To do this, I have to destroy the Tooltipster, change the tit ...

Having trouble retrieving cell values from a table using tr and td tags in C# Selenium is causing issues

I'm facing an issue where my code is unable to retrieve the cell value and instead throws an exception stating: "no such element: Unable to locate element: {"method":"xpath","selector":"html/body/div[2]/div[2]/table/tr[1]/td[0]}" Below is the HTML ma ...

Display a text over a full-screen HTML5 video

Is there a way to display text on a fullscreen video in HTML? I have tried using absolute positioning for the text and relative/fixed/none positioning for the video, but it does not work when the video is in fullscreen mode. I also attempted to call the ...