【CSS】배경 이미지 설정
background-image


background-color 로 배경색은 설정할 수 있었지만, 그것만으로는 왠지 맛있지 않다・・・

그렇다면 배경 이미지를 넣어 보자

예.html
<div>
<p>海はいいねぇ</p>
</div>
예.css
div {
color: white;
width: 100%;
height: 500px;
background-image: url(https://www.pakutaso.com/shared/img/thumb/RED19515A006_TP_V.jpg);
}
하단에 background-image: 이미지 URL; 넣어 보았습니다

웹
↓

이미지의 왼쪽 상단에 문자와 사진이 포함되었습니다

문자로 작성한 대로
바다는 좋다 ~

···와 재미있는!
바다가 아닌 하늘 밖에 비치지 않는다! !

원인은 내가 높이를 height: 500px; 로 하고 있기 때문에 들어가지 않는 이미지는 잘라 버렸다고 생각합니다

그렇다고 높이를 바꾸고 싶지 않아

그런 때는・・・!


background-size: cover; 추가

예.css
div {
color: white;
width: 100%;
height: 500px;
background-image: url(https://www.pakutaso.com/shared/img/thumb/RED19515A006_TP_V.jpg);
background-size: cover;
}
웹
↓

표시되었습니다!


Reference
이 문제에 관하여(【CSS】배경 이미지 설정), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/mikimikiman/items/a23c9df4e39f3702c52d텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)