Struggling to achieve the desired layout in the navigation code using CSS Grid. I am aiming for it to occupy the entire width of the screen

I'm facing an issue with customizing my HTML layout using grids. I want my nav element to occupy the entire available width.

Below is my current code:

  header {
  text-align: center;
  grid-area: header;
  border: solid;
}

#nav1 {
  text-decoration: none;
  border: solid;
  background-color: green;
  grid-area: MH;
  width: 1fr;
  text-align: center;
}

#nav2 {
  text-decoration: none;
  border: solid;
  background-color: red;
  grid-area: MC;
  width: 1frs;
  text-align: center;
}

#nav3 {
  text-decoration: none;
  border: solid;
  background-color: yellow;
  grid-area: start;
  width: 1fr;
  text-align: center;
}

footer {
  grid-area: footer;
  border: solid;
  background-color: orange;
  margin-top: 0px;
  height: 100px;
}

main {
  text-decoration: none;
  border: solid;
  background-color: gray;
  grid-area: main;
  height: 500px;
  color: #ff00eb;
  border-color: black;
}

aside {
  width: 0.5fr;
  border: solid;
  background-color: purple;
  grid-area: aside;
}

#big-container,
nav {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: auto;
  grid-template-areas: 'header header header' 'MH MC start' 'main main aside' 'footer footer footer ';
  grid-gap: 0px;
  padding: 0px;
<!-- This is my header-->
<header>
  <h1></h1>
</header>

<div id="big-container">

  <nav>
    <a href="My-house-(6)/index.html" id="nav1"> my house</a>
    <a href="calendar/calendar.html" id="nav2"> my calendar</a>
    <a href="index2.0.html" id="nav3">main</a>
  </nav>

  <main>

    Main content here
  </main>


  <aside>
    Aside section
  </aside>


  <footer>
    Footer content
  </footer>
</div>

Answer №1

To enhance the navigation bar, I recommend setting the display flex property like so:

 header {
  text-align: center;
  grid-area: header;
  border: solid;
}

footer {
  grid-area: footer;
  border: solid;
  background-color: orange;
  margin-top: 0px;
  height: 100px;
}

main {
  text-decoration: none;
  border: solid;
  background-color: gray;
  grid-area: main;
  height: 500px;
  color: #ff00eb;
  border-color: black;
}

aside {
  width: 0.5fr;
  border: solid;
  background-color: purple;
  grid-area: aside;
}

#big-container {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: auto;
  grid-template-areas: 'header header header' 'MH MC start' 'main main aside' 'footer footer footer ';
  grid-gap: 0px;
  padding: 0px;
}

nav {  
  width: 100%;
  background: lightblue;
  display: flex;
  justify-content: center;
}
nav > a {
  display: block;
  text-decoration: none;
  border: solid;  
  text-align: center;      
  width:100%;
}

nav > a:nth-child(1) {  
  background-color: green;
}
nav > a:nth-child(2) {  
  background-color: green;
}
nav > a:nth-child(3) {  
  background-color: green;
}
<!-- This is my header-->
<header>
  <h1></h1>
</header>
<nav>
  <a href="My-house-(6)/index.html" id="nav1"> my house</a>
  <a href="calendar/calendar.html" id="nav2"> my calendar</a>
  <a href="index2.0.html" id="nav3">main</a>
</nav>

<div id="big-container">
  <main>

    main
  </main>


  <aside>
    aside
  </aside>


  <footer>
    footer
  </footer>
</div>

Answer №2

To simplify the code for your desired layout, you can use the following snippet:

body {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-areas: "header header header" "nav nav nav" "main main aside" "footer footer footer ";
}

header {
  text-align: center;
  grid-area: header;
  border: solid;
}
nav {
  grid-area: nav;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
}
#nav1 {
  text-decoration: none;
  border: solid;
  background-color: green;
  text-align: center;
}

#nav2 {
  text-decoration: none;
  border: solid;
  background-color: red;
  text-align: center;
}

#nav3 {
  text-decoration: none;
  border: solid;
  background-color: yellow;
  text-align: center;
}

main {
  text-decoration: none;
  border: solid;
  background-color: gray;
  grid-area: main;
  height: 500px;
  color: #ff00eb;
  border-color: black;
}

aside {
  width: 0.5fr;
  border: solid;
  background-color: purple;
  grid-area: aside;
}

footer {
  grid-area: footer;
  border: solid;
  background-color: orange;
  margin-top: 0px;
  height: 100px;
}
<header>
  header
</header>

<nav>
  <a href="Mitt-hus-(6)/index.html" id="nav1"> mitt hus</a>
  <a href="kalender/calender.html" id="nav2"> min calender</a>
  <a href="index2.0.html" id="nav3">main</a>
</nav>

<main>
  main
</main>

<aside>
  aside
</aside>

<footer>
  footer
</footer>

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

What could be the reason for 'selected' not appearing?

Can anyone explain why the 'selected' attribute is not appearing in my <option value=""> element? <p> <select name="images" class="dropdown"> <option value="empty" <?php if(isset($_GET[ ...

The HTML unit is unable to locate the form for unknown reasons. My suspicion is that it could be due to the presence of Angular

Struggling with using HTMLunit to login and upload a file. Successfully logged in but unable to locate the form, despite it being present on the HTML page. Here is the JAVA CODE snippet: public static void main(String[] args) { WebClient webClient = ...

Issue with modal box not displaying properly when hidden div is within a for loop

In my project, I have a MySQL select statement that retrieves all the results to be displayed in an unordered list (<ul>) using a for loop. This functionality works perfectly. However, I wanted to add a "click more" link at the bottom of each result ...

Steps for declaring CSS values with fallbacks in case of unsupported values

I'm looking to utilize the overflow: overlay property in Chrome, and overflow: scroll in Firefox. Simply declaring the overlay value causes Firefox not to scroll at all, even though I know it's not standard. My question is: what's the optim ...

Responsive Input Navigation Bar CSS

How can I create a top bar that resembles the design of Google Play? https://i.sstatic.net/tdLVz.png I am struggling to make the input box flexible and fit the window size... The minimum width of Div.search is set to 250px but it's not working ...

Ways to streamline a form containing several duplicate rows and make it more user-friendly

Looking for some advice on implementing a "working hours" module. Just need something simple like: Monday: 10:00 - 18:00 ... Saturday: 11:00-16:00 with some additional info. I'm currently attempting to... <form id="working_hours"> <s ...

Animate a jumping figure using jQuery

Is it possible to create an animation of a person jumping from the bottom of the screen to the top, with the scroll bar following them? I have my doubts but would love to know if it can be done. If you want to see what I mean, check out this PDF: http:// ...

What is causing the TouchSwipe jQuery plugin not to function in my code?

I have integrated the TouchSwipe jQuery plugin into my code to detect mouse movement and display the number of pixels moved when swiping left or right. To download the TouchSwipe jQuery plugin, I visited this link: TouchSwipe and then proceeded to use it ...

PHP Multiple Uploads is a feature that allows users to

I'm currently attempting to utilize the dropzone JS plugin in combination with PHP for the purpose of uploading multiple files and then displaying each file's URL. Here is my progress so far: $upload_dir = 'files'; for($i=0; $i&l ...

What could be the reason for bootstrap failing to recognize and apply my variables?

Whenever I set the text color to green using this code: @textColor: green; It works perfectly and changes the text color, but when I try to modify grid column width and gutter width with this code: @gridColumnWidth: 10px; @gridGutterWidth: 0px; @flu ...

If the option of "none" is chosen, I would like to deactivate all checkbox selections

Struggling with disabling all checkboxes in a PHP form when the NONE option is selected. <h5>HEALTH OF STUDENT</h5> <p>Any physical, emotional, or other difficulties to be aware of?</p> <table> <td>Hearing ...

Having trouble getting datatables.net to function properly with JavaScript

I've been experimenting with datatables from http://datatables.net/ Attempting to make it work using javascript, but I'm facing issues. Even when following the example provided on the website, it still shows a blank page. Does anyone have any su ...

What is the best way to automatically close a modal box after submitting a form?

Currently, I am utilizing the CSS modal box developed by Paul R. Hayes. More information about this can be found here - Within the modal box, I have integrated a form. This form is aimed at an iframe that remains concealed on the same page. My objective i ...

The elegant scroll-bar (whether directive-based or not) seems to be having trouble functioning within the ng-view

I am looking to add a stylish scroll bar to a paragraph that is located within the ng-view. My module code appears as follows: var myweb = angular.module('myweb' , ['ngRoute', 'perfect_scrollbar']); myweb.config(function($ro ...

Error message encountered while attempting to upload a file with Express-fileupload in a Node.js environment: "Unable to locate specified

I am currently facing an issue while attempting to upload a PDF file, save it in a directory under a specific name for querying purposes, and store that name in an SQL table. I am utilizing Express-fileupload to handle the file upload process, but when I t ...

What is the best way to eliminate the gap between these two div elements?

There's a gap between two divs in my HTML that I can't seem to remove. Here are the relevant CSS styles: #tab-2-content { display: grid; grid-template-rows: 1fr 2fr; width: 70%; margin: 0 auto; grid-gap: 0; } ... (CSS code continues) ...

Enhance Your Website with Stunning Bootstrap Icons

I have been attempting to utilize this bootstrap signup template here, but upon rendering it, the icons for the user, email, password, and so forth are not appearing as expected. <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email ...

The `required` attribute is ineffective when used with the `<form>` element

My required attribute isn't enforcing mandatory field completion before form submission. HTML Code: <!-- Modal Content --> <form class="modal-content2"> <div class="container3"> < ...

Activate the button click event using JavaScript or jQuery automatically when the page is loaded in Internet Explorer

Currently, I'm faced with this code snippet: window.onload = function () { $('#btnFilter').click(function (e) { btnFilter(e); }); } The issue here is that the function only works when the button is clicked. What I actually ...

Compile a list of URLs found within a particular HTML A tag and save them to a text file

In an attempt to extract specific URLs from a webpage, I aim to target only those within a particular HTML A tag. For instance, the targeted URLs are in HTML A tags that contain "Info science": a bunch of HTML before <a rel="external nofollow&quo ...