본문 바로가기

css

12장 예제- 자동으로 칼럼 개수 조절하기

<!DOCTYPE html>
<html lang="ko">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>자동으로 칼럼 개수 조절하기 </title>
  <style>
    #wrapper1 {
      display:grid;
      grid-template-columns:repeat(auto-fit, minmax(200px, 1fr));
      margin-bottom:20px;
    }

    #wrapper2{
      display:grid;
      grid-template-columns:repeat(auto-fill,minmax(200px, 1fr));
    }

    h1{
      font-size:24px;
    }

    .items {
      padding:15px;
      background-color:#eee;
    }
    .items:nth-child(odd){
      background-color:#bbb;
    }
   
  </style>
</head>
<body>
  <h1>auto-fit일 때</h1>
    <div id="wrapper1">            
      <div class="items">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Soluta nesciunt magni voluptatem.</div>
      <div class="items">Lorem ipsum dolor sit amet consectetur adipisicing elit.</div>
      <div class="items">Lorem ipsum dolor, sit amet consectetur adipisicing elit. Eius nulla corrupti porro!</div>
      <div class="items">Lorem ipsum dolor sit.</div>
      <div class="items">Lorem ipsum dolor sit amet consectetur adipisicing elit. Accusantium, quos!</div>
      <div class="items">Lorem, ipsum dolor sit amet consectetur adipisicing elit. Porro odit quam sit.</div>
    </div>

    <h1>auto-fill일 때</h1>
    <div id="wrapper2">            
      <div class="items">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Soluta nesciunt magni voluptatem.</div>
      <div class="items">Lorem ipsum dolor sit amet consectetur adipisicing elit.</div>
      <div class="items">Lorem ipsum dolor, sit amet consectetur adipisicing elit. Eius nulla corrupti porro!</div>
      <div class="items">Lorem ipsum dolor sit.</div>
      <div class="items">Lorem ipsum dolor sit amet consectetur adipisicing elit. Accusantium, quos!</div>
      <div class="items">Lorem, ipsum dolor sit amet consectetur adipisicing elit. Porro odit quam sit.</div>
    </div>
</body>
</html>