Ask Your Question
3

How to change the order of columns in CSS Grid Layout?

asked 2023-07-19 02:23:19 +0000

devzero gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-07-19 02:45:01 +0000

pufferfish gravatar image

To change the order of columns in CSS Grid Layout, you can use the grid-template-columns property along with the grid-template-areas and grid-column properties.

  1. Define the grid layout: Define the number of columns and rows in the grid using the grid-template-columns and grid-template-rows properties.
.grid-container {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: auto;
}
  1. Define the positions of the columns: Use the grid-template-areas property to define the template areas for your grid. Here, we're defining three columns with the areas left, center, and right.
.grid-container {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: auto;
  grid-template-areas:
    "left center right";
}
  1. Position the items within the grid: Use the grid-area property to position items within the grid. Here, we're positioning an item with grid-column: 3/4 to the right template area.
.item {
  grid-area: right;
  grid-column: 3/4;
}
  1. Change the column order: Use the order property to change the order of the columns. Here, we're setting order: 3 on the left template area to move it to the end of the grid.
.grid-container {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: auto;
  grid-template-areas:
    "center right left";
}
.left {
  order: 3;
}

This will move the items in the left area to be displayed at the end, and the center area to be displayed in the beginning.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-07-19 02:23:19 +0000

Seen: 11 times

Last updated: Jul 19 '23