Centering in CSS Grid

后端 未结 7 866
半阙折子戏
半阙折子戏 2020-11-21 07:11

I\'m trying to create a simple page with CSS Grid.

What I\'m failing to do is center the text from the HTML to the respective grid cells.

I\'ve tried placing

7条回答
  •  独厮守ぢ
    2020-11-21 07:37

    Try using flex:

    Plunker demo : https://plnkr.co/edit/nk02ojKuXD2tAqZiWvf9

    /* Styles go here */
    
    html,
    body {
      margin: 0;
      padding: 0;
    }
    
    .container {
      display: grid;
      grid-template-columns: 1fr 1fr;
      grid-template-rows: 100vh;
      grid-gap: 0px 0px;
    }
    
    .left_bg {
      background-color: #3498db;
      grid-column: 1 / 1;
      grid-row: 1 / 1;
      z-index: 0;
      display: flex;
      justify-content: center;
      align-items: center;
    
    }
    
    .right_bg {
      background-color: #ecf0f1;
      grid-column: 2 / 2;
      grid_row: 1 / 1;
      z-index: 0;
      display: flex;
      justify-content: center;
      align-items: center;
    }
    
    .text {
      font-family: Raleway;
      font-size: large;
      text-align: center;
    }
    

    HTML

        

    Review my stuff

    Hire me!

提交回复
热议问题