Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CSS Grid Subgrid
#1
Description:

CSS Grid's subgrid value allows you to create nested grids that inherit the column and row sizes from the parent grid.

Example:

<!DOCTYPE html>
<html>
<head>
  <title>CSS Grid Subgrid Example</title>
  <style>
    .grid-container {
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      grid-template-rows: repeat(2, 150px);
      grid-gap: 10px;
    }
    .grid-item {
      border: 1px solid black;
      padding: 10px;
    }
    .nested-grid {
      display: grid;
      grid-template-columns: subgrid;
      grid-gap: 5px;
    }
    .nested-item {
      background-color: lightblue;
      padding: 5px;
    }
  </style>
</head>
<body>
  <div class="grid-container">
    <div class="grid-item">
      <div class="nested-grid">
        <div class="nested-item">A</div>
        <div class="nested-item">B</div>
      </div>
    </div>
    <div class="grid-item">
      <div class="nested-grid">
        <div class="nested-item">C</div>
        <div class="nested-item">D</div>
      </div>
    </div>
  </div>
</body>
</html>

Explanation:

In this example, the .grid-container creates a 2x2 grid layout. Each .grid-item contains a .nested-grid, which uses display: grid and grid-template-columns: subgrid to inherit the column size from the parent grid. This way, the nested grids automatically align with the parent's column sizes, creating a consistent layout.
Also follow me on Youtube for videos about video games:
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  CSS Grid Masonry Layout Qomplainerz 0 664 07-26-2023, 07:54 PM
Last Post: Qomplainerz
  CSS Custom Scrollbar Styles (Webkit and Firefox) Qomplainerz 0 458 07-26-2023, 07:52 PM
Last Post: Qomplainerz
  CSS Box Decoration Break Qomplainerz 0 406 07-26-2023, 07:49 PM
Last Post: Qomplainerz
  CSS Conic Gradients for Circular Progress Bar Qomplainerz 0 385 07-26-2023, 07:48 PM
Last Post: Qomplainerz
  CSS Variable Fonts Animation Qomplainerz 0 392 07-26-2023, 07:44 PM
Last Post: Qomplainerz
  CSS Scrollbar Styling Qomplainerz 0 399 07-26-2023, 07:43 PM
Last Post: Qomplainerz
  CSS Grid Auto-fit and Minmax Qomplainerz 0 375 07-26-2023, 07:41 PM
Last Post: Qomplainerz
  CSS clip path Qomplainerz 0 405 07-26-2023, 07:38 PM
Last Post: Qomplainerz
  CSS Feature Queries Qomplainerz 0 356 07-26-2023, 07:05 PM
Last Post: Qomplainerz
  CSS Custom properties (Variables) Qomplainerz 0 298 07-26-2023, 07:04 PM
Last Post: Qomplainerz

Forum Jump:


Users browsing this thread: 4 Guest(s)