<picture>
element<picture>
?
<picture>
문법
<img>
를 fallback으로 첨부해야한다. <picture>
는 <img>
tag가 없으면 인식되지 않는다!
img {display: block; margin: 0 auto;}
<picture>
<source media="(min-width: 650px)" srcset="images/kitten-stretching.png">
<source media="(min-width: 465px)" srcset="images/kitten-sitting.png">
<img src="images/kitten-curled.png" alt="a cute kitten">
</picture>
<img>
와 <source>
엘리먼트 모두에 적용됩니다.<img>
max-width: 100%; <style>
.rwd-wrapper{
width: 30%;
border: 5px solid blueviolet;
}
.rwd-wrapper img{
max-width: 100%;
height: auto;
}
</style>
</head>
<body>
<div class="rwd-wrapper">
<img src="images/image-src.png" alt="">
</div>
</body>
```
3. srcset 속성을 사용해서 Pixel density 설정
![0416](https://user-images.githubusercontent.com/48080762/56205794-bd0a5a80-6085-11e9-818e-61f08070d206.png)
```html
<div class="rwd-wrapper">
<img src="images/image-src.png" alt=""
srcset="images/image-1x.png 1x,
images/image-2x.png 2x,
images/image-3x.png 3x,
images/image-4x.png 4x">
</div>
<picture>
의 <source media="">
로 조건 줌
<picture>
<source media="(max-width: 650px)" srcset="images/small.jpg">
<source media="(min-width: 651px) and (max-width: 999px)" srcset="images/media.jpg">
<source media="(min-width: 1000px)" srcset="images/large.jpg">
<img class="rwd-img" src="images/normal.jpg" alt="">
</picture>
.rwd-bg{
width: 100%;
height: 0 !important;
padding-top: calc(3280 / 4928 * 100%);
background: url("images/light.jpg") no-repeat;
background-size: 100% 100%;
}
.wrapper{
width: 50%;
}
.rwd-bg{
width: 100%;
height: 0 !important;
padding-top: calc(3280 / 4928 * 100%);
background: url("images/light.jpg") no-repeat;
background-size: 100% 100%;
}
<div class="wrapper">
<div class="rwd-bg"></div>
</div>
CSS Trick Background-size 참고 사이트
@media all and (min-resolution: 192dpi){
.rwd-bg{
background-image: url("images/unsplash.jpg");
}
}