简体   繁体   中英

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.

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> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM