Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Indent in CSS Grid

I have a header with 4 buttons, I divide it into 6 columns and I want to leave the first and the last empty, and place the buttons in the center.

.test {
  display: grid;
  grid-template-columns: repeat(6, 1fr);

  align-items: center;
  justify-content: center;
}

However, if I use grid-column-start: 2, the buttons are rearranged down.

like image 864
Michael George Avatar asked Oct 15 '25 04:10

Michael George


1 Answers

Use grid-column-start: 2 only on the first button using button:first-child. You have the issue as you are setting grid-column-start on all buttons - see demo below:

.test {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
}

.test button:first-child {
  grid-column-start: 2;
}
<div class="test">
  <button>1</button>
  <button>2</button>
  <button>3</button>
  <button>4</button>
</div>
like image 169
kukkuz Avatar answered Oct 17 '25 18:10

kukkuz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!