The grid area may not properly adjust based on the width size of the browser

When adjusting the width of your browser, you may notice occasional white space in the bottom right corner.

https://i.stack.imgur.com/UFV6R.png https://i.stack.imgur.com/VfhMN.png

Is there a way to remove this extra margin?

In other words, how can I ensure that the card__bottom_right class occupies the entire side?

Why does it sometimes fit perfectly while at other times there is a gap?

This is the code snippet:

<!DOCTYPE html>
<html>
<head>
  <title></title>
  <style type="text/css">
    body {
      background: black;
    }

    .card {
      margin: 0 auto;
      max-width: 800px;
      background: white;
      overflow: hidden;

      display: grid;
      grid-template:
        "card__title card__title card__title" 1fr
        "card__message card__message card__message" 1fr
        "card__bottom_left card__bottom_middle card__bottom_right" 1fr
        / 1fr 1fr 1fr;
    }

    .card__title {
      padding-top: 16px;
      padding-left: 16px;
      grid-area: card__title;
    }

    /* Remaining CSS styles have been retained for reference */

  </style>
</head>
<body>

<div class="card">
  <div class="card__title">Title</div>
  <div class="card__message">Message</div>
  <div class="card__bottom_left">1</div>
  <div class="card__bottom_middle">2</div>
  <div class="card__bottom_right">3</div>
</div>

</body>
</html>

The reproduction of the issue in the above snippet might not be visible on Stack Overflow but should appear correctly on a full page view.

I encountered the issue when the browser width was set to 1085px using Chrome Version 85.0.4183.83 (Official Build) (64-bit).


To aid in reproducing the scenario, I have created a class named wrap that simulates the browser behavior. This should help replicate the problem effectively.

<!DOCTYPE html>
<html>
<head>
  <title></title>
  <style type="text/css">
    body {
      background: black;
    }

    .wrap {
      width: 1085px;
    }

    /* Similar CSS styles as before are used here to maintain context */

  </style>
</head>
<body>
  <div class="wrap">
    <div class="card">
      <div class="card__title">Title</div>
      <div class="card__message">Message</div>
      <div class="card__bottom_left">1</div>
      <div class="card__bottom_middle">2</div>
      <div class="card__bottom_right">3</div>
    </div>
  </div>
</body>
</html>

An enlarged image showcasing the aforementioned issue can be viewed below.

https://i.stack.imgur.com/IsBlz.png

Questions Overview

  • How can the grid area be properly fitted?
  • If possible, what causes the misalignment in some cases?

Answer №1

To enhance the visual layout, consider adjusting the background color of the elements.

<!DOCTYPE html>
<html>
<head>
  <title></title>
  <style type="text/css">
    body {
      background: black;
    }

    .card {
      margin: 0 auto;
      max-width: 800px;
      
      overflow: hidden;

      display: grid;
      grid-template:
        "card__title card__title card__title" 1fr
        "card__message card__message card__message" 1fr
        "card__bottom_left card__bottom_middle card__bottom_right" 1fr
        / 1fr 1fr 1fr;
    }

    .card__title {
      padding-top: 16px;
      padding-left: 16px;
      grid-area: card__title;
    }
    
    .card__title,
    .card__message {
      background: white;
    }

    .card__message {
      padding-top: 16px;
      padding-left: 16px;
      grid-area: card__message;
    }

    .card__bottom_left {
      background: pink;
      padding-left: 16px;
      grid-area: card__bottom_left;
    }

    .card__bottom_middle {
      background: pink;
      grid-area: card__bottom_middle;
    }

    .card__bottom_right {
      background: pink;
      grid-area: card__bottom_right;
    }

  </style>
</head>
<body>

<div class="card">
  <div class="card__title">Title</div>
  <div class="card__message">Message</div>
  <div class="card__bottom_left">1</div>
  <div class="card__bottom_middle">2</div>
  <div class="card__bottom_right">3</div>
</div>

</body>
</html>

Answer №2

Implement a condensed version of Eric Meyer's CSS reset.

Test out the following code snippet before applying any custom body styles. It worked well for my project!

https://i.stack.imgur.com/AA43D.png

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  border: 0;
  vertical-align: baseline;
}

Reference:

Credits to Concordia Bootcamps for the adaptation.

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

Preserve text input from a multi-line textarea

Having an issue with a form that includes a <textarea>....</textarea> field. When saving the text, it displays the result in another form but as one continuous line within a paragraph <p>...</p>. The problem arises when trying to e ...

HTML code now launches in the existing electron window rather than opening a new window

<html> <head> <title></title> </head> <input type="button" name="new" id="newmon" value="new"> <button onclick="open1()">monitor 1</button&g ...

Creating a responsive design with dual backgrounds using Tailwind CSS

I have a design in Figma that I want to convert to React using Tailwind CSS while maintaining 100% pixel-perfect accuracy. The design is created for a Macbook Pro 16 inch, which has a width of 1728px. However, I want to center the content within a customiz ...

What's the best way to expand the right side of .li following a left offset of -20px

My nested list structure looks like this... https://i.sstatic.net/sggVx.png What you see is a recursive ul/li setup... <div class="family d-block"> <span class="pb-2"> <small class="text-muted">Family:</small><br> < ...

Tips for customizing the appearance of an HTML dropdown menu

Here is the code snippet: <select name="xyz" id="abc"> <option value="x">10/Page</option> <option value="y">20/Page</option> <option value="z">30/Pa ...

How can we refine the user information based on the selection of a radio button?

How do I apply a filter to user details when selecting a radio button? Visit Plunker *I need to display only the questions of authenticated users on the list page, so I created a plunker example. If the user is authenticated or an admin, I want to filter ...

Is it possible to modify the flex direction in Bootstrap based on specific breakpoints?

I am currently utilizing Bootstrap 4 for my project. I have a div that is styled with "d-flex" and it is meant to display as a row at the "lg" breakpoint (screens 1200px and above). However, on smaller devices such as mobile phones at the "sm" or "xs" brea ...

ever-evolving background-image with dynamic CSS styling

Being new to both PHP and Javascript, please excuse any mistakes in my explanation. I have information stored in a PHP array that I bring to my index page using the function below (located in a separate file called articles.php that is included in my index ...

Truncating text with ellipsis in CSS when wrapping on a nested div structure

Here is a 3-tier nested div tree structure with the outer node having a maximum width where I want the ellipsis wrapping to occur. I've almost achieved the desired result, but the issue arises when the inner nodes are not trimmed to accommodate as mu ...

Executing a function upon the loading of a template in AngularJS

I have been searching through various responses here, but I haven't come across one that addresses my specific problem. Apologies if this has already been answered. I am a beginner in angular js and have recently begun working on angular routing. I am ...

Do you know the term for when JavaScript is utilized to display specific sections of a png image?

Imagine you have an image file in the format of a PNG which includes various icons intended for use on a website. How can JavaScript be utilized to choose and showcase a specific icon from that image? It's a technique I've observed in practice, b ...

Certain rows appear to be missing even though they are present in both the webpage and its corresponding source code

I am facing a CSS issue that I am unable to resolve. I have 20 results that should be displayed on my website, but only 14 of them are appearing. The other ones are visible in the source code when inspected. When I move the position of the menu up or down, ...

Seeking instructions on incorporating multiple components in a tab section effectively?

I am currently using a tab system that functions flawlessly. As I delve into learning VueJs, one concern has arisen in my mind about components and/or templates: Using the analogy of tab windows, how can I incorporate two components within a single tab, s ...

"Improve text visibility on your website with Google PageSpeed's 'Ensure text remains visible' feature, potentially saving you

Click here for the image reference showing the 0ms potential saving message I'm having trouble with a warning in Google PageSpeed and I've tried everything. This is the code I'm using to define the font-family: @font-face { font-family: ...

What are some strategies to stop a jQuery UI button created with a link from inheriting the link's text color?

I recently came across a recommendation to create a jQuery button on top of a link for redirect purposes: <a href="/search" class="button">My link</> $(".button").button(); However, I noticed that if the button class has a red foreground colo ...

Utilizing a box within a background image using HTML and CSS

In the midst of my college project, I've encountered a hurdle. There's an image I need to overlay with a box that has padding on all sides corresponding to the outline of the image. Despite my attempts, I haven't been successful in achieving ...

Checking links with AngularJS and HTML 5

Good day everyone: It seems like a simple question, but despite spending hours searching online, I am still unable to find the solution: how can an URL be validated with the inclusion of www without using http. Here's what I have tried so far: I a ...

The positioning of the menu icons varies

When it comes to displaying the search icon in the WordPress toggle bar, I use a custom JavaScript file. This setup is mainly focused on website design and menu functionality. Additionally, I have integrated a newsletter subscription plugin for managing su ...

What is the best way to assign an identifier to a variable in this scenario?

script.js $('a').click(function(){ var page = $(this).attr('href'); $("#content").load(page); return false; }); main.html <nav> <a href="home.html">Home</a> <a href="about.html">About</a> < ...

automatically collapse a submenu once a different menu option is selected

After doing some research and trying out various solutions, I still couldn't get it to work. I made adjustments to my dropdown menu and click function so that each submenu opens and closes when its parent is clicked. However, I'm now looking to f ...