CSS

๐ŸŽจ CSS 6 | ๊ทธ๋ฆฌ๋“œ(with ๋“œ๋ฆผ์ฝ”๋“œ by ์•จ๋ฆฌ) 2ํƒ„

grasinnong 2022. 9. 9. 16:38

 

 

 

 

 

Step 4  :  grid ์ž์‹์—๊ฒŒ ์ค„ ์ˆ˜ ์žˆ๋Š” ์†์„ฑ๋“ค ( grid cell )

 

Grid Line

 

 

 

 

 -grid-column-start   ,    grid-column-end

 

column์„ ๊ธฐ์ค€์œผ๋กœ ๋ช‡ ๋ฒˆ์งธ ์ค„๋ถ€ํ„ฐ ๋ช‡ ๋ฒˆ์งธ ์ค„๊นŒ์ง€ ์ฐจ์ง€ํ•  ์ง€ ์ •์˜ 

.item2{
      grid-column-start : 2;
      grid-column-end : 4;
}

 

 

 

 

 -grid-row-start   ,    grid-row-end

 

row๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋ช‡ ๋ฒˆ์งธ ์ค„๋ถ€ํ„ฐ ๋ช‡ ๋ฒˆ์งธ ์ค„๊นŒ์ง€ ์ฐจ์ง€ํ•  ์ง€ ์ •์˜ 

.item2{
      grid-column-start : 2;
      grid-column-end : 4;
      grid-row-start : 1;
      grid-row-end : 3;
}

 

 

 

 

๋‹จ์ถ•ํ˜•

.item2{
      grid-column : 2 / 4;
      grid-row : 1 / 3;
 }

 

.item2{
      grid-column : 2 / span 2; /*์ด 2๊ฐœ์˜ cell์„ ์ฐจ์ง€ํ•จ*/
      grid-row : 1 / 3;
 }

 

 

 

 

 

 

 

 

Step 5  :  grid-areas

 

index.html

<body>
  <section class="container">
    <img src="https://images.unsplash.com/photo-1662581872342-3f8e0145668f?ixlib=rb-1.2.1&ixid=MnwxMjA3fDF8MHxlZGl0b3JpYWwtZmVlZHwxfHx8ZW58MHx8fHw%3D&auto=format&fit=crop&w=500&q=60" alt="img" class="image image1">
    <img src="https://images.unsplash.com/photo-1662705286250-046f3f745ec7?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHw0fHx8ZW58MHx8fHw%3D&auto=format&fit=crop&w=500&q=60" alt="img" class="image image2">
    <img src="https://images.unsplash.com/photo-1662622194548-f50b20179287?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHwxNXx8fGVufDB8fHx8&auto=format&fit=crop&w=500&q=60" alt="img" class="image image3">
    <img src="https://images.unsplash.com/photo-1662556224725-48a9d346ffca?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHwxN3x8fGVufDB8fHx8&auto=format&fit=crop&w=500&q=60" alt="img" class="image image4">
    <img src="https://images.unsplash.com/photo-1662618113675-c7aed7142ccf?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHwyMHx8fGVufDB8fHx8&auto=format&fit=crop&w=500&q=60" alt="img" class="image image5">
    <img src="https://images.unsplash.com/photo-1662668862763-dc613ee191ab?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHwyMnx8fGVufDB8fHx8&auto=format&fit=crop&w=500&q=60" alt="img" class="image image6">
    <img src="https://images.unsplash.com/photo-1662555320245-0c113fe1b87c?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHwyNnx8fGVufDB8fHx8&auto=format&fit=crop&w=500&q=60" alt="img" class="image image7">
  </section>
</body>

 

styles.css

*{
      margin : 0;
      padding : 0;
      box-sizing : border-box;
    }
    body{
      width : 100vw;
      height : 100vh;
      padding : 5rem;
      background-color : black;
    }
    .container{
      display : grid;
      grid-template-columns: repeat(3, 1fr);
      grid-auto-rows : 150px;
      grid-gap : 1rem;
    }
    .container img{
      width : 100%;
      height : 100%;
      object-fit : cover;
    }

 

 

 

 

 

 

 -grid-template-areas (container)

 

๊ฐ ์…€์˜ ์ด๋ฆ„ ์ง€์ •ํ•ด์ฃผ๊ธฐ

.container{
      display : grid;
      grid-template-columns: repeat(3, 1fr);
      grid-auto-rows : 150px;
      grid-gap : 1rem;
      grid-template-areas :
        "a a a"
        "b c c"
        "b d g"
        "e f g"
    }

 

 

 

 -grid-areas (grid cell)

 

๊ฐ grid cell์—๊ฒŒ ๊ทธ๋ฆฌ๋“œ ์˜์—ญ ์•Œ๋ ค์ฃผ๊ธฐ

 

.image1{
      grid-area : a;
    }
    .image2{
      grid-area : b;
    }
    .image3{
      grid-area : e;
    }
    .image4{
      grid-area : c;
    }
    .image5{
      grid-area : d;
    }
    .image6{
      grid-area : f;
    }
    .image7{
      grid-area : g;
    }

 

 

 

 

 

 

 

 

 

์ถ”๊ฐ€ : grid ๋ฅผ ์ ์šฉํ–ˆ์„ ๋•Œ container ์˜ width ๋ฅผ ๋„˜์–ด์„ ๋‹ค๋ฉด

 

index.html

<body>
  <div class="container">
    <article>
      <img src="./img/aboutmain.jpg" alt="img">
      <p>
        ์ฒซ ์‹ฑ๊ธ€ [๋‚˜์˜ ๊ทธ๋Š˜]๋กœ ๋งŽ์€ ๊ด€์‹ฌ์„ ๋ฐ›์œผ๋ฉฐ ๋ฐ๋ท”ํ•œ ์œค์ง€์˜์€ ์ดํ›„ EP [Blue Bird]๋กœ ํ˜ธํ‰์„ ์ด์–ด๊ฐ€๋ฉฐ ๋งŽ์€ ๋ฆฌ์Šค๋„ˆ๋“ค์˜ ์ƒˆ๋ฒฝ ๊ฐ์„ฑ์„ ์ฑ„์šฐ๋Š” ๋ฎค์ง€์…˜์œผ๋กœ ์ž๋ฆฌ๋งค๊น€ํ–ˆ๋‹ค
      </p>
    </article>
    <aside>
      <ul class="contents">
        <li><img src="./img/album1.png" alt="album_img"></li>
        <li><img src="./img/album2.jpg" alt="album_img"></li>
        <li><img src="./img/album3.jpg" alt="album_img"></li>
        <li><img src="./img/album4.png" alt="album_img"></li>
        <li><img src="./img/album5.jpg" alt="album_img"></li>
        <li><img src="./img/album6.jpg" alt="album_img"></li>
      </ul>
    </aside>
  </div>
</body>

 

styles.css

.container{
      width : 1140px;
      margin : auto;
      display : grid;
      grid-template-columns: 2fr 1fr;
}

 

 

 

 

ํ™”๋ฉด์ฒ˜๋Ÿผ width 1140์„ ๋„˜์Œ. 

 

img max-width ์ง€์ •ํ•ด์ฃผ๊ธฐ 

img{
  max-width : 100%;
}

 

 

 

 

 

 

 

 

 

 

 

 

Preventing a Grid Blowout | CSS-Tricks

Say you have a very simple CSS grid layout with one column fixed at 300px and another taking up the rest of the space at 1fr.

css-tricks.com

 

A Complete Guide to Grid | CSS-Tricks

Our comprehensive guide to CSS grid, focusing on all the settings both for the grid parent container and the grid child elements.

css-tricks.com