Korean_hamster
지현의 개발자 성장과정
Korean_hamster
전체 방문자
오늘
어제
  • 분류 전체보기 (122)
    • Front-End Developer (79)
      • Project (12)
      • HTML (8)
      • CSS (17)
      • Computer Science (9)
      • JavaScript (20)
      • React (13)
    • 이런저런 생각 (7)
    • 주간 성장회고 (24)
    • English (0)
    • 리뷰 (2)
    • Books (5)

블로그 메뉴

  • 방명록

공지사항

인기 글

태그

  • js
  • 라우터
  • 반응형웹
  • 면접관님
  • sass
  • 비전공개발자
  • HTML
  • CSS
  • CS
  • 프론트앤드
  • 멋사
  • 비전공자개발자
  • 깃
  • 깃헙
  • 리액트
  • fetch
  • flex
  • 멋쟁이사자처럼
  • 프론트앤드스쿨
  • AtomicHabits

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
Korean_hamster

지현의 개발자 성장과정

srcset attribute를 이용해서 반응형 이미지 만들기
Front-End Developer/HTML

srcset attribute를 이용해서 반응형 이미지 만들기

2022. 4. 2. 12:32

무엇을? 

CSS media 쿼리가 아닌 HTML만을 이용하여 반응형 이미지를 만들어 보고 싶다.

 

  • 일단 부모elements로 picture태그를 사용해준다.
  • 그 밑에 source 태그를 사용하고, 그 안의 attrubute로 srcset으로 사진파일의 이름, media attribut로 min-width를 지정해준다.

 

    <picture>
      <source srcset="과카몰리_600.JPG" media="min-width:960px" />
      <source srcset="과카몰리_400.JPG" media="min-width:620px" />
      <img src="과카몰리_200.JPG" alt="" />
    </picture>

 

min-width는 최소 넓이로, 960px로 설정했다면 최소 넓이가 960px에 도달할 때 까지 srcset에 지정해준 사진을 사용해. 라는 뜻

 

 

 

  • 화면 넓이가 960px에 도달할 때 까지는 > 과카몰리_600.JPG 사진이 나온다. 

 

 


  • 화면을 줄여 넓이가 620px에 닿을 때 까지는 > 과카몰리_400.JPG 사진이 나온다.

 


  • 620보다 더 작아지면 > 기본 이미지로 설정해 둔 과카몰리_200.JPG 사진이 나온다.

 


브라우저 지원

 

IE는 지원하지 않는다. 

 

 

https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images

 

Responsive images - Learn web development | MDN

That's a wrap for responsive images — we hope you enjoyed playing with these new techniques. As a recap, there are two distinct problems we've been discussing here:

developer.mozilla.org

 

 The 800px picture is 128KB on disk, whereas the 480px version is only 63KB — a saving of 65KB. Now, imagine if this was a page that had many pictures on it. Using this technique could save mobile users a lot of bandwidth.

 

반응형 이미지의 장점 + 용량을 절약할 수 있다.

여기에 대해서 조금 더 깊게 공부해봐야겠다. 

저작자표시 (새창열림)

'Front-End Developer > HTML' 카테고리의 다른 글

5살에게 가르치는 안헷갈리는 HTML table  (8) 2022.04.05
점진적 향상기법이란? / 이미지 포맷의 종류  (0) 2022.04.02
Grouping Content  (0) 2022.04.02
What is HTML Living Standard?  (0) 2022.04.02
form 태그.  (0) 2022.04.01
    Korean_hamster
    Korean_hamster
    Keep pushing myself to the limits

    티스토리툴바