Skip to content

Latest commit

 

History

History
24 lines (18 loc) · 527 Bytes

File metadata and controls

24 lines (18 loc) · 527 Bytes

Collapsing a grid column

Just found out that grid-template-columns accepts auto as a value!

Which means that if you need a collapsable sidebar you can define it in the css as follows:

body {
  display: grid;
  grid-template-columns: auto 1fr;
}

.sidebar {
  width: 0;
  transition: all 1s;
}

.sidebar.open {
  width: 300px;
}

Now, as soon as the class open is added to the sidebar it will be 300px wide, and of course the other div, will take up the rest of the screen width because of the 1fr.