Containers do not line up properly with each other. Adjusting the width leads to unexpected consequences

As someone who is new to HTML and CSS, I am facing a challenge with aligning the items within a navigation bar on my website. The list serves as a navigation bar and is contained inside the "inner header" div. While I was able to align the entire "nav" container (in teal) to the right edge of the "inner header" container, I am struggling to achieve the same alignment for the individual items within the nav (in red).

The appearance of the containers can be seen here.

I have attempted various approaches, including setting the width to 100% which caused the text to separate into multiple rows, possibly due to the display type. Another attempt involved adding a width of 98px, which brought me closer to the desired outcome but did not perfectly align with the teal background.

You can see how close I got to the desired outcome here.

Your advice would be greatly appreciated!

.inner_header {
  width: 1000px;
  height: 100%;
  display: block;
  margin: 0 auto;
  background-color: #8ecae6;
  display: flex;
  justify-content: center;
  align-items: center;
}

.nav {
  float: right;
  height: 100%;
  width: 70%;
  background-color: teal;
  text-align: right;
}

.nav a {
  height: 100%;
  display: table;
  table-layout: fixed;
  float: left;
  padding: 0px 20px;
  background-color: red;
  overflow: hidden;
  width: 98px;
}

.nav a:last-child {
  padding-right: 0px;
}

.nav a li {
  display: table-cell;
  vertical-align: middle;
  height: 100%;
  font-family: 'Montserrat';
  font-weight: 300;
}
<div class="header">
  <div class="inner_header">
  
    <div class="logo_container">
      <img src=".png">
      <img src=".jpeg">
    </div>

    <p>Text <br> Text</p>

    <ul class="nav">
      <a>
        <li>Home</li>
      </a>
      <a>
        <li>Data</li>
      </a>
      <a>
        <li>Tool</li>
      </a>
    </ul>
    
  </div>
</div>

Answer №1

It seems like there might have been some confusion regarding your request, but I took a shot at reproducing the design based on your description and screenshot.

.inner_header {
  width: 1000px;
  height: 100%;
  display: block;
  margin: 0 auto;
  background-color: #8ecae6;
  display: flex;
  justify-content: center;
  align-items: center;
}

.nav {
  float: right;
  height: 100%;
  width: 70%;
  display: table;
  background-color: teal;
  text-align: right;
  padding:0;
}

.nav a {
  height: 100%;
  display: table-cell;
  padding: 0px 20px;
  background-color: red;
  overflow: hidden;
  width: auto;
}

.nav a:last-child {
  padding-right: 0px;
}

.nav a li {
  display: table-cell;
  vertical-align: middle;
  height: 100%;
  font-family: 'Montserrat';
  font-weight: 300;
}
<div class="header">
  <div class="inner_header">
  
    <div class="logo_container">
      <img src=".png">
      <img src=".jpeg">
    </div>

    <p>Text <br> Text</p>

    <ul class="nav">
      <a>
        <li>Home</li>
      </a>
      <a>
        <li>Data</li>
      </a>
      <a>
        <li>Tool</li>
      </a>
    </ul>
    
  </div>
</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

Stream music from SoundCloud by simply clicking a button on an external source, no need

My post contains an embedded SoundCloud player using the following code: <iframe class="soundcloud_iframe" width="100%" height="166" scrolling="no" frameborder="no" src="'.esc_url('https://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcl ...

Several buttons, each requiring to show distinct text

Currently, I am attempting to enhance an existing project that was graciously created for me. I must admit, I am quite new to this, so please be patient with me! In my project, there are 9 buttons, each triggering the display of a different image upon bei ...

Looking to create a custom loader that adapts to different screen sizes

Can anyone help me make the text in my centered div responsive on my website loader? I'm new to coding and struggling to figure it out. Any assistance would be greatly appreciated! Make sure to view the full page snippet so you can see the text prope ...

Challenges with exporting dynamically generated divs using jspdf in an Angular 2 project

I have been utilizing the jspdf library to print div elements in my current project. But I recently discovered an issue where dynamic content within a div is not being printed correctly. Specifically, when incorporating simple Angular if statements, jspdf ...

Is it possible to conduct HTML-based Selenium tests without an internet connection?

As a newcomer to Selenium, I am currently using the Selenium IDE which has led me to create table structures like the one below: <table cellspacing="1" cellpadding="1" border="1" name="SELENIUM-TEST"> <thead> <tr class="title"> ...

Issues with jQuery functionality occurring when trying to display or hide div contents on dynamically loaded AJAX content

I have encountered an issue while working on a project that involves showing or hiding a div based on the selection of a drop down value. The show/hide functionality works perfectly when implemented on the same page, but it fails when I try to do the same ...

A guide on configuring Flexbox to consistently display three columns

For the website I'm working on, I've utilized Flexbox to properly align the items. Within the div .main, I have organized the content in separate divs. These are the CSS properties that I've applied: .main{ margin: 0 auto; /*max-height: ...

URL to section of website without the navigation bar portion

I am trying to solve a problem with creating a link that will take me to a specific part of the page while taking into account the height of the navbar. The issue is that since the navbar is fixed to the top with a solid color, it ends up covering part of ...

Does applying a style to an element that already has the same value result in a decrease in performance? Alternatively, do all browsers simply overlook it?

Assuming I have an element with the style top: 5px, and then I execute element.style.top = "5px";, will the browser readjust its position and trigger a layout again? Or does it recognize that there is no need to change anything? (Is this behavior specified ...

Converting JSON data into a JavaScript array and retrieving the array through an AJAX request from PHP

Currently, I am working on a project where I have created a function named AjaxRequest to manage all my AJAX requests. While making the requests is not an issue, receiving and placing the data back onto the page has proven to be quite challenging. Within ...

Create styles for each component based on their specific props when designing a customized Material-UI theme

I am having trouble styling the notchedOutline of a disabled <OutlinedInput /> in my custom MUI theme. My goal is to make the border color lighter than the default color when the input is disabled. Here is what I have attempted so far: const theme = ...

Display content exclusively within a modal specifically designed for mobile devices

I want to implement a feature where a button triggers a modal displaying content, but only on mobile devices. On desktop, the same content should be displayed in a div without the need for a button or modal. For instance: <div class="container&quo ...

p5.js experiencing issue: Uncaught TypeError - Unable to access property 'transpose3x3' due to null value

I have a simple website built with Flask where I am running several p5.js sketch animations, and everything is working smoothly. However, when I try to add a new sketch that utilizes WEBGL, I encounter the following error: Uncaught TypeError: Cannot read p ...

Struggling with aligning two divs side by side on an HTML page

Recently, I've been experimenting with Electron and attempting to create 2 divs side by side. Despite trying various alignment options found here, nothing seems to be working for me. Here's the code I have so far: Code body, html { hei ...

Utilize custom fonts from your local directory within a Vite Vue3 project

Inside my main.scss file, I am loading local fonts from the assets/styles/fonts folder: @font-face { font-family: 'Opensans-Bold'; font-style: normal; src: local('Opensans-Bold'), url(./fonts/OpenSans-Bold.ttf) format('truety ...

The filter is displaying incorrect categories

I am facing an issue with creating a work filter based on the last column which represents categories. When I select an option from the dropdown, I want to display only that specific category and hide the others. Currently, when I try clicking on an option ...

Unique mechanism for tracking clicks in ASP and C#

Is there a preferred method for showing a click counter on an HTML page when working with a .aspx file that connects to a .cs file pulling data from a SQL server, without relying on an external text file for tracking purposes? I'm trying to avoid usin ...

Finding the image source of a clicked image

Is it possible to retrieve the image src after clicking on another image? $(document).ready(function() { $('img.getimage').click(function() { alert($(this).attr('src')); }); }); .sinistra { width: 150px; } .getimage { wi ...

Storing Form Data in MySQL, upon clicking the submit button the user is redirected to a PHP page and the information is not

Currently, I am facing an issue with injecting data into my SQL table. Whenever I input information into the forms and click on the submit button, the page redirects me to my PHP file without actually injecting any data. The tables remain empty. Below is ...

Centering a Font Awesome icon within its parent element

Below is the code I am using: <div style="width:60px; height:60px; background-color: lightgrey;"> <a class="" href="javascript:void(0)" style="color: black; width: inherit; height: inherit;"> <i class="fa fa-lg fa-play" aria-hidden="t ...