html , css

background 정리

고로케 2021. 5. 27.
반응형

* background 기본 세팅

* {
  box-sizing: border-box;   
  # border 사이즈를 안쪽 padding, margin 과 상관없이 고정해주는 옵션
  }
.background{
  height: 450px;
  background-image: url("~~~~");
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center center;
  }

 

background-image: url("그림 주소");

1. background-repeat

이미지를 반복시키는 속성 모음

/* 반복하지 않음 */
background-repeat: no-repeat;

/* 가로 방향으로만 반복 */
background-repeat: repeat-x;

/* 세로 방향으로만 반복 */
background-repeat: repeat-y;

/* 가로와 세로 모두 반복 */
background-repeat: repeat;

/* 반복할 수 있는 만큼 반복한 뒤, 남는 공간은 이미지 간의 여백으로 배분 */
background-repeat: space;

/* 반복할 수 있는 만큼 반복한 뒤, 남는 공간은 이미지 확대를 통해 배분 */
background-repeat: round;

 

2. background-size

배경 이미지의 사이즈 속성

/* 원래 이미지 사이즈대로 출력 */
background-size: auto;

/* 화면을 꽉 채우면서, 사진 비율을 유지 */
background-size: cover;

/* 가로, 세로 중 먼저 채워지는 쪽에 맞추어서 출력 */
background-size: contain;

/* 픽셀값 지정 (가로: 30px, 세로: 50px로 설정) */
background-size: 30px 50px;

/* 퍼센트값 지정 (가로: 부모 요소 width의 60%, 세로: 부모 요소 height의 70%로 설정) */
background-size: 60% 70%;

 

3. background-position

배경 이미지의 위치 or 확대 했을 때 확대 되는 위치 설정

/* 단어로 지정해주기 (가로: left, center, right, 세로: top, center, bottom) */
/* 아래와 같은 총 9개의 조합이 가능 */
background-position: left top;
background-position: left center;
background-position: left bottom;
background-position: right top;
background-position: right center;
background-position: right bottom;
background-position: center top;
background-position: center center;
background-position: center bottom;

/* 퍼센트로 지정해주기 (가로: 전체 width의 25% 지점, 세로: 전체 height의 75% 지점 ) */
background-position: 25% 75%;

/* 픽셀로 지정하기 (가로: 가장 왼쪽 가장자리에서부터 오른쪽으로 100px 이동한 지점, 세로: 가장 상단 가장자리에서 아래로 200px 이동한 지점) */
background-position: 100px 200px;

 

연습) 

 

반응형

'html , css' 카테고리의 다른 글

html,css 연습(1) border, margin, padding 식당  (0) 2021.05.28
[html] 기본 골격  (0) 2021.05.27
border 정리  (0) 2021.05.26
영역 크기 총 정리 width, hight, overflow 정리  (0) 2021.05.26
[css]Padding과 Margin 차이, 총정리  (0) 2021.05.25

댓글