<img>
, <video>
and <iframe>
| Grid@charset "utf-8"
/* All Device */
/* Mobile Device */
@media all and (min-width: 768px){
/* 사용자 해상도가 768px 이상일 때 실행됨 */
}
img{
max-width: 100%;
height: auto;
}
• 용량으로 인한 성능, 속도 고려 필요
• Mobile Responsive Web test site: Troy - Responsive web tester
• 현재 기기의 Pixel Ratio 알 수 있는 사이트: myDevice.io
• 다양한 Image Format 대응
• 해결
<img>
의 srcset, sizes 속성<picture>
해상도 따라 조절하는 신규 요소 : <picture>
모를 때를 대비한 fallback image 있어야함.rwd-container{
width: 50%;
box-sizing: border-box;
border: 10px solid #000;
}
.rwd-container img, .rwd-container video{
width: 100%;
height: auto;
}
<img>
가 parent container의 width가 줄어들 때마다 같이 줄어든다.<video>
도 가능. 그러나 모두 크기 조절을 위해 wrapping해야한다.<iframe>
을 반응형으로 만들기<iframe>
삽입
<div class="rwd-iframe">
<iframe src="https://www.youtube.com/embed/2S24-y0Ij3Y?controls=0" allowfullscreen></iframe>
</div>
.rwd-iframe{
border: 10px solid #00f;
width: 80%;
}
.rwd-iframe iframe{
width: 100%;
height: auto;
}
<img>
나 <video>
처럼 하면 안 먹음<iframe>
은 wrapping <div>
2개 필요함
비율별 module화
.rwd-iframe{
position: relative;
padding-top: calc(9 / 16 * 100%);
background: pink;
width: 100%;
}
.rwd-3-4{
padding-top: calc(3 / 4 * 100%);
}
.rwd-9-16{
padding-top: calc(9 / 16 * 100%);
}
<div class="rwd-container">
<div class="rwd-iframe rwd-9-16">
<iframe src="https://www.youtube.com/embed/2S24-y0Ij3Y?controls=0" allowfullscreen></iframe>
</div>
</div>
<div class="rwd-container">
<div class="rwd-iframe rwd-3-4">
<iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d2974.021471174445!2d127.05441626516713!3d37.54323347980236!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x357ca49534790c57%3A0xc115101cbaecb40e!2z7JWE7YGs67C466as7ISc67mE7Iqk!5e1!3m2!1sko!2skr!4v1555310320240!5m2!1sko!2skr" allowfullscreen></iframe>
</div>
</div>
.container{
display: grid;
}
.container{
display: grid;
grid-template-columns: 50% 50%;
grid-template-rows: 50% 50%;
}
.container{
background: yellow;
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: 100px 100px;
}
.items4{
background: lime;
grid-column-start: 2;
grid-column-end: 3;
grid-row-start: 1;
grid-row-end: 2;
}
단축표기법
.items4{
background: lime;
/* start / end */
grid-column: 2 / 3;
grid-row: 1 / 2;
}
.items2{
background: orange;
grid-column: 1 / 4;
grid-row: 2 / 3;
}
.items2{
background: orange;
/* row-start / column-start / row-end / column-end */
grid-area: 2 / 1 / 3 / 4;
}
.container{
background: yellow;
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: 100px 100px;
grid-template-areas: "item2 . item1"
"item4 item4 item3"
}
.container{
background: yellow;
display: grid;
grid-template-columns: repeat(12, 65px);
grid-column-gap: 20px;
}
: repeat(반복 횟수, 크기) method 사용
.container{
max-width: 1000px;
margin: 0 auto;
background: silver;
display: grid;
grid-template-columns: repeat(12, 65px);
/* grid-template-rows: ; */
grid-column-gap: 20px;
}
.header{
background: pink;
grid-area: 1 / 1 / 2 / 13;
}
.navigation{
background: skyblue;
grid-area: 2 / 1 / 3 / 13;
}
.book{
background: lime;
grid-area: 3 / 1 / 4 / 5;
}
.news{
background: orange;
grid-area: 3 / 5 / 4 / 13;
}
.board{
background: blanchedalmond;
grid-area: 4 / 1 / 5 / 5;
}
.favorite{
background: gold;
grid-area: 4 / 10 / 5 / 13;
}
.twitter{
background: brown;
grid-area: 4 / 5 / 5 / 10;
}
.footer{
background: teal;
grid-area: 5 / 1 / 6 / 13;
}
Grid area 잡기 : Mobile Device
/* Mobile Device */
@media all and (max-width: 999px){
.container{
display: grid;
grid-template-columns: repeat(4, 1fr);
padding: 0 20px;
}
}
/* Mobile Device */
@media all and (max-width: 999px){
.container{
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-column-gap: 20px;
padding: 0 20px;
grid-template-areas: "header header header header"
"nav nav nav nav"
"book book news news"
"board board favorite favorite"
"twitter twitter twitter twitter"
"footer footer footer footer"
}
.header{
background: yellow;
grid-area: header;
}
.navigation{
background: pink;
grid-area: nav;
}
.book{
background: skyblue;
grid-area: book;
}
.news{
background: lime;
grid-area: news;
}
.board{
background: purple;
grid-area: board;
}
.favorite{
background: orange;
grid-area: favorite;
}
.twitter{
background: aqua;
grid-area: twitter;
}
.footer{
background: hotpink;
grid-area: footer;
}
}