Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Grid Container in CSS

Grid Container in CSS

? CSS Grid Container

A Grid Container is any HTML element where you enable CSS Grid layout by setting display: grid or display: inline-grid. This container then defines a grid system to place and align its child elements (grid items) in rows and columns.


How to Create a Grid Container

.container {  display: grid; /* or inline-grid */}

Key Properties for Grid Container

PropertyDescriptionExample Values
grid-template-columnsDefines the number and size of columns100px 200px 100px, repeat(3, 1fr), auto
grid-template-rowsDefines the number and size of rows50px 100px, repeat(2, 200px)
grid-column-gap / column-gapSpace (gap) between columns10px, 1em
grid-row-gap / row-gapSpace (gap) between rows15px
gapShorthand for setting both row and column gaps20px 10px (row-gap 20px, column-gap 10px)
grid-auto-rowsSize of rows created implicitly (beyond defined rows)100px, minmax(100px, auto)
grid-auto-columnsSize of columns created implicitly150px
grid-auto-flowControls how auto-placed items are inserted (row, column, dense)row, column, row dense
justify-itemsAlign items horizontally inside their grid areastart, end, center, stretch
align-itemsAlign items vertically inside their grid areastart, end, center, stretch
justify-contentAlign the entire grid horizontally within the containerstart, end, center, space-between
align-contentAlign the entire grid vertically within the containerstart, end, center, space-around

Example: Simple 3-column Grid Container

.container {  display: grid;  grid-template-columns: repeat(3, 1fr);  gap: 20px; /* sets both row and column gaps */}
<div class="container">  <div>Item 1</div>  <div>Item 2</div>  <div>Item 3</div>  <div>Item 4</div></div>
  • This will create 3 equal-width columns.

  • Items automatically flow into rows.


Notes

  • Grid containers establish a new grid formatting context for their children.

  • Grid layout is two-dimensional: you control rows and columns simultaneously.

  • Use fr units to distribute available space proportionally.

  • Use auto to size columns/rows based on content.


If you want, I can help you create a custom grid layout or explain grid item placement!

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql