Center align grid cell content
P粉060528326
P粉060528326 2023-09-15 10:34:15
0
1
661

I want to center align content inside a grid item, centered horizontally but not vertically. Check it out on JSfiddle: http://jsfiddle.net/6zs8ydhf/

.container {
  display: grid;
  grid-template-columns: 200px auto;
  grid-template-rows: 400px 200px;
}

.item {
  border: 1px solid #111;
}

.item2 h1 {
  display: flex;
  align-items: center;
  justify-content: center;
}
<div class="container">
  <div class="item item1">
    <h1>1</h1>
  </div>
  <div class="item item2">
    <h1>2 应该居中</h1>
  </div>
  <div class="item item3">
    <h1>3</h1>
  </div>
</div>

P粉060528326
P粉060528326

reply all(1)
P粉071559609

Here's what you need to do:

.item {
  border: 1px solid #111;
   display: flex;
  align-items: center;
  justify-content: center;
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template