Movatterモバイル変換


[0]ホーム

URL:


Menu
×
See More 
Sign In
+1 Get Certified Upgrade Teachers Spaces Bootcamps Get Certified Upgrade Teachers Spaces Bootcamps
   ❮     
     ❯   

W3.CSS Responsive Grid


Grid Layout

Agrid is a layout system forrows andcolumns.

The grid layout makes it easier to design complex and responsive web pages.

A grid consists of aparent grid element containing one or moregrid items.

1

2

3

4

5

6

7

8


Thew3-grid Class

Thew3-grid class creates a parent container for grid items.

The children of the grid container automatically become grid items.

Example

<div class="w3-grid"">
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <div>4</div>
</div>

Try it Yourself »

Example

<div class="w3-grid-padding"">
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <div>4</div>
</div>

Try it Yourself »

Note

w3-grid andw3-flex is new inW3.CSS 5.0.

w3-grid vs w3-flex

w3-grid is fortwo-dimensional layout, with rows AND columns.

w3-flex is forone-dimensional layout, with rows OR columns.


CSS Properties

Many standard CSS properties can be used for a grid container:

  • grid-template
  • grid-template-rows
  • grid-template-columns
  • grid-template-areas
  • gap
  • row-gap
  • column-gap
  • grid-column
  • grid-column-start
  • grid-column-end
  • grid-row
  • grid-row-start
  • grid-row-end
  • justify-content
  • align-content
  • grid-auto-rows
  • grid-auto-columns

Thegrid-template-columns Property

Thegrid-template-columns property specifies the number of columns in the grid and the widths of each column.

Values can beauto (automatic),fr(fractions),px (pixels),%(percentages) or any combination.

Examples

<div class="w3-grid">

Try it Yourself »

<div class="w3-grid">

Try it Yourself »

<div class="w3-grid">

Try it Yourself »

<div class="w3-grid">

Try it Yourself »

You can also use therepeat() function:

Examples

<div class="w3-grid">

Try it Yourself »

Track Repeat

Track repeat uses an integer to set the repeat count a size values to set track sizes.

repeat(4, 1fr)
repeat(4, [col-start] 250px [col-end])
repeat(4, [col-start] 60% [col-end])
repeat(4, [col-start] 1fr [col-end])
repeat(4, [col-start] min-content [col-end])
repeat(4, [col-start] max-content [col-end])
repeat(4, [col-start] auto [col-end])
repeat(4, [col-start] minmax(100px, 1fr) [col-end])
repeat(4, [col-start] fit-content(200px) [col-end])
repeat(4, 10px [col-start] 30% [col-middle] auto [col-end])
repeat(4, [col-start] min-content [col-middle] max-content [col-end])

Auto Repeat

Auto repeat uses auto-fill or auto-fit to set the repeat count a fixed size to set track sizes.

repeat(auto-fill, 250px)
repeat(auto-fit, 250px)
repeat(auto-fill, [col-start] 250px [col-end])
repeat(auto-fit, [col-start] 250px [col-end])
repeat(auto-fill, [col-start] minmax(100px, 1fr) [col-end])
repeat(auto-fill, 10px [col-start] 30% [col-middle] 400px [col-end])

Fixed Repeat

Fixed repeat uses an integer to set the repeat count and a fixed size to set track sizes.

repeat(4, 250px)
repeat(4, [col-start] 250px [col-end])
repeat(4, [col-start] 60% [col-end])
repeat(4, [col-start] minmax(100px, 1fr) [col-end])
repeat(4, [col-start] fit-content(200px) [col-end])
repeat(4, 10px [col-start] 30% [col-middle] 400px [col-end])


Thegrid-template-rows Property

Thegrid-template-rows property specifies the number of rows in the grid and the height of each row.

Values can beauto,px (pixels)or% (percentages).

Example

<div class="w3-grid">

Try it Yourself »


Thegrid-template Property

Thegrid-template property is a shorthand for grid-template-rows and grid-template-columns.

Example

<div class="w3-gridtemplate">

Try it Yourself »


Thegap Property

Thegap property sets the gap (spacing) between the rows and columns.

Example

<div class="w3-grid">
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <div>4</div>
</div>

Try it Yourself »


Thegrid-template-areas Property

Thegrid-template-areas property specifies areas within the grid layout.

Example

<div class="w3-grid"myArea myArea . . .">
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <div>4</div>
</div>

Try it Yourself »


Thecolumn-gap Property

Thecolumn-gap property sets the gap (spacing) between the columns.

Example

<div class="w3-grid">
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <div>4</div>
</div>

Try it Yourself »


Therow-gap Property

Therow-gap property sets the gap (spacing) between the rows.

Example

<div class="w3-grid">
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <div>4</div>
</div>

Try it Yourself »


Thegrid-column-start Property

Thegrid-column-start property specifies the column where to start an item.

Example

<div class="w3-grid">
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <div>4</div>
</div>

Try it Yourself »


Thegrid-column-end Property

Thegrid-column-start property specifies the column where to end an item.

Example

<div class="w3-grid">
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <div>4</div>
</div>

Try it Yourself »


Thegrid-column Property

Thegrid-column property specifies the column where to start and end a grid item.

Example

<div class="w3-grid">
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <div>4</div>
</div>

Try it Yourself »


Thegrid-row-start Property

Thegrid-row-start property specifies the row where to start a grid item.

Example

<div class="w3-grid">
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <div>4</div>
</div>

Try it Yourself »


Thegrid-row-end Property

Thegrid-row-end property specifies the row where to end a grid item.

Example

<div class="w3-grid">
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <div>4</div>
</div>

Try it Yourself »


Thegrid-row Property

Thegrid-row property specifies the row where to start and end a grid item.

Example

<div class="w3-grid">
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <div>4</div>
</div>

Try it Yourself »


Thejustify-content Property

Thejustify-content property aligns the items in the grid.

Examples

<div class="w3-grid">

Try it Yourself »

<div class="w3-grid">

Try it Yourself »

<div class="w3-grid">

Try it Yourself »

<div class="w3-grid">

Try it Yourself »

<div class="w3-grid">

Try it Yourself »

<div class="w3-grid">

Try it Yourself »


Thealign-content Property

Thealign-content property aligns the items vertically in the grid.

Examples

<div class="w3-grid">

Try it Yourself »

<div class="w3-grid">

Try it Yourself »

<div class="w3-grid">

Try it Yourself »

<div class="w3-grid">

Try it Yourself »

<div class="w3-grid">

Try it Yourself »

<div class="w3-grid">

Try it Yourself »


Thegrid-auto-rows Property

Thegrid-auto-rows property specifies a default row size.

Example

<div class="w3-grid">
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <div>4</div>
</div>

Try it Yourself »


Thegrid-auto-columns Property

Thegrid-auto-columns property specifies a default column size.

Example

<div class="w3-grid">
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <div>4</div>
</div>

Try it Yourself »

General CSS Properties

PropertyDescription
align-contentVertically aligns the whole grid inside the container (when total grid size is smaller than container)
align-itemsAligns content in a grid item along the column axis
align-selfAligns the content for a specific grid item along the column axis
displaySpecifies the display behavior (the type of rendering box) of an element
column-gapSpecifies the gap between the columns
gapA shorthand property for therow-gap and thecolumn-gap properties
gridA shorthand property for thegrid-template-rows, grid-template-columns, grid-template-areas, grid-auto-rows, grid-auto-columns, and thegrid-auto-flow properties
grid-areaEither specifies a name for the grid item, or this property is a shorthand property for thegrid-row-start,grid-column-start,grid-row-end, andgrid-column-end properties
grid-auto-columnsSpecifies a default column size
grid-auto-flowSpecifies how auto-placed items are inserted in the grid
grid-auto-rowsSpecifies a default row size
grid-columnA shorthand property for thegrid-column-start and thegrid-column-end properties
grid-column-endSpecifies where to end the grid item
grid-column-startSpecifies where to start the grid item
grid-rowA shorthand property for thegrid-row-start and thegrid-row-end properties
grid-row-endSpecifies where to end the grid item
grid-row-startSpecifies where to start the grid item
grid-templateA shorthand property for thegrid-template-rows,grid-template-columns andgrid-areas properties
grid-template-areasSpecifies how to display columns and rows, using named grid items
grid-template-columnsSpecifies the size of the columns, and how many columns in a grid layout
grid-template-rowsSpecifies the size of the rows in a grid layout
justify-contentHorizontally aligns the whole grid inside the container (when total grid size is smaller than container)
justify-selfAligns the content for a specific grid item along the row axis
place-selfA shorthand property for thealign-self and the justify-self properties
place-contentA shorthand property for thealign-content and the justify-content properties
row-gapSpecifies the gap between the grid rows

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning.
Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness
of all content. While using W3Schools, you agree to have read and accepted ourterms of use,cookies andprivacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved.W3Schools is Powered by W3.CSS.

-->
[8]ページ先頭

©2009-2026 Movatter.jp