What is the best way to create a 3 x 3 CSS grid layout with a sidebar that spans the full height of the viewport using grid-template-areas?

Can someone provide guidance on achieving this layout https://ibb.co/Y8TQLcC while maintaining the DOM order? I've been struggling with grid template areas.

body {
  margin: 0;
}

* {
  box-sizing: border-box;
}

.parent {
display: grid;
grid-template-areas: 
  "one three";
   "two"
}

.one {
  grid-area: one;
  border: 1px solid;
}

.three {
grid-area: three;
  border: 1px solid;
}

.two {
grid-area: two;
  border: 1px solid;
}
<div class="parent">
    <div class="one">one</div>
    <div class="three">three</div>
    <div class="two">two</div>
</div>

Answer №1

It seems like your grid-template-areas are not correctly defined. Imagine it as sketching out a basic table/grid and informing CSS about the specific cells in rows and columns that should behave in a certain way when displayed.

To correct this, adjust the grid-template-areas to:

grid-template-areas: 
  "one one three"
  "one one three"
  "two two three";
}

The updated code will look like this:

body {
  margin: 0;
}

* {
  box-sizing: border-box;
}

.parent {
display: grid;
grid-template-areas: 
  "one one three"
  "one one three"
  "two two three";
grid-template-rows: auto; height: 100vh;
}

.one {
  grid-area: one;
  border: 1px solid;
}

.three {
grid-area: three;
  border: 1px solid;
}

.two {
grid-area: two;
  border: 1px solid;
}
<div class="parent">
    <div class="one">one</div>
    <div class="three">three</div>
    <div class="two">two</div>
</div>

Answer №2

Your preferred design consists of a grid layout with 3 rows and 3 columns, occupying the entire height of the viewport.

To achieve this layout, you need to adjust the .parent grid container element's grid-template-areas property accordingly.

Furthermore, make sure to set the height of .parent to cover 100% of the viewport height using the viewport-percentage lengths unit vh:

.parent {
  display: grid;
  height: 100vh;
  grid-template-areas: 
  "one one three"
  "one one three"
  "two two three";
}

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

The PHP code encountered a syntax error due to an unexpected $EOF on the final empty line

I've been tasked with maintaining an old website that went offline due to script errors. I managed to resolve most of the issues in the script, but there's one error that's giving me trouble. The site is showing a syntax error that says "une ...

Is there a way to not limit the height of parent elements when using the Bootstrap 4.6 grid system or Flexbox

I'm struggling to make Bootstrap/Flexbox work smoothly within a height restriction. In my design, I have a <main> element with a set height. In the application itself, this height is calculated so that the footer aligns perfectly at the bottom ...

On the x-axis of the D3 graph, each data point is precisely the width of a date

I am currently trying to visualize data based on dates, and I am aiming for something similar to the following: My goal is to create rectangles that represent each day's data. Here is how I am drawing the rectangles: svg.selectAll(".my_class") .data ...

Display Highcharts in an HTML table format

As I work on developing a system that generates various types of graphs, my goal is to synchronize a chart and table so that when the chart is DRILLDOWNED, the table will also update. Is there a method to convert the data currently displayed by HighChart ...

CSS3: What is causing this issue in FireFox?

http://jsfiddle.net/tNg2B/ It's clear that there is a noticeable difference when viewing this in Chrome compared to Firefox. The ":before" and ":after" pseudo classes seem to be malfunctioning in Firefox. Is there a way to resolve this issue? Edit: ...

Flexbox element in React not resizing to fit width

I've been working on a slide carousel and it's almost complete, but I'm facing an issue with adjusting the arrows to the images. When testing the website for responsiveness, I noticed that the div inside the flexbox stops shrinking and rema ...

HTML/CSS Challenges: Dealing with Play Button Alignment Issues

Having a header on the left side and wanting to insert a button in line with the header on the right side has me facing some issues. Setting "position:relative" and "top:400px" moves the button perfectly, as does adding "left:200px". However, upon hoverin ...

I'm encountering difficulties with customizing the root styling of material-ui's DialogActions

Check out the two buttons in a DialogActions just like this. This is the JSX snippet I'm working with: <DialogActions classes={{ root: classes.dialogActionsLeft }}> <Button autoFocus onClick={() => { setOpen(false); }} ...

It is imperative that the HTML div element remains within the boundaries of the page

Let me begin by providing some context. I am currently developing a responsive page that uses percentages to position my divs, allowing users to drag and drop items wherever they please. However, a problem arises when the user positions an object too close ...

Is there a way to display Unicode block characters seamlessly in Chrome without any spaces between them?

Is there a way to properly display data containing Unicode full block characters (\u2588) without gaps caused by font smoothing in browsers? ██████████████ What methods can be used to render these characters seamlessly? I ...

Troubleshooting problem with Angular 2 in Internet Explorer related to the use of [style]="

I've encountered a challenge while using angular 2 (2.0.0-beta.17). The app works perfectly on most browsers, but as expected, IE 11 is causing trouble. The scripts included in the head for angular are: <script type='text/javascript' sr ...

Utilize JQuery to display a modal dialog within a pre-existing modal dialog

In my project, I am currently utilizing JQuery version 2.1.1 and JQuery UI version 1.11.0. My aim is to open a modal dialog within another modal dialog, with the primary (parent) dialog being disabled. While both dialogs have their modal properties set to ...

When the flex-grow property is set to 1, the height of the div extends beyond the space that

Here is an example of some HTML code: .container { height: 100%; width: 100%; display: flex; flex-direction: column; padding: 10px; background-color: aqua; } .box { width: 100%; height: 100%; flex-grow: 1; background-color: cadetb ...

Tips for aligning numerous rows in a single column using Bootstrap

I have a col div with 3 row divs that I am trying to center within the col div. Currently, they are aligned to the left side of the col div as shown in the image. I am struggling to figure out how to place them in the center of the col div. https://i.ssta ...

What is the process for integrating PHP into CSS code?

Seeking some assistance here. I am attempting to incorporate PHP code, specifically for retrieving an image from a database, into CSS. My issue lies in having a small section of CSS code on my example.php page and needing to display different background i ...

What measures can be taken to keep the rightmost element from moving when hovered over?

While I am generally happy with the layout, there seems to be a slight jump to the left when hovering over the right-most image (you need to click "show images" to view them). Strangely, this issue does not occur with the last row of images. Any suggestion ...

Struggling to align my image in the center while applying a hover effect using CSS

Hey there, I'm having an issue centering my image when I add instructions for it to tilt on mouseover. If I take out the 'tilt pic' div, the image centers just fine. Can anyone help me identify what I might be doing wrong? Thanks in advance! ...

Preventing Canvas Image Disappearance with JavaScript's onload Event

My current issue involves adding an Image to my webpage. However, every time I hit the refresh button, the image disappears. After researching on Stack Overflow, it was suggested to include window.onload=yourDrawFunction() in the code. Despite following th ...

Step-by-step guide on creating a linear graph in CSS using a table

I am a newcomer to the world of CSS and I am looking to create a graph using CSS without the use of any libraries or frameworks. Can someone kindly assist me in drawing a linear graph using this HTML table? Appreciate any help in advance. <html> & ...

How can a specific button be disabled by using its id in Angular with Typescript?

There are 3 cards, each with a "Like" button. I have already written the code to detect their ids, but now I want to know how to disable the button that has been clicked and create a table in another component that displays the information of the button on ...