Creating a Dynamic Grid Layout: A Step-by-Step Guide

Having created a specific grid layout using HTML and CSS, I am struggling to make it work across all devices. I have already created the CSS, but I seem to be missing something in the HTML, such as the col-md or col-sm classes from Bootstrap. However, every time I try to implement them, it still doesn't work properly. Can anyone help me with this issue?

.container {  display: grid;
    grid-template-columns: 285px 285px 285px 400px;
    grid-template-rows: 142px 296px 259px 333px;
    grid-auto-rows: 1fr;
    gap: 5px 5px;
    grid-auto-flow: row;
    grid-template-areas:
      "A B C D"
      "E B C D"
      "F G H D"
      "I I I I";
    width: 1440px;
    height: 1239px;
  }
  
  .A {
    grid-area: A;
    width: 259px;
    height: 122px;
  }
  
  .B {
    grid-area: B;
    width: 259px;
    height: 416px;
  }
  
  .C {
    grid-area: C;
    width: 259px;
    height: 416px;
  }
  
  .D {
    grid-area: D;
    width: 380px;
    height: 668px;
  }
  
  .E {
    grid-area: E;
    width: 259px;
    height: 273.87px;
  }
  
  .F {
    grid-area: F;
    width: 259px;
    height: 230px;
  }
  
  .G {
    grid-area: G;
    width: 259px;
    height: 230px;
  }
  
  .H {
    grid-area: H;
    width: 259px;
    height: 230px;
  }
  
  .I {
    grid-area: I;
    width: 1252px;
    height: 335px;
  }
  
  
  html, body {
    height: 100%;
    margin: 0;
  }
  
  
  .container * {
    border: 1px solid red;
    position: relative;
  }
  
  .container *:after {
    content:attr(class);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: grid;
    align-items: center;
    justify-content: center;
  }
  
 

  @media (min-width: 575.98px) { 
    .container { grid-template-columns: repeat(1, 1fr); }

   }

@media (min-width: 767.98px) { 
    .container { grid-template-columns: repeat(2, 1fr); }

 }

@media (min-width: 991.98px) { 
    .container { grid-template-columns: repeat(2, 1fr); }

 }

@media (min-width: 1199.98px) { 
    .container { grid-template-columns: repeat(3, 1fr); }

 }

@media (min-width: 1399.98px) { 
    .container { grid-template-columns: repeat(4, 1fr); }

 }
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0>
    <title>This is an example</title>
    <link rel="stylesheet" type="text/css" href="/dashboard.css"> 
</head>
<body>
    
      <section class="content">
        <div class="container">
          <div class="A"></div>
          <div class="B"></div>
          <div class="C"></div>
          <div class="D"></div>
          <div class="E"></div>
          <div class="F"></div>
          <div class="G"></div>
          <div class="H"></div>
          <div class="I"></div>
        </div>
      </section>
</body>
</html>

I have attempted to use col-sm-3, col-md-3, col-lg-3, col-xl-3 in the HTML, but it has not produced the desired outcome;

Answer №1

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .container {
            display: grid;
            grid-template-columns: 1fr 1fr 1fr 2fr;
            grid-auto-rows: 100px;
            gap: 5px;
            width: 100%;
            height: 100%;
        }

        html,
        body {
            height: 100%;
            margin: 0;
        }


        .container * {
            border: 1px solid red;
        }
        
        @media (max-width:1200px) {
            .container {
                grid-template-columns: 1fr 1fr 1fr;
            }
        }

        @media (max-width:1000px) {
            .container {
                grid-template-columns: 1fr 1fr ;
            }
        }

        @media (max-width:600px) {
            .container {
                grid-template-columns: 1fr;
            }
        }
    </style>
</head>

<body>
    <section class="content">
        <div class="container">
            <div class="A"></div>
            <div class="B"></div>
            <div class="C"></div>
            <div class="D"></div>
            <div class="E"></div>
            <div class="F"></div>
            <div class="G"></div>
            <div class="H"></div>
            <div class="I"></div>
        </div>
    </section>
</body>

</html>

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

Adjusting Bootstrap 4 Modal Transparency

Currently using Bootstrap 4 Beta and looking to darken the background when a Modal is displayed. I stumbled upon a solution suggesting the addition of a CSS class. .modal-backdrop.in { opacity: 0.5 !important; position: fixed; } The advice was no ...

Retrieving data from an HTML Table using Javascript

I am in the process of designing a dynamic web form that populates from a stored procedure. The form consists of a table with a dropdown list, a text box, and a label. While I can successfully retrieve data from the dropdown and text box, I am facing diffi ...

How to optimize form fields in Bootstrap by utilizing the size/maxlength attributes in HTML inputs

When I attempted to utilize html5's form size/maxlength with bootstrap, I encountered an intriguing issue. The .form-control class in bootstrap overrides the size, but if removed, the input loses its styling. Check out the code pen here: http://code ...

How to Alter Button Color upon Click in React with Bootstrap?

I'm working on implementing a thumbs up and thumbs down feature similar to Reddit's upvote and downvote system. The goal is to change the color of the object to green when the thumbs up is clicked and to red when the thumbs down is clicked. How ...

Preserve marked checkboxes upon page refresh

So I created a search engine with a filter using checkboxes in a form. The filter function is working fine when I submit the form (I'm using Flask for this). However, once the results are displayed, the checkboxes that were used as filters become unch ...

How can I use jQuery to create a new div element if it is not already present

I am familiar with how to add a class if it does not already exist, for example: $("ul:not([class~='bbox'])").addClass("bbox"); Alternatively, if(!$("ul").hasClass("class-name")){ $("ul").addClass("bbox"); } However, I am unsure how to c ...

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 ...

Why is my bootstrap-enhanced website appearing unattractive on MSIE 8?

Check out my website at My website displays perfectly in browsers like Firefox, Chrome, Opera, and the Android Browser. However, when I viewed it on Internet Explorer 8 at my parent's house, it looked all messed up. How can I improve the compatibilit ...

What is the process for transferring a folder to public storage in Laravel?

I've been attempting to upload and save a folder (which contains several files) into my local directory, but I'm encountering difficulties. Below is the input form I have: <input type="file" name="folder" id="folder&q ...

Preloaded background images are loaded twice

I have a background image that I am preloading and caching, but my code is not reading it from the cache. It keeps loading the image as if it is not cached. Even though I have 8 images in the "imgSrcArray," I have simplified this example by hard coding jus ...

Vintage webpage utilizing Bootstrap 3.3.4

I've been working on updating my old website that was built with Bootstrap 3.3.4 a few years ago. Recently, I made some minor changes to the content and everything was working fine just last week. However, when I checked the website today using XAMPP, ...

Issues with CSS causing image resizing problems on Chrome, looking for solutions

On my website, I have favicons from various external domains. However, there seems to be an issue with resizing them when they are not 16px in size. Sometimes only the top or bottom half of the image is displayed, but upon refreshing the page, the entire i ...

A guide on using JavaScript to obtain the original calculation for a specific equation once a checkbox has been unchecked

I am facing a scenario where I have two input fields. One should display the value of Quantity, and the other should display the value of Price. The first input, which is for quantity and of type number, has the disabled attribute. However, upon checking a ...

Web browsers are displaying code rather than the page itself

I recently hosted a .Net application on my Local IIS Server. Unfortunately, I neglected to handle error cases in MVC, opting instead to utilize the IIS .NET Error for page redirection to a specific page. When errors occur, the ASP.Net error page shows up ...

Switch the style of a set of thumbnail images when clicked

I am working with a set of thumbnails where one has an "p7_current" class applied, giving it a border, while the rest have an "p7_inactive" class removing the border. My goal is to have the last clicked thumbnail in a group of 6 to have the "p7_current" c ...

How to Adjust Overlapping Text in CSS?

Currently, I am facing an issue with an element overlapping in my CSS file. On a regular browser, one line of text appears fine but on mobile devices, it overlaps into two lines. This problem is specifically for the mobile version of the website, particula ...

Tips for altering the label color of an md-input-container after text has been entered

Is there a way to dynamically change the color of an md-input-container label after certain input is added? The default grey color gives the impression that the field is disabled. I specifically want to modify the color of the label "Description" when the ...

What is the best way to manage the appearance of multiple elements in React simultaneously?

I have a fun little game that I've been working on. Check it out - here In my game, when you hover over a square, it turns blue. If you hover over it again, it turns white. I achieve this by applying styles to the event target on hover. const handleM ...

animation for closing the hamburger menu

Having trouble creating a hamburger menu animation. I've set up two divs - one for the basic horizontal lines and one for the X icon. Using jQuery, I can hide and show them (clicking on the lines hides them and shows the X). But now I want to animate ...

Customize the Width of DropDown List Items with Razor

I'm having trouble adjusting the width of items in a DropDownList. I want the width of the DropDown items to be different from the DropDown itself. Can anyone assist me with this? <div class="col-md-3"> @f.FormGroup().DropDownList("IdTipoAc ...