Centering in CSS Grid

后端 未结 7 862
半阙折子戏
半阙折子戏 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

        <div class="container">
      <!--everything on the page-->
    
      <div class="left_bg">
        <!--left background color of the page-->
        <div class="text">
          <!--left side text content-->
          <p>Review my stuff</p>
        </div>
      </div>
    
      <div class="right_bg">
        <!--right background color of the page-->
        <div class="text">
          <!--right side text content-->
          <p>Hire me!</p>
        </div>
      </div>
    </div>
    
    0 讨论(0)
提交回复
热议问题