Design a new CSS grid arrangement

Need help with achieving a responsive layout using CSS grid. The design should be as seen in the image link below for resolutions over 900px:-

https://i.sstatic.net/QaFub.jpg

For resolutions lower than 900px, the layout should switch to resemble this https://i.sstatic.net/fGqCC.jpg

I have attempted the following so far:

.container {
   display: grid;
   grid-template-columns: 250px auto 250px;
   grid-column-gap: 1rem;
 }

The current code successfully creates the first image layout but I'm struggling with adapting it for the second layout under 900px resolution.

Any suggestions on how to modify the CSS grid to achieve the desired layout as shown in the images?

Feel free to check out my code here: jsfiddle

Answer №1

Improvements in using grid-template-areas

.item1 { grid-area: box1; }
.item2 { grid-area: box2; }
.item3 { grid-area: list; }
.item4 { grid-area: box3; }

.grid-container {
  display: grid;
  grid-template-areas:
    'box1 list box3'
    'box2 list box3';
  grid-gap: 10px;
  background-color: #2196F3;
  padding: 10px;
}

.grid-container > div {
  background-color: rgba(255, 255, 255, 0.8);
  text-align: center;
  padding: 20px 0;
  font-size: 30px;
}

@media screen and (max-width: 900px) {
    .grid-container {
      grid-template-areas:
        'box1 list'
        'box2 list'
        'box3 list';
    }
}
<div class="grid-container">
  <div class="item1">Box 1</div>
  <div class="item2">Box 2</div>
  <div class="item3">List</div>  
  <div class="item4">Box 3</div>
</div>

Answer №2

I am looking forward to utilizing grid-column-start, grid-column-end, grid-row-start, and grid-row-end to create the necessary grids in conjunction with media queries.

.grid-container {
  display: grid;
  grid-template-columns: auto auto auto;
  grid-gap: 10px;
  background-color: #2196F3;
  padding: 10px;
}
.grid-container > div {
  background-color: rgba(255, 255, 255, 0.8);
  text-align: center;
  padding: 20px 0;
  font-size: 30px;
}
.box2{
  grid-column-start:1;
  grid-column-end:2;
}
.list1 {
  grid-row-start: 1;
  grid-row-end: 3;
  grid-column-start:2;
  grid-column-end:3;
}
.box3{
 grid-column-start:3;
 grid-column-end:4;
 grid-row-start:1;
 grid-row-end:2;
}

@media (max-width:900px){
    .grid-container {
      grid-template-columns: auto auto;
    }
    .list1 {
    grid-row-start: 1;
    grid-row-end: 4;
    }
   .box3{
    grid-column-start:1;
    grid-column-end:2;
    grid-row-start:3;
    grid-row-end:4;
    }
 
}
<h1>Grid Lines</h1>

<div class="grid-container">
  <div class="box1">1</div>
  <div class="box2">2</div>
  <div class="list1">3</div>  
  <div class="box3">4</div>  
</div>

<p>You can refer to line numbers when placing grid items.</p>

Answer №3

Hopefully, utilizing grid-auto-flow: column combined with mediaquery will provide the desired layout

Access the code on Fiddle here

<div class="grid-container">
  <div class="item1">Box 1</div>
  <div class="item2">List</div>
  <div class="item3">Box 2</div> 
  <div class="item4">Box 3</div>
</div>


.grid-container {
  display: grid;
  grid-template-columns: 25% 50%;
  grid-gap: 10px;
  grid-auto-flow: column;

  > div {
    border: solid 1px #00f;
    padding: 10px;
  }
}

.item2 {
  grid-row-start: 1;
  grid-row-end:   3;
  grid-column: 2 / 3;
}


@media screen and (max-width: 900px) { 
  .grid-container { 
    grid-template-columns: 25% 1fr ;
  }

.item2 {
    grid-row-end: 4;  
  }
}

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

How can I ensure a div always moves to the right by using margin-right auto?

How can I align a div to the right using margin-right auto? I attempted margin-right: auto; and margin: 0 0 0 auto; but it was not successful. ...

Increase the div id using jQuery

I've got this code snippet here and, oh boy, am I a newbie. How can I increase the number in the div using a jQuery script? if($res >= 1){ $i=1; while($row = mysqli_fetch_array($qry)){ echo "<div clas ...

Angular - creating adaptive HTML container with CSS styling

I am trying to achieve a layout similar to the one shown in the image. A container can have multiple elements starting within it or no elements at all. The elements always have a fixed height, and the container's height is determined by the number of ...

The CSS style is missing from the print preview

I've designed a style specifically for printing like this: #content .inner h2 { background: Red; border-bottom: solid 1px #dfdfdf; color: #000000; font-size: 20px; padding-left: 10px; } However, the red color doesn't show up in the print previe ...

Are browser zoom and screen size variations equivalent in terms of impact on display?

I am curious about ensuring my website is responsive on all screen sizes. Is resizing the browser window equivalent to viewing my website on various devices with different screen sizes? I have observed that my webpage appears well on larger screens, but w ...

Enhancing the appearance of a PHP HTML email

I scoured the web for an answer to this question and all I could find was to include the following: $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; and ...

Tips for seamlessly integrating an overlay into a different image

My current system is set up to overlay the image when you check the checkboxes. However, I'm facing an issue with positioning the image inside the computer screen so it's not right at the edge. Can anyone provide assistance with this? <html&g ...

Using Angular 6 to load external HTML files with CSS inside a router-outlet

I'm currently working on creating a json-based dynamic template using Angular 6. There are certain scenarios where I need to fetch external html content (which could be stored in a database) along with its corresponding css (also stored separately in ...

When the canvas is dragged, an item within it suddenly leaps or bounces

I've noticed that when I drag the canvas using -webkit-transform: translate(x,y), an element on the canvas jumps. Are there any suggestions for addressing this issue? ...

What are some tips for leveraging aframe in order to achieve a captivating 360 video effect?

SCENARIO Inspired by the immersive effect showcased here, we aim to utilize a 360 video as the central feature of an extended webpage layout. ISSUE Exploring options, I experimented with Mozilla's aframe, demonstrated here. Yet, integrating an < ...

Automatically populate a div with content from a file

As I am completely new to the world of HTML, I find myself in need of quickly putting together something for work just as a proof of concept. I apologize if this question has been answered previously, but honestly, I wouldn't even know how to start se ...

Default modal overlay closure malfunctioning; encountering errors when manually managed through jQuery

A custom overlay has been designed and implemented. <div class="overlay modal" id="11"> <div class="background-overlay"></div> <div class="description"> <div class="hidden-xs"> <img src=' ...

Revamping Existing Styles: Making a Statement with `:after`

In my asp.net mvc application, I am facing an issue where the * symbol, representing a required field, and the ? symbol, representing help, are not both being displayed. The ? symbol seems to be overriding the * symbol, resulting in only one symbol being s ...

Choosing several buttons in typescript is a skill that every programmer must possess

I need help with selecting multiple buttons in TypeScript. The code I tried doesn't seem to be working, so how can I achieve this? var input = document.getElementById('input'); var result = document.getElementById('result'); v ...

Replace Font Awesome icon with a background image

Looking to replace a Font Awesome icon with a background image using only CSS. Current Setup: https://i.sstatic.net/tkPXz.jpg .btn.btn-default.bootstrap-touchspin-up:before { font-family: Fontawesome; content: "\f067"; font-size: 14px; } ...

Creating a responsive design using HTML and CSS to ensure that all elements fit perfectly on any window size or resolution

Currently, my friend and I are collaborating on a mod for the popular game known as Minecraft. My responsibility is to create a website where we can showcase this mod and provide information about its features. The main issue I am encountering is the inab ...

using node-sass with several different starting points

I am currently working on a project where my main entry point is structure.scss, and each platform has its own second entry point. Here is the folder structure: scss/ | |-- components/ # Modular Component Files | |-- login.scss ...

Transform HTML content into a PDF document with page breaks

Currently, I am developing a function that involves an HTML template. The purpose of this function is to generate a dynamic template and convert it into a PDF. So far, I have been able to achieve this using the following code: var output = ''; ...

Removing the gridlines in a Linechart using Apexcharts

I am experiencing issues with the grid and Nodata options on my Apexchart line chart. noData: { text: none , align: 'center', verticalAlign: 'middle', offsetX: 0, offsetY: 0, style: { color: undefined, fontSize: &apo ...

Ways to stop cascading CSS attributes to child elements?

I am in the process of creating three tables. <table id="first"> <tr> <td> 1. CAPTION </td> </tr> <tr> <td> <table id="second"> <tr& ...