๐จ CSS 6 | ๊ทธ๋ฆฌ๋(with ๋๋ฆผ์ฝ๋ by ์จ๋ฆฌ) 2ํ
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