CSS Grid must occupy the entire width and height on every side

Can someone help me out with a coding issue I am facing? Here's the scenario:

I have set up all my boxes on a grid layout, but I want all the black borders to touch each other seamlessly. Essentially, I want the entire page to be filled only with the grid layout. Below is the code snippet for reference:

DEMO:

 * {
    margin: 0 auto;
}

body {
    width: 100%;
    height: 100%;
    min-width: 100%;
    overflow: hidden;
}

.grid-container {
        display: grid;
        grid-template-columns: 0.8fr 2fr 0.8fr;
        grid-template-rows: 1fr 1fr 1fr 1fr;
        gap: 0px 0px;
        grid-template-areas:
            "logo nav time"
            "computer-menu terminal computer-anim"
            "missions terminal notebook"
            "missions terminal notebook";
    }

.missions {
    grid-area: missions;
    border: 3px solid black;
}

.terminal {
    grid-area: terminal;
    border: 3px solid black;
}

.notebook {
    grid-area: notebook;
    border: 3px solid black;
}

.computer-menu {
    grid-area: computer-menu;
    border: 3px solid black;
}

.logo {
    grid-area: logo;
    border: 3px solid black;
}

.nav {
    grid-area: nav;
    border: 3px solid black;
}

.time {
    grid-area: time;
    border: 3px solid black;
}

.computer-anim {
    grid-area: computer-anim;
    border: 3px solid black;
}
<div class="grid-container">
    <div class="missions"><h1>MISSIONS</h1></div>
    <div class="terminal"><h1>TERMINAL</h1></div>
    <div class="notebook"><h1>NOTEBOOK</h1></div>
    <div class="computer-menu"><h1>COMPUTER-MENU</h1></div>
    <div class="logo"><h1>LOGO</h1></div>
    <div class="nav"><h1>NAV</h1></div>
    <div class="time"><h1>TIME</h1></div>
    <div class="computer-anim"><h1>COMPUTER-ANIM</h1></div>
</div>

Answer №1

The issue lies within this specific rule in your code:

* {
   margin: 0 auto;
}

The usage of auto margins is causing the grid items to be centered within the columns.

To resolve this, you can either remove that rule entirely or adjust the selector accordingly.

 /* * {
   margin: 0 auto;
 } */

 body {
   width: 100%;
   height: 100%;
   min-width: 100%;
   overflow: hidden;
 }

 .grid-container {
   display: grid;
   grid-template-columns: 0.8fr 2fr 0.8fr;
   grid-template-rows: 1fr 1fr 1fr 1fr;
   gap: 0px 0px;
   grid-template-areas:
     "logo nav time"
     "computer-menu terminal computer-anim"
     "missions terminal notebook"
     "missions terminal notebook";
 }

 .missions {
   grid-area: missions;
   border: 3px solid black;
 }

 .terminal {
   grid-area: terminal;
   border: 3px solid black;
 }

 .notebook {
   grid-area: notebook;
   border: 3px solid black;
 }

 .computer-menu {
   grid-area: computer-menu;
   border: 3px solid black;
 }

 .logo {
   grid-area: logo;
   border: 3px solid black;
 }

 .nav {
   grid-area: nav;
   border: 3px solid black;
 }

 .time {
   grid-area: time;
   border: 3px solid black;
 }

 .computer-anim {
   grid-area: computer-anim;
   border: 3px solid black;
 }
<div class="grid-container">
  <div class="missions">
    <h1>MISSIONS</h1>
  </div>
  <div class="terminal">
    <h1>TERMINAL</h1>
  </div>
  <div class="notebook">
    <h1>NOTEBOOK</h1>
  </div>
  <div class="computer-menu">
    <h1>COMPUTER-MENU</h1>
  </div>
  <div class="logo">
    <h1>LOGO</h1>
  </div>
  <div class="nav">
    <h1>NAV</h1>
  </div>
  <div class="time">
    <h1>TIME</h1>
  </div>
  <div class="computer-anim">
    <h1>COMPUTER-ANIM</h1>
  </div>
</div>

Answer №2

Have you attempted to apply the following CSS:

/* INCLUDED */
.grid-container > div {
  width:calc(100% - 6px);
}

EXAMPLE

* {
    margin: 0 auto;
}

body {
    width: 100%;
    height: 100%;
    min-width: 100%;
    overflow: hidden;
}

.grid-container {
    display: grid;
    grid-template-columns: 0.8fr 2fr 0.8fr;
    grid-template-rows: 1fr 1fr 1fr 1fr;
    gap: 0px 0px;
    grid-template-areas:
        "logo nav time"
        "computer-menu terminal computer-anim"
        "missions terminal notebook"
        "missions terminal notebook";
}

.missions {
    grid-area: missions;
    border: 3px solid black;
}

.terminal {
    grid-area: terminal;
    border: 3px solid black;
}

.notebook {
    grid-area: notebook;
    border: 3px solid black;
}

.computer-menu {
    grid-area: computer-menu;
    border: 3px solid black;
}

.logo {
    grid-area: logo;
    border: 3px solid black;
}

.nav {
    grid-area: nav;
    border: 3px solid black;
}

.time {
    grid-area: time;
    border: 3px solid black;
}

.computer-anim {
    grid-area: computer-anim;
    border: 3px solid black;
}

/* INCLUDED */
.grid-container > div {
  width:calc(100% - 6px);
}
<div class="grid-container">
    <div class="missions"><h1>MISSIONS</h1></div>
    <div class="terminal"><h1>TERMINAL</h1></div>
    <div class="notebook"><h1>NOTEBOOK</h1></div>
    <div class="computer-menu"><h1>COMPUTER-MENU</h1></div>
    <div class="logo"><h1>LOGO</h1></div>
    <div class="nav"><h1>NAV</h1></div>
    <div class="time"><h1>TIME</h1></div>
    <div class="computer-anim"><h1>COMPUTER-ANIM</h1></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

Achieving Vertical Stacking and Responsive Scaling for Row and Column Containers on Mobile View Using HTML, CSS, and Bootstrap 4

Utilizing the Bootstrap grid system to organize text boxes in a 2 by 2 layout on a webpage. The desktop view displays the content in rows and columns effectively, but it would be beneficial to have an easy way to adjust the width. However, the problem ari ...

Unable to open modal using a button in PHP

<?php $result = mysqli_query($con, $sql); while ($row = mysqli_fetch_array($result)) { echo '<tr><td>'; echo '<h5 style="margin-left:6px; color:black;">' . $row['id'] . '</h5> ...

What is the most efficient way to write this code?

When I find myself surrounded by a ton of PHP code, instead of exiting PHP I tend to include variables directly within strings like this: echo "This is how I use a ".$variable." inside a string"; However, I wonder if it would be more efficient to actuall ...

What is the method for placing an image retrieved from a pointer as the background image?

In my code, I am retrieving an image from a specific source: <img src={event.eventData?.foto_portada} /> The issue arises when I attempt to utilize that image within my CSS properties as shown below: .background-image { background-image: url(); ...

Discovering the row that was clicked: A step-by-step guide

Hello, I have created a table using JavaScript and now I am looking to determine the row and column that the user has clicked on. Below is the function I am using to generate the table: function doNextSteps() { removeAustriaFromCountries(); //i ...

Could you please review my PHP code? I encountered a syntax error: unexpected '}' character. Thank you

I encountered an issue in the final line <?php } ?> as it reports a syntax error, unexpected '}' <?php if (isset($_SESSION['u_id'])) { //echo "You are logged in!"; include_once 'database.php&apo ...

When viewing submenus of the selected menu item, they will display in the same color as

There is a menu item on the site labeled portfolio with 3 sub menus that have been added as links in the WordPress menu. When we click on the portfolio menu, the text color of the sub menus also changes. I have commented out the CSS for the current menu it ...

The sign-up button mysteriously vanishes after the page is refreshed

I am encountering an issue with the sign up button during the user registration process. There is a checkbox for Terms & Conditions, and the button should only become enabled after checking this box. Everything seems to be functioning correctly, but when I ...

Is there a way to utilize HTML and CSS to position checkboxes in front of text questions?

I need help with organizing checkboxes and labels in my webform. Currently, the checkboxes are appearing after the label text, causing them to be misaligned. How can I ensure that the checkboxes appear before the corresponding text? <label for="needs ...

What is the best way to change the innerHTML of an element with AJAX before it has been loaded into the DOM?

Currently, I have a main feed that displays a list of blog post titles. Whenever a title is clicked, I want to show the details of the corresponding blog post in a new HTML file. Here's my existing code: window.location.href = "/viewpost.html"; ...

Tips for adjusting the size of various div elements by dragging in Ionic using AngularJS

I am developing an exciting ionic application that is designed to mimic the layout shown in the image below. The app will feature three dynamic div elements that adjust their size based on the movements of a draggable red circle on the screen. Check out t ...

A step-by-step guide to configuring layouts in AngularJS

I'm a newcomer to Angular JS with a screen layout that is split into 4 sections. <table> <tr> <td>Section 1</td> <td>Section 2</td> <td>Section 3</td> </tr> <tr> <td ...

When utilizing *NgIf, the button will be shown without the accompanying text being displayed

When trying to display either a confirm or cancel button based on a boolean set in my component.ts, I implemented the following code in my HTML: <mat-dialog-actions class="dialog-actions"> <button class="cancel-btn" ...

When utilizing React, I generated an HTML page with a distinct .js file, however, encountered two unexpected errors

Update : Gratitude to everyone who has helped me in tackling this issue. One user suggested using a web server, but my intention was to find a solution using just a single HTML and JS file. Even though I tried following the steps from a similar question o ...

A menu bar featuring dual color schemes for visual differentiation

I am currently designing a navigation bar where one category stands out with a different color (blue) compared to the rest (green). The functionality I'm aiming for is that when the cursor moves away from the blue HOME category, it should change back ...

placing an image within a frame

I am having trouble aligning two divs side by side. I want to create a white background box with the date displayed in the top right corner, and I want the image to be at the same height as the date. Below is the code I have written: #boxx { background-c ...

Can anyone provide guidance on how to trigger 3 unique functions in a specific order using JavaScript?

I've been troubleshooting this issue for quite some time, but I just can't seem to figure it out. Here's my dilemma: I have three functions - one to shrink a div, one to reload the div with new data, and one to enlarge the div - all triggere ...

Incorporating the parent object into a nested JavaScript function

I have come across similar questions, but my situation seems unique to me. I have simplified my code and turned one line into a comment, but the core concept remains unchanged... function myFunction(options) { var button; options.widgets.forEach(f ...

Tips for consistently positioning a div beneath another div in HTML/CSS

Would appreciate it if you could review this. <.div id="main"> Main Div <./div> <br/> <.div id="sub">Sub-Division<./div> ...

The nth-child selector is not functioning correctly with material-ui components

Trying to figure out how to give two paragraphs different background colors using nth-child. Here's the JSX: <div className={classes.paragraphs}> <p>Test 1</p> <p>Test 2</p> </div> And the CSS: const useSty ...