Ensuring the same height for the navigation bar and logo with aligned vertical text

I'm in the process of recreating a simple navigation menu and I've reached the section where I am encountering an issue with the list items. The orange li element is not filling up 100% of the width, and I also need the links to align in the middle instead of being centered. Here's an example of what I am trying to achieve:

Take a look at this example page for reference. You can also see a screenshot below:

https://i.stack.imgur.com/DKPhx.jpg

This is my current progress so far:

.page-header{
display: inline-block;
    margin: 0;
    position: absolute;
    vertical-align: middle;
    width: 100%;
    z-index: 110;
background-color: aqua;
}
.header-standard {
height: 86px;
}
.branding{
display: block;
float: left;
}
.branding img {
height: 60px;
margin: 15px 25px;
}
.standard-nav{
height: 100%;
display: block;
float: right;
}
.special-link {
display: inline;
    background-color: #ff5252;
    width: 200px;
height: auto;
    text-align: center;
margin: 0;
}
.standard-nav > ul > li {    
bottom: 0;
}
.standard-nav ul li {
display: inline-block;
padding: 0;
margin: 0;
}
<header class="page-header">
  <div class="header-standard">
  <div class="branding">
  <img src="http://via.placeholder.com/350x150">
  </div>
  <nav class="standard-nav">
  <ul>
  <li>Link 1</li>
  <li>Link 2</li>
  <li>Link 3</li>
  <li>Link 4</li>
  <li class="special-link">Special Link</li>
  </ul>
  </nav>
  
  </div>
</header>​

Answer №1

If you're looking for a different way to structure this design, consider utilizing flexbox instead of using float properties.

.page-header {
  margin: 0;
  position: absolute;
  width: 100%;
  z-index: 110;
  background-color: aqua;
}

.header-standard {
  height: 86px;
  display: flex;
  justify-content: space-between;
}


.branding img {
  height: 60px;
  margin: 15px 25px;
}

.standard-nav {
  height: 100%;
  display: flex;
  align-items: center;
}

.standard-nav ul {
  display: flex;
  align-items: center;
  height: 100%;
  margin: 0;
  padding: 0;
}

.special-link {
  background-color: #ff5252;
  width: 200px;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}


.standard-nav ul li {
  list-style: none;
  padding-right: .5em;
}
<header class="page-header">
  <div class="header-standard">
    <div class="branding">
      <img src="http://via.placeholder.com/350x150">
    </div>
    <nav class="standard-nav">
      <ul>
        <li>Link 1</li>
        <li>Link 2</li>
        <li>Link 3</li>
        <li>Link 4</li>
        <li class="special-link">Special Link</li>
      </ul>
    </nav>

  </div>
</header>​

Answer №2

Consider using the flex property in your CSS for a more flexible layout. Make sure to include prefixes for different browsers.

HTML

<header class="page-header header-standard">

    <div class="branding">
      <img src="http://via.placeholder.com/350x150">
    </div>

    <nav class="standard-nav">
      <ul>
        <li>Link 1</li>
        <li>Link 2</li>
        <li>Link 3</li>
        <li>Link 4</li>
        <li class="special-link">Special Link</li>
      </ul>
    </nav>

</header>

CSS

header,
nav,
nav ul {
  display: flex;
  align-items: stretch;
}

nav {
  flex: 1;
  justify-content: flex-end;
}

nav li {
  display: flex;
  align-items: center;
  height: 100%;
}

Check out this JsFiddle demo: https://jsfiddle.net/0xz5of71/1/

Answer №3

To ensure proper display, make sure to include the following CSS properties:

height: 100%; margin: 0; line-height: 86px
for the ul element. Additionally, adjust the height of the left element as it currently exceeds the height of its parent container.

.page-header{
display: inline-block;
    margin: 0;
    position: absolute;
    vertical-align: middle;
    width: 100%;
    z-index: 110;
background-color: aqua;
}
.header-standard {
height: 86px;
}
.branding{
display: block;
float: left;
}
.branding img {
height: 60px;
margin: 15px 25px;
}
.standard-nav{
height: 100%;
display: block;
float: right;
}
.special-link {
display: inline;
    background-color: #ff5252;
    width: 200px;
height: auto;
    text-align: center;
margin: 0;
}
.standard-nav > ul > li {    
bottom: 0;
}
.standard-nav > ul {
  margin: 0;
  line-height: 86px;
  height: 100%:
}
.standard-nav ul li {
display: inline-block;
padding: 0;
margin: 0;
}
<header class="page-header">
  <div class="header-standard">
  <div class="branding">
  <img src="http://via.placeholder.com/350x150">
  </div>
  <nav class="standard-nav">
  <ul>
  <li>Link 1</li>
  <li>Link 2</li>
  <li>Link 3</li>
  <li>Link 4</li>
  <li class="special-link">Special Link</li>
  </ul>
  </nav>
  
  </div>
</header>​

Answer №4

To create a floating logo and align the navigation without using float is another option to consider. Additionally, using display:table/flex/grid can also be helpful in avoiding the use of floats.

.page-header {
  position: absolute;
  width: 100%;
  z-index: 1;
  background-color: aqua;
}

.header-standard {}

body{margin:0;}

.branding {
  float: left;
}

.branding img {
  height: 60px;
  margin-left: 25px;
}

.standard-nav {
  text-align: right;
}

.special-link {
  background-color: #ff5252;
}

.standard-nav ul li {
  display: inline-block;
  padding: 0;
  margin: 0;
}

.standard-nav ul li a {
  display: inline-block;
  line-height: 60px;
  padding: 0 0.5em
}
<header class="page-header">
  <div class="header-standard">
    <div class="branding">
      <img src="http://via.placeholder.com/350x150">
    </div>
    <nav class="standard-nav">
      <ul>
        <li><a href="#">Link 1</a></li>
        <li><a href="#">Link 2</a></li>
        <li><a href="#">Link 3</a></li>
        <li><a href="#">Link 4</a></li>
        <li><a class="special-link" href="#">Special Link</a></li>
      </ul>
    </nav>

  </div>
</header>​

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

How can I create a design that adjusts to show 5 columns on larger screens and 2 columns on smaller screens using Bootstrap 4?

I am working on a responsive column layout for an online store. I need to display 5 columns on large screens and 2 columns on mobile screens using Bootstrap4. However, on screens below 576px width, only one column is being rendered instead of two. How ca ...

Adjust: Return scale to default

By applying transform: rotate(-2deg); to a section, I have created an effect where the section rotates slightly. Additionally, when the user hovers over the same section, it increases in size due to transform: scale(1.1);. However, on one specific page of ...

Update the HTML weather icon with data from JSON

I have a collection of weather icons stored on my computer. How can I customize the default weather icons with my own set of icons? In the JSON file, there is a variable like this: "icon":"partlycloudy" <html> <head> <script src="http://c ...

Toggle Divs with jQuery (Rotate images depending on link)

I am currently using the following code to toggle the visibility of div elements. http://jsfiddle.net/XwN2L/3120/ In addition, I would like to have a unique image sprite for each link when it is selected. I attempted to assign individual IDs to each link ...

Deploying CSS/JS files in Magento 2 is a crucial

Hello, I recently set up magento2 with the sample data included. After attempting to deploy static css/JS using the command php bin/magento setup:static-content:deploy, I didn't receive any errors but the issue persists. Additionally, I am unable to l ...

Is it possible to combine the index page with the login page for a web project, or is it recommended to create a separate login page?

Would it be a violation of any rules if the index page of my web project is used as the login page for users? Do I have to redirect them to a different page? Is this considered best practice? ...

Getting the first nested object within an object in Angular 8: A comprehensive guide

Looking to extract the first object from a JSON data set? In this case, we want to retrieve {"test": {"id":1, "name":"cat"}} from the following object: { "3": {"test": {"id":1, "name":"cat"}}, "4": {"test": {"id":2, "name":"dog"}}}. Keep in mind that the ...

Is it possible to change label text using CSS without referencing the element by its ID?

Here is a simple code snippet: <div class="delem"><label class="required" for="last_name">Full Name :</label><input id="fullname" type="text" name="fullname" value="" class="fullsize" required=""></div> <div class="delem" ...

Error message occurs when creating a pie chart with invalid values for the <path> element in Plottable/D3.js

For those who need the code snippets, you can find them for download here: index.html <!doctype html> <html> <head> <meta charset="UTF-8"> <!-- CSS placement for legend and fold change --> </head> <body ...

Guide to dynamically add tr element using CSS to a table

While using the $.each function in jQuery, I am retrieving data and adding it to a table in the following manner: $.each(segment, function (index, innerSegment) { var tr; tr = $('<tr/>'); tr.append("<td>" + segment[i].Airline.Air ...

Tips for deactivating all JavaScript events on a webpage that has been loaded within an iframe

My website is equipped with various JS click/mouseover/mouseout/scroll events and incorporates several JS libraries to operate features such as carousels, bootstrap modal pop-ups, and more. I am looking to halt all events on a specific element. Although I ...

CSS-only countdown animation

I've been experimenting with a pure HTML/CSS countdown animation, but I'm facing challenges in getting it to run smoothly. Currently, I'm focusing on minutes and seconds only. One issue I encountered is that the digit representing tens of mi ...

Having trouble locating the search bar element on Walmart's website?

I'm currently working on a bot that needs Selenium to interact with the search bar on Walmart's website, where it will input the name of a specific product and perform a search. However, I've encountered an issue where no matter what method ...

Transfer file content by dragging and dropping it onto a TextArea when an anchor tag is dropped

Within my application, there are 2 textareas with corresponding code implementing "dragover" and "drop" listeners for each one: // for dragover handleDragOver : function (evt) { var self = this; evt.preventDefault(); console.log ( ...

Loop through a list of form names using ng-repeat and send each form name to a JavaScript function when clicked

I have multiple forms within an ng-repeat loop, each with a different name. I need to pass the form data when a button inside the form is clicked. However, when I try to call it like this: checkSaveDisable(updateProductSale_{{productIndex}}) it thro ...

Turn off transparency for the child element if the parent element has transparency

In my design setup, there is a container with an opacity set at 0.8. This allows the background image to subtly shine through the content area. The challenge arises when I place a client photo inside this container. The issue is that the photo's opac ...

Distinguishing Features of HTML, Canvas, and WebGL

Is there a way to draw images in WebGL with the same quality as HTML, even when downscaled? I've noticed that scaling down images in WebGL results in poor quality compared to HTML. After reading about 'Handling High DPI (Retina) displays in WebGL ...

Within a div element, there are links that I would like to hover over to emphasize the text

Hey there, I'm looking to make the text change color when you hover over the entire div. Currently, only the background changes color, but I want the text to as well. Thank you for your assistance! .shadow-box .service-box {text-align:center;borde ...

Verifying if a number is present in a textbox when inserting text (without using setTimeout)

I have an input field similar to the one shown below: <input type ="number" id="numberTxt" placeholder="Number Only"/> To ensure that the value entered is a number, I am using the following function with the keypress event: <script> ...

The internal style and script specified within the <head> section are not being rendered

Within my Joomla website using the T3 template, I inserted the following "Custom Code" just before the closing </head> tag: <style type="text/stylesheet"> div.t3-sidebar.t3-sidebar-right{ background: #F8F8F8 none repeat scroll 0% 0%; ...