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

Why isn't margin working with position: fixed?

I need help finding a solution for incorporating margin in a box within my App class. The issue is that the position fixed property doesn't seem to work as intended. <div className="App"> <div className="box"> ...

Tips for including a footer element in React:How can a footer division be

I need help with implementing a footer in my React web app. Currently, the body section in index.html looks like this: <body> <div id="root"></div> <script src="index.js"></script> </body> Inside index.js, the rend ...

What is the best way to center a parent container vertically?

I currently have a main grid with grid items that are also containers, set as inline-sized containers to allow for different internal layouts based on their width. How can I horizontally align the main grid in the center once it exceeds a certain width? A ...

How can I remove the bouncing effect of the top bar in Chrome when scrolling in Three

There is a frustrating problem I am encountering on my website with the joystick control. Whenever I try to move my joystick down, Chrome triggers either the refresh dropdown or the top bar bounces and goes in and out of fullscreen mode. ...

Trouble with CSS styling arising when launching the MVC application on IIS

Currently working on a website in ASP.Net MVC 5. I am trying to test it on my local IIS (version 8), but encountering an issue where the CSS styling is not being applied. In my _layout.cshtml file, I opted for direct link tags instead of using bundles. &l ...

Error: The document object is not defined when attempting to access it within a

<script type="module" src="/scripts/navbar.js"></script> <script> async function fetchContent(e) { e && e.preventDefault(); const response = await fetch('https: ...

Scala Play templating with vararg HtmlContent allows for dynamic generation of

I have a standard template in play 2.6, where I need to pass in a variable number of HtmlContents. The template is defined like this (including the implicit parameter): @(foo: String)(content: Html*)(implicit bar: Bar) When working with the template, I c ...

Retrieving HTML Source Code in Android Studio

I am having trouble with testing this function even though the permissions are correctly set in the manifest file. Can anyone help me figure out what I'm doing wrong? public void fetchHTMLContent() throws Exception { URL url = new URL("http:/ ...

Receiving an UNDEFINED INDEX error when trying to send data from an HTML form to a

I've created an HTML form that is styled using CSS for weekly work data entry. <form action="wwinsert.php" method="post"> <fieldset> <legend>Weekly Work</legend> <p><label class="lab1" for="StoreNumber">Store:</ ...

Interact with Datatable by clicking on the table cell or any links within the cell

When I am working with the datatable, I want to be able to determine whether a click inside the table was made on a link or a cell. <td> Here is some text - <a href="mylink.html">mylink</a> </td> Here is how I initialize my da ...

What is the method for incorporating text below font icons?

Having a bit of trouble here with my code snippet featuring 'font awesome' icons in circles. I'm looking to add text beneath each icon, but the alignment within the circle is proving to be a challenge. Check out the code in this link to see ...

Create a personalized form with HTML and JQuery

Currently, the data is displayed on a page in the following format: AB123 | LHRLAX | J9 I7 C9 D9 A6 | -0655 0910 -------------------------------------------------------- CF1153 | LHRLAX | I7 J7 Z9 T9 V7 | -0910 1305 ---------------- ...

"Troubleshooting problems with jQuery accordion collapse and styling using CSS

I'm currently dealing with an issue regarding my accordion design. I have customized the stylesheet using themeroller, but when I collapse one of the sections, the header changes to black instead of reverting back to its original red color. I've ...

How to turn off the default print media query in Zurb Foundation 5 without relying on SASS

I've been having trouble with printing website pages that are built using Zurb Foundation 5. Whenever I try to print or preview the page, it defaults to the `medium` grid size and looks different from how it appears on the desktop version. I've ...

How can we prevent the navigation from fading out when scrolling back up, as JQuery control the opacity of the Nav to fade in?

Looking for some guidance on jQuery assistance. I currently have a fixed navigation bar at the top of my webpage with an initial opacity set to 0 upon page load. As the user scrolls down, I want the navigation bar to fade in using the following code: fun ...

CSS class for modifying color based on certain conditions

Suppose I have this CSS code: label { color: #AAAAAA; } Can I modify it to include a condition that changes the color to red if the label has the "error" class? I am aware that I can dynamically add the class to the label in HTML, but I am curious if ...

What are alternative ways to divide CSS without relying on CSS-in-JS and CSS modules?

Recently, I transitioned to next.js and I'm eager to develop an application with CSS styles without resorting to css-in-js or inline styling. In my exploration, I've come across two potential options: using CSS modules or importing global styles ...

issues with the visual studio website code (Struggling to establish a connection between the site and a database)

Currently, I am in the process of developing a website using Visual Studio and attempting to connect it to a Microsoft SQL Server 2014 database. My learning journey has led me to a tutorial video on YouTube focusing on creating a coffee-themed website alon ...

The z-index is preventing me from selecting a certain area

I'm currently facing a challenge with a Bootsrap card that seems to be unclickable and I am unable to type input into the form inside of it. The root cause appears to be related to the z-index that I used to position the card "behind" the header and f ...

What could be causing the server to return an empty response to an ajax HTTP POST request?

Attempting to make a POST request using ajax in the following manner: $.ajax({ type: "POST", url: 'http://192.168.1.140/', data: "{}", dataType: "json", ...