Unable to extend two components to completely occupy the width of the page

I am having difficulty ensuring that two elements occupy the entire width of the page regardless of the device size. Nav1 and Nav2 are positioned alongside each other in nav-container and will contain content. This is why I need them to be separate.

I initially tried setting the width to 50% for each .nav# element, thinking it would make them fill the full width on any device. However, this approach did not yield the desired result.

.nav-container {
  position: absolute;
  display: flex;
  float: right;
}

.nav1 p {
  display: inline;
}

nav {
  background: rgb(255, 255, 255);
}

.nav1 {
  width: 50%;
  height: 300px;
}

.nav2 {
  width: 50% height: 300px;
}
<div class="nav-container">
  <nav class="nav1">
    <p class=""></p>
  </nav>
  <nav class="nav2">
    <p class="menu">
      Menu
    </p>
  </nav>
</div>

Attempting to replicate a navigation bar similar to the one found on this website

Answer №1

To ensure equal spacing for the nav elements, you must set a 100% width on the container and apply flex-grow: 1 to each nav element within it.

body {
  margin: 0;
}

.nav-container {
  position: absolute;
  width: 100%;
  display: flex;
  
}

.menu {
  margin: 0;
}

nav {
  background: #f8f8f8;
  flex-grow: 1;
  height: 300px;
}

.nav2 {
  background: #eee;
}
<div class="nav-container">
  <nav class="nav1">
     <p class="menu">Menu 1</p>
   </nav>
   <nav class="nav2">
     <p class="menu">
       Menu 2
     </p>
  </nav>
</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

Mysterious HTML/CSS element causing page to stretch beyond limits

I am currently updating a website to make it responsive. Check it out here: When the viewport is below 980px in width, a horizontal scroll bar appears and the html/body/container remains at 980px. I've attempted to apply an inline width of 200px to ...

What is the method for showcasing login errors and prompting users to fill in all fields simultaneously on a page with PHP?

As I develop a PHP login page, I am implementing a system where users need to enter a username and password to access the platform. One query that arises is: How can I dynamically display an 'Invalid username or password' error message on the s ...

Having trouble with the Python for loop functioning incorrectly?

I'm facing issues with my for loop in my Django application. I'm attempting to display other users who have logged in under "Users who could be friends," but nothing is appearing. I believe my app will function correctly once I resolve this issue ...

Steps for saving the ajax response in a jQuery variable and displaying it in an HTML textbox

Here is a link to my code snippet on GitHub: https://gist.github.com/anuragk098/3e11673136325b5e5b1859bde11f2117 And here is a link to my webpage: The first text box in my project retrieves all the cities using a jQuery function: var months = [<?=$cit ...

Switch classes according to scrolling levels

My webpage consists of multiple sections, each occupying the full height and width of the screen and containing an image. As visitors scroll through the page, the image in the current section comes into view while the image in the previous section disappe ...

Overflow issues arise when incorporating an embedded iframe (YouTube) into a Bootstrap website, hindering the visibility of surrounding

So, I have a youtube video embedded on my page and when I resize the page, the video frame doesn't adjust responsively like the rest of the content. It overflows and blocks other site content. I'm looking to make it responsive if possible or at ...

What is the best way to retrieve a PDF file from another website and showcase it on our own site without any redirection?

Is there a way to display a pdf from another website without having to redirect to that site? I'm looking for a solution that involves using the URL directly. ...

Using URL parameters in Node.js applications

I am encountering an issue with my nodejs setup, and I am hoping someone can assist me. My challenge lies in trying to pass a parameter with a specific value to a page.html file, like this: page.html?s=1 However, I am encountering a problem where the pa ...

Is there a way to ensure that a CSS flex child occupies its own row exclusively?

Within this flex container that displays children in a row with wrapping enabled, most components look good side by side. However, there is one component - an input slider that I want to place on its own row, taking up the entire width of the container. I ...

Utilizing CSS with jQuery

When developing a web application with minimal intensity where overhead is not an issue, is it feasible to exclusively implement CSS in Javascript/jQuery and eliminate external CSS files entirely? $('<div/>').attr({'id':'spe ...

How can I split my button into two distinct colors?

Here is a button example with CSS styling: CSS .Btns { width:200px; height:75px; background-color:lightblue; color:black; font-weight:bold; } HTML: <button id="btnProduct" type="button" clas ...

Unsure why the React button is disappearing specifically on Safari iOS. Any thoughts on how CSS

Hey there! I created a small hamburger button for my website, but for some reason, it doesn't show up on Safari iOS. Interestingly, it works perfectly fine on Windows Chrome, Windows Firefox, and my Android device. I've been trying to troubleshoo ...

Is there a way to invoke an AngularJS function using JavaScript without specifying the ID parameter?

I am interested in invoking an AngularJS function without relying on the use of an id parameter. My current method for calling the AngularJS function is shown below: JS File: angular.element(document.getElementById('service_search')).scope().s ...

Due to the feature in VISUAL STUDIO CODE that presents folders and subfolders at the same level

While working on my Angular project, I encountered an issue with creating a subfolder within a folder. Despite trying the same process in Windows Explorer, I faced the same problem of them appearing on the same level. What could be causing this discrepan ...

Chrome has a tendency to cut off page contents in print preview, unlike other browsers that do not have this issue

My current version of Chrome browser (54.0.2840.59) is exhibiting a strange behavior when attempting to print preview an HTML page I have developed. The print preview truncates the page content, displaying less than what should be shown. The content is not ...

What is the best way to dynamically link an Angular Material table with information pulled from the backend server

I am attempting to connect a mat-table with data from the backend API following this Angular Material Table Dynamic Columns without model. Below is the relevant content from the .ts file: technologyList = []; listTechnology = function () { ...

The process of setting up React in the terminal becomes tricky when the VS code editor is directing to a non-existent path

Issue with VS Code editor not recognizing existing path Recently attempted to install React using the npx command in the terminal, following steps from various tutorials on YouTube. Despite trying all suggested methods, the installation didn't succee ...

Is it possible for URLs in CSS Custom Properties to be relative to the CSS file where they are defined?

I have a CSS library with resources like images and fonts that can be accessed from anywhere via CDN. I am trying to create URLs for these resources as Custom CSS Properties, relative to the library. <!-- https://my.server/index.html --> <link rel ...

Fonts appear altered on a Windows computer

Working on my new website watr.io, I've noticed that the font appears differently on Windows versus Mac. The one displayed on Mac is the desired outcome, but I can't seem to figure out what's causing the discrepancy. I've been troublesh ...

The oninput event does not trigger if the text field value is transferred from a different form

Event Handling: The oninput event functions perfectly when I input a mobile number into the small text field in my form. It displays a message indicating that the number already exists and disables the submit button accordingly. However, it fails to valida ...