我想在網格項目內部居中對齊內容,水平居中但垂直不居中。在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>
這是你需要做的: