Utilizing a grid system to stack blocks with identical area labels

I'm attempting to design a 3-column layout where blocks are placed in their respective columns based on their class. Here is an example of what I have in mind: https://i.sstatic.net/0GnUN.png

My initial approach was as follows:

<div class="container">
  <div class="type1">type1</div>
  <div class="type2">type2</div>
  <div class="type2">type2</div>
  <div class="type1">type1</div>
  <div class="type2">type2</div>
  <div class="type3">type3</div>
</div>
.container{
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-areas: 'type1 type2 type3';
  gap: 20px;
  padding: 20px;
}
.type1{
  background-color: aqua;
  grid-area: type1;
}
.type2{
  background-color: forestgreen;
  grid-area: type2;
}
.type3{
  background-color: salmon;
  grid-area: type3;
}

However, the issue with this implementation is that blocks with the same grid-area will be overlapped.

https://i.sstatic.net/2A1hy.png

I'm trying to identify the problem in my code and determine if there's a solution for achieving the desired layout. p.s: The order of the blocks is random since I am dynamically generating them based on data types.

Answer №1

Special thanks to Paulie_D!!

Thanks to his suggestion, I was able to implement the changes successfully.

.container{
    display: grid;
    gap: 20px;
    padding: 20px;
    grid-auto-flow: column;
    grid-template-columns: repeat(3,1fr);
}
.type1{
    background-color: aqua;
    grid-column-start: 1;
}
.type2{
    background-color: burlywood;
    grid-column-start: 2;
}
.type3{
    background-color: coral;
    grid-column-start: 3;
}

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

"Learn how to create a scrolling div using a combination of CSS and JavaScript with absolute and relative

After relying solely on "pre-made" components like Mui or TailWind, I decided to create a component using only CSS and maybe JavaScript. However, I encountered some difficulties when attempting to position a div inside an image using relative and absolute ...

Triangle-shaped border image with a gradient pattern

How can I create an odd-shaped triangle using CSS? Initially, I used transparent borders with transform: rotate to achieve the left triangle shape successfully. However, I am now attempting to use a gradient border image pattern as the background for the s ...

Targeting the landscape mode on screens of both iPhone 4 and iPhone 5 sizes using CSS3 Media Queries

I'm facing a problem with CSS3 media queries while developing a mobile site. The code I've written works perfectly on the landscape mode of an iPhone 5, but it's not quite right on an iPhone 4 or earlier in landscape mode. /* Default stylin ...

Eliminate any vacant areas within a container and shift the container, along with its contents, on the webpage

I want to eliminate the empty space within the container while maintaining some spacing around the black box, and ensure responsiveness. Additionally, how can I shift the container with its content downwards and to the right of the webpage, while still ke ...

Instructions on deactivating the background when the sidebar is displayed and closing the sidebar by clicking anywhere other than the sidebar

I'm in the process of creating a sidebar for my website. When the sidebar is displayed (by clicking showRight), I want to disable the background content so that the user can't interact with anything outside of the menu. If the user clicks on th ...

What is the process to change the URL?

Currently, I am deep into developing a large-scale web application for a company. The project has been ongoing for about four months now, and we have encountered a harmless yet annoying issue that we haven't had time to address. The problem lies in t ...

Explore the Filter List without being affected by the arrangement of words or the level of search precision

I was able to resolve the issue by adjusting my search filter algorithm. Now, I can search regardless of word order, but the results are not as specific as I need them to be. When I type "Correy" in the search bar, it shows all results containing that wo ...

Bootstrap 4 Card Body Spinner Overlay with Flex Alignment

Seeking to center a spinner both vertically and horizontally within a bootstrap 4 card body. Despite trying my-auto, justify-content-center & align-items-center, it seems like I'm missing something. I've double-checked the display types and ...

Resolving jQuery complications in the validation of login forms

I've been attempting to validate a form using jQuery and PHP, but none of the tutorials I've followed have worked for me. I'm feeling lost and confused as I've tried multiple approaches with no success. I'm hoping someone can pinpo ...

Dealing with Vertical Alignment in the Center and Landscape Orientation challenge in Bootstrap 4.1

When in landscape orientation, I'm facing an issue with the vertical alignment being centered (card in the middle of the screen), which cuts off various elements like my logo image... The "problem" lies in the h-100 class of the MAIN tag, as well as ...

Internet Explorer does not offer support for stopping scrolling using either jQuery or CSS

I have created an overlapping screen similar to Facebook's photo viewer, and it works well on Chrome, Safari, and Firefox. However, I am struggling to make it work on Internet Explorer (IE). The issue is that the div overlaps correctly but allows scro ...

Changing a URL parameter based on the element's width is a simple task when

I'm trying to display elements on a page by replacing a string in the URL parameter with the width of each element of a certain class. I'm new to JavaScript, so any help would be appreciated! Here's an example of the HTML for objects on the ...

Significant empty space to the left of content due to Zurb Foundation

I'm currently utilizing Zurb Foundation within a rails project. My goal is to structure a basic page that consists of a table, text field, and a couple of buttons. However, I am facing a significant gap on the left side of my content, causing the rig ...

I'm attempting to update the background image source by fetching a URL inputted into a form field

I am struggling to update the background image source using a URL provided in a form field. Despite my efforts, I have not been successful in making the necessary changes. My coding skills are limited and I find myself stuck in this situation. Any assist ...

Am I on the right track with incorporating responsiveness in my React development practices?

Seeking advice on creating a responsive page with React components. I am currently using window.matchMedia to match media queries and re-rendering every time the window size is set or changes. function reportWindowSize() { let isPhone = window.matchMed ...

How can you achieve a vertical list display for a label while preserving its inline-block properties?

I have chosen to use labels for my radio buttons because I enjoy the convenience of being able to click on the text to select the option. However, I want these labels to appear in a vertical list format. Currently, they are displaying as blocks, causing th ...

I am experiencing difficulty closing my Bootstrap 5 nav bar once it has been clicked in mobile view

Having an issue with my Bootstrap 5 navbar in mobile view - it can be clicked to open, but won't close when clicked again. Currently using Bootstrap v5.0. If anyone has insight into why this might be happening, please let me know! <link href ...

Tips on extracting JSON data from an HTML source using BeautifulSoup in Python

In my HTML page, I have a variety of information including: <input class="json-data" id="init-data" type="hidden" value='{"keyboardShortcuts":[{"name":"xxxx","description":"yyyyy", > etc... I am trying to extract something like name = xxxx ...

What criteria does a PHP function need to meet in order to be considered valid for use with AJAX and PHP?

My website includes an input field that undergoes real-time checking via AJAX requests to inform users if their input is valid or not. Upon submission, the input must be rechecked to ensure it meets the same criteria as checked by AJAX (in case JavaScript ...

HTML does not support the use of certain symbols

Currently, I am in the process of designing a homepage for my school project. However, I have run into an issue. The content that I want to be displayed on my homepage is as follows: "Daudzspēlētāju tiešsaites lomu spēle (Massively Multiplayer Online ...