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

Ways to decrease the width of a outlined material icon

Is there a way to adjust the appearance of this icon to make it appear thinner? I have tried using font-weight and stroke-width without success. .material-icons-outlined, .material-icons.material-icons--outlined { font-family: 'Material Icons Out ...

Utilize Bootstrap to switch between 'collapse' and 'collapse in' depending on the device being used

I have a collapsible panel set to default "expand" (collapse in) and it is working well. However, I would like to make it "collapse" (shrink) for mobile and tablet devices. Is there any built-in feature in Bootstrap that can help me achieve this? <div ...

Show the text area content in an alert when using Code Mirror

When I try to alert the content of a textarea that is being used as a Code Mirror on a button click, it appears blank. However, when I remove the script for Code Mirror, the content displays properly. I am puzzled about what could be causing this issue wi ...

Issues with style not loading properly within innerHTML in Angular2

Currently, I am in the process of developing a page using Angular2/4 that includes a left navigation bar. To achieve reusability, I have separated this left menu into its own component and nested it within the main component. The objective is to utilize th ...

Assist me in temporarily altering the color of menu items in a sequential manner upon the page's loading

Currently, I'm working on a website that features a subtle dark grey menu at the top of every page. The menu is built using HTML and CSS with a list structure. To highlight the corresponding menu item based on the current page, I am utilizing the ID a ...

An issue with jQuery and LESS causing stylesheets to update only once

Struggling with updating a custom CSS href - everything works perfectly the first time, but subsequent updates do not reflect any changes on the page. Even though I can see the href updating in Chrome debugger and there are no errors being thrown by LESS, ...

Custom AngularJS directive fails to reflect changes in model after selecting a file

I recently created a custom directive called ng-file-chosen, which is supposed to capture the selected file name from an <input> element and bind it to the ng-model passed in. In the code snippet below, the result of ng-file-chosen is linked to mode ...

What is the best way to restrict the selection of specific days of the week on an HTML form date input using a combination of JavaScript, React, and HTML?

I need help customizing my Forms Date Input to only allow selection of Thursdays, Fridays, and Saturdays. I've searched for a solution but haven't been successful so far. Is there any JavaScript or HTML code that can help me achieve this? Below ...

I am having trouble getting the border-radius to display properly in my email table

I'm in the process of designing a responsive email template. For the white content area, I've applied border-radius: 5px;. While it's working fine on the bottom corners of the table, the top corners don't seem to display the border-rad ...

Identifying and categorizing flip switches with jQuery without relying on div elements

Is it possible to have two jQuery flip switches side by side, but only one visible if the screen is too narrow? I've tried assigning different classes to each switch for styling purposes, but it doesn't seem to work correctly. When I assign a cl ...

Utilizing HTML templates efficiently without the need for a view engine

For a new application, we are implementing multiple servers for handling different functions - one server for delivering HTML files, another as a proxy to handle HTTPS requests, and a Java backend with a database. The view server should be simple, with an ...

How can I use CSS to place a div at the bottom of its container?

I am trying to figure out how to use CSS to position a div at the bottom of its container, but the size of the container is not fixed. Can anyone provide some guidance on this issue? Thank you in advance for helping me solve this problem. You can check o ...

`Slide bootstrap carousel without moving other elements`

.carousel { position: relative; height: 500px; .carousel-inner .item { height: 500px; } .carousel-indicators > li { margin: 0 2px; background-color: $maincolor; border-color: $maincolor; opacity: .7; ...

Switch the background image of one div when hovering over a different div

Can anyone assist me with creating an interactive map where continents light up as you hover over them? I am using multiple images within div elements in order to achieve this effect. Specifically, I want to change the background image of one div when hove ...

Add a 'tag a' directly following 'img'

Check out this code snippet: <a href="#" class="list-group-item"> <span class="badge"><?=$st ?></span> <img class="small_profile_pic" src="<?=$pic ?>" /> aaa<a ...

Ways to eliminate a textbox from an HTML table using jQuery or JavaScript while retaining the textbox values

Currently, I am facing a task where I have a table with a column filled with textboxes. My goal is to eliminate the textboxes using jQuery/JavaScript while retaining the values within them. Here are a couple of methods I have attempted: // removes both t ...

Tips for aligning inline elements in the center of a webpage

My goal is to center the title in the middle of the page, taking into account its alignment with the search bar. However, I want it to be centered independently and not affected by the search bar's position. Is there a way to achieve this? To better ...

Position the Material UI Box element to the bottom of its parent container

Hello there, I've come across the following layout: <Box width="100%" height="100%" p={1}> <Box my={1} display="flex" justifyContent="center"> </ ...

Preventing data loss upon submitting a form (PHP)

Currently, I have an HTML file that allows users to select appointment times for specific days of the week. Once they click submit, a PHP file generates and displays a calendar with the chosen times as checkboxes. My goal is to enable users to input their ...

Angular 1.5 component using HTTP GET

Trying to utilize a 1.5 component with AngularJS has presented some challenges for me. I have a service that fetches my JSON file using $HTTP and returns a promise. In the controller of my component, I resolve the promise and assign it to a value using thi ...