본문 바로가기
Reference/CSS

background-image 속성은 배경 이미지 경로 및 그라디언트를 설정합니다.

by @webstoryboy 2023. 1. 4.

background-image 속성은 배경 이미지 경로 및 그라디언트를 설정합니다.

Reference/CSS

background-image 속성은 배경 이미지 경로 및 그라디언트를 설정합니다.

by @webs 2023. 01. 03.

background-image

background-image 속성은 배경 이미지 경로 및 그라디언트를 설정합니다.

웹 문서에 이미지를 표현하는 방법은 두가지가 있습니다. img 태그와 background 속성을 이용하는 방법입니다. 원칙적으로 의미가 있는 이미지는 img 태그를 사용하고, 그렇지 않은 경우는 background 속성을 사용합니다. background 속성은 의미가 없는 이미지를 사용하기 위한 방법입니다. 배경이 장식용이거나 디자인 용도라면 background를 이용해서 많이 사용합니다. 여기에는 사이즈, 반복여부, 위치, 효과 등 다양한 속성을 사용할 수 있습니다.


특징 설명
기본값 background-image : none
적용 background
버전 CSS1
사용성 ★★★★★

정의(Definition)

  • background-image 속성은 배경 이미지 경로 및 그라디언트를 설정합니다.
  • background-image 속성은 다중 이미지를 익스플로러9 이상부터 지원됩니다.

관련된 속성(Related Properties)

  • background 속성은 배경 이미지의 속성을 일괄적으로 설정합니다.
  • background-image 속성은 배경 이미지 경로 및 그라디언트를 설정합니다.
  • background-position 속성은 배경 이미지의 위치를 설정합니다.
  • background-size 속성은 배경 이미지 사이즈를 설정합니다.
  • background-repeat 속성은 배경 이미지 반복 여부를 설정합니다.
  • background-origin 속성은 배경 이미지의 위치 기준점을 설정합니다.
  • background-clip 속성은 배경 이미지의 위치 기준점을 설정합니다.
  • background-attachment 속성은 배경 이미지의 고정 여부를 설정합니다.
  • background-color 속성은 배경 색을 설정합니다.
  • background-blend-mode 속성은 배경 이미지를 혼합했을 때의 상태를 설정합니다.

문법(Syntax)

background-image : none | url | gradient

/* 기본 속성 */
background-image : none;
background-image : url("../image.jpg");

/* 다중 이미지 설정 */
background-image : url("../image1.jpg"), url("../image2.jpg");

/* 그라디언트 설정 */
background-image : linear-gradient();
background-image : radial-gradient();
background-image : repeating-linear-gradient();
background-image : repeating-radial-gradient();

/* 전역 속성 */
background-image : inherit;   /* 상속 */
background-image : initial;   /* 초기화 */
background-image : revert;    /* 원래대로 돌리기 */
background-image : unset;     /* 설정 해제 */

속성(Property)

속성값 값(예) 설명
none background-image : none; 백그라운드 이미지를 설정하지 않습니다.
url background-image : url(../img.jpg); 백그라운드 이미지 경로를 설정합니다.
gradient background-image : radial-gradient(); 백그라운에 그라디언트를 설정합니다.

예제1(Sample)

백그라운드 이미지를 설정하는 예제입니다.

image01
image02
image03
image04
HTML
CSS
SCRIPT
<div id="bg-box">
    <div class="box"></div>
</div>
#bg-box .box {
    background-image: url(https://tistory1.daumcdn.net/tistory/783187/skin/images/bg1-min.jpg);
    background-repeat: repeat;
    background-position: center;
    background-size: 10%;
    height: 400px;
}
#bg-box.bg1 .box {
    background-image: url(https://tistory1.daumcdn.net/tistory/783187/skin/images/bg1-min.jpg);
}
#bg-box.bg2 .box {
    background-image: url(https://tistory1.daumcdn.net/tistory/783187/skin/images/bg2-min.jpg);
}
#bg-box.bg3 .box {
    background-image: url(https://tistory1.daumcdn.net/tistory/783187/skin/images/bg3-min.jpg);
}
#bg-box.bg4 .box {
    background-image: url(https://tistory1.daumcdn.net/tistory/783187/skin/images/bg4-min.jpg);
}
#bg-box.bg5 .box {
    background-image: url(https://tistory1.daumcdn.net/tistory/783187/skin/images/bg5-min.jpg);
}
#bg-box.bg6 .box {
    background-image: url(https://tistory1.daumcdn.net/tistory/783187/skin/images/bg6-min.jpg);
}
#bg-box.bg7 .box {
    background-image: url(https://tistory1.daumcdn.net/tistory/783187/skin/images/bg7-min.jpg);
}
#bg-box.bg8 .box {
    background-image: url(https://tistory1.daumcdn.net/tistory/783187/skin/images/bg8-min.jpg);
}
#bg-box.bg9 .box {
    background-image: url(https://tistory1.daumcdn.net/tistory/783187/skin/images/bg9-min.jpg);
}
#bg-box.bg10 .box {
    background-image: url(https://tistory1.daumcdn.net/tistory/783187/skin/images/bg10-min.jpg);
}
//Javascript none

예제2(Sample)

linear-gradient(top, right, bottom, left)를 적용한 예제입니다.

gradient01
gradient02
gradient03
gradient04
.gradient01 {background-image: linear-gradient(to top, #a18cd1, #fbc2eb);}
.gradient02 {background-image: linear-gradient(to right, #a18cd1, #fbc2eb);}
.gradient03 {background-image: linear-gradient(to bottom, #a18cd1, #fbc2eb);}
.gradient04 {background-image: linear-gradient(to left, #a18cd1, #fbc2eb);}

예제3(Sample)

linear-gradient를(각도) 적용한 예제입니다.

gradient05
gradient06
gradient07
gradient08
.gradient05 {background-image: linear-gradient(0deg, #84fab0, #249092);}
.gradient06 {background-image: linear-gradient(90deg, #84fab0, #249092);}
.gradient07 {background-image: linear-gradient(180deg, #84fab0, #249092);}
.gradient08 {background-image: linear-gradient(260deg, #84fab0, #249092);}

예제4(Sample)

linear-gradient를(색상 추가) 적용한 예제입니다.

gradient09
gradient10
gradient11
gradient12
gradient13
gradient14
gradient15
gradient16
.gradient09 {background-image: linear-gradient(140deg, #fa709a, #fee140);}
.gradient10 {background-image: linear-gradient(140deg, #fa709a, #fee140, #fa709a);}
.gradient11 {background-image: linear-gradient(140deg, #fa709a, #fee140, #fa709a, #30cfd0);}
.gradient12 {background-image: linear-gradient(140deg, #fa709a, #fee140, #fa709a, #30cfd0, #66a6ff);}
.gradient13 {background-image: linear-gradient(140deg, #fa709a, #fee140, #fa709a, #30cfd0, #66a6ff, #764ba2);}
.gradient14 {background-image: linear-gradient(140deg, #fa709a, #fee140, #fa709a, #30cfd0, #66a6ff, #764ba2, #009efd);}
.gradient15 {background-image: linear-gradient(140deg, #fa709a, #fee140, #fa709a, #30cfd0, #66a6ff, #764ba2, #009efd, #2575fc);}
.gradient16 {background-image: linear-gradient(140deg, #fa709a, #fee140, #fa709a, #30cfd0, #66a6ff, #764ba2, #009efd, #2575fc, #72afd3);}

예제5(Sample)

linear-gradient를(위치 변경) 적용한 예제입니다.

gradient17
gradient18
gradient19
gradient20
gradient21
gradient22
gradient23
gradient24
.gradient17 {background-image: linear-gradient(140deg, #f43b47 0%, #fa709a 20%, #453a94 100%);}
.gradient18 {background-image: linear-gradient(140deg, #f43b47 0%, #fa709a 30%, #453a94 100%);}
.gradient19 {background-image: linear-gradient(140deg, #f43b47 0%, #fa709a 40%, #453a94 100%);}
.gradient20 {background-image: linear-gradient(140deg, #f43b47 0%, #fa709a 50%, #453a94 100%);}
.gradient21 {background-image: linear-gradient(140deg, #f43b47 0%, #fa709a 60%, #453a94 100%);}
.gradient22 {background-image: linear-gradient(140deg, #f43b47 0%, #fa709a 70%, #453a94 100%);}
.gradient23 {background-image: linear-gradient(140deg, #f43b47 0%, #fa709a 80%, #453a94 100%);}
.gradient24 {background-image: linear-gradient(140deg, #f43b47 0%, #fa709a 90%, #453a94 100%);}

예제6(Sample)

linear-gradient(경계선)를 적용한 예제입니다.

gradient25
gradient26
gradient27
gradient28
gradient29
gradient30
gradient31
gradient32
.gradient25 {background-image: linear-gradient(0deg, #c471f5 50%, #fa71cd 50%);}
.gradient26 {background-image: linear-gradient(30deg, #c471f5 50%, #fa71cd 50%);}
.gradient27 {background-image: linear-gradient(60deg, #c471f5 50%, #fa71cd 50%);}
.gradient28 {background-image: linear-gradient(90deg, #c471f5 50%, #fa71cd 50%);}
.gradient29 {background-image: linear-gradient(120deg, #c471f5 50%, #fa71cd 50%);}
.gradient30 {background-image: linear-gradient(150deg, #c471f5 50%, #fa71cd 50%);}
.gradient31 {background-image: linear-gradient(180deg, #c471f5 50%, #fa71cd 50%);}
.gradient32 {background-image: linear-gradient(210deg, #c471f5 50%, #fa71cd 50%);}

예제7(Sample)

linear-gradient(fixed)를 적용한 예제입니다.

gradient33
gradient34
gradient35
gradient36
gradient37
gradient38
gradient39
gradient40
.gradient33 {background: linear-gradient(20deg, #fa709a, #fee140) fixed;}
.gradient34 {background: linear-gradient(20deg, #fa709a, #fee140) fixed;}
.gradient35 {background: linear-gradient(20deg, #fa709a, #fee140) fixed;}
.gradient36 {background: linear-gradient(20deg, #fa709a, #fee140) fixed;}
.gradient37 {background: linear-gradient(20deg, #fa709a, #fee140) fixed;}
.gradient38 {background: linear-gradient(20deg, #fa709a, #fee140) fixed;}
.gradient39 {background: linear-gradient(20deg, #fa709a, #fee140) fixed;}
.gradient40 {background: linear-gradient(20deg, #fa709a, #fee140) fixed;}

예제8(Sample)

radial-gradient(위치 변경)를 적용한 예제입니다.

gradient41
gradient42
gradient43
gradient44
gradient45
gradient46
gradient47
gradient48
.gradient41 {background: radial-gradient(#2a5298 0%, #209cff 20%, #68e0cf 100%);}
.gradient42 {background: radial-gradient(#2a5298 0%, #209cff 30%, #68e0cf 100%);}
.gradient43 {background: radial-gradient(#2a5298 0%, #209cff 40%, #68e0cf 100%);}
.gradient44 {background: radial-gradient(#2a5298 0%, #209cff 50%, #68e0cf 100%);}
.gradient45 {background: radial-gradient(#2a5298 0%, #209cff 60%, #68e0cf 100%);}
.gradient46 {background: radial-gradient(#2a5298 0%, #209cff 70%, #68e0cf 100%);}
.gradient47 {background: radial-gradient(#2a5298 0%, #209cff 80%, #68e0cf 100%);}
.gradient48 {background: radial-gradient(#2a5298 0%, #209cff 90%, #68e0cf 100%);}

예제9(Sample)

radial-gradient(방향)를 적용한 예제입니다.

gradient49
gradient50
gradient51
gradient52
gradient53
gradient54
gradient55
gradient56
.gradient49 {background: radial-gradient(ellipse farthest-corner at center top, #f8bfa4 0%, #f33b4e 100%);}
.gradient50 {background: radial-gradient(ellipse farthest-corner at left top, #f8bfa4 0%, #f33b4e 100%);}
.gradient51 {background: radial-gradient(ellipse farthest-corner at right top, #f8bfa4 0%, #f33b4e 100%);}
.gradient52 {background: radial-gradient(ellipse farthest-corner at bottom left, #f8bfa4 0%, #f33b4e 100%);}
.gradient53 {background: radial-gradient(ellipse farthest-corner at bottom center, #f8bfa4 0%, #f33b4e 100%);}
.gradient54 {background: radial-gradient(ellipse farthest-corner at center top, #f8bfa4 0%, #f33b4e 100%);}
.gradient55 {background: radial-gradient(ellipse farthest-corner at left top, #f8bfa4 0%, #f33b4e 100%);}
.gradient56 {background: radial-gradient(ellipse farthest-corner at right center, #f8bfa4 0%, #f33b4e 100%);}

예제10(Sample)

radial-gradient(색상 추가)를 적용한 예제입니다.

gradient57
gradient58
gradient59
gradient60
gradient61
gradient62
gradient63
gradient64
.gradient57 {background-image: radial-gradient(#e14fad, #f9d423);}
.gradient58 {background-image: radial-gradient(#e14fad, #f9d423, #f48fb1);}
.gradient59 {background-image: radial-gradient(#e14fad, #f9d423, #f48fb1, #ce93d8);}
.gradient60 {background-image: radial-gradient(#e14fad, #f9d423, #f48fb1, #ce93d8, #b39ddb);}
.gradient61 {background-image: radial-gradient(#e14fad, #f9d423, #f48fb1, #ce93d8, #b39ddb, #9fa8da);}
.gradient62 {background-image: radial-gradient(#e14fad, #f9d423, #f48fb1, #ce93d8, #b39ddb, #9fa8da, #80cbc4);}
.gradient63 {background-image: radial-gradient(#e14fad, #f9d423, #f48fb1, #ce93d8, #b39ddb, #9fa8da, #80cbc4, #80deea);}
.gradient64 {background-image: radial-gradient(#e14fad, #f9d423, #f48fb1, #ce93d8, #b39ddb, #9fa8da, #80cbc4, #80deea, #cddc39);}

예제11(Sample)

repeating-linear-gradient를 적용한 예제입니다.

gradient61
gradient62
gradient63
gradient64
.gradient65 {background-image: repeating-linear-gradient(45deg, transparent 5px, transparent 25px, #33691e 10px, #33691e 45px);}
.gradient66 {background-image: repeating-linear-gradient(45deg, transparent 10px, transparent 25px, #33691e 10px, #33691e 45px);}
.gradient67 {background-image: repeating-linear-gradient(45deg, transparent 15px, transparent 25px, #33691e 10px, #33691e 45px);}
.gradient68 {background-image: repeating-linear-gradient(45deg, transparent 20px, transparent 25px, #33691e 10px, #33691e 45px);}

예제12(Sample)

repeating-linear-gradient를 적용한 예제입니다.

gradient69
gradient70
gradient71
gradient72
.gradient69 {background-image: repeating-linear-gradient(45deg, transparent 5px, transparent 25px, #33691e 10px, #7cb342 45px);}
.gradient70 {background-image: repeating-linear-gradient(45deg, transparent 10px, transparent 25px, #33691e 15px, #7cb342 45px);}
.gradient71 {background-image: repeating-linear-gradient(45deg, transparent 15px, transparent 25px, #33691e 20px, #7cb342 45px);}
.gradient72 {background-image: repeating-linear-gradient(45deg, transparent 20px, transparent 25px, #33691e 25px, #7cb342 45px);}

예제13(Sample)

repeating-radial-gradient를 적용한 예제입니다.

gradient73
gradient74
gradient75
gradient76
.gradient73 {background-image: repeating-radial-gradient(#f6d365, #f6d365 5px, #fda085 5px, #fda085 10px);}
.gradient74 {background-image: repeating-radial-gradient(#f6d365, #f6d365 5px, #fda085 5px, #fda085 15px);}
.gradient75 {background-image: repeating-radial-gradient(#f6d365, #f6d365 5px, #fda085 5px, #fda085 20px);}
.gradient76 {background-image: repeating-radial-gradient(#f6d365, #f6d365 5px, #fda085 5px, #fda085 25px);}

예제14(Sample)

repeating-radial-gradient를 적용한 예제입니다.

gradient77
gradient78
gradient79
gradient80
.gradient77 {background-image: repeating-radial-gradient(#f6d365, #f6d365 5px, #fda085 10px, #fda085 10px);}
.gradient78 {background-image: repeating-radial-gradient(#f6d365, #f6d365 5px, #fda085 15px, #fda085 15px);}
.gradient79 {background-image: repeating-radial-gradient(#f6d365, #f6d365 5px, #fda085 20px, #fda085 20px);}
.gradient80 {background-image: repeating-radial-gradient(#f6d365, #f6d365 5px, #fda085 25px, #fda085 25px);}

실습1(Example)

repeating-radial-gradient를 이용한 예제입니다.

난 대꾸도 잊은채
환화게 웃는그녀를 잠시 멍하니 바라보았다.
HTML
CSS
SCRIPT
<div class="esample">
<div>난 대꾸도 잊은채<br> 환화게 웃는그녀를 잠시 멍하니 바라보았다.</div>
</div>
@import url('https://webfontworld.github.io/iropke/IropkeBatang.css');
    
.esample {
    height: 100%;
    background-image: repeating-linear-gradient(135deg, 
        #2b3284 0px, #2b3284 100px,
        #4177bc 100px, #4177bc 105px,
        #2b3284 105px, #2b3284 130px,
        #4177bc 130px, #4177bc 260px,
        #ffffff 260px, #ffffff 265px,
        #4177bc 265px, #4177bc 270px,
        #444caa 270px, #444caa 330px
    );
    color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    font-family: 'IropkeBatang';
    text-align: center;
}
// Javascript none

실습2(Example)

radial-gradient를 이용한 예제입니다.

난 대꾸도 잊은채
환화게 웃는그녀를 잠시 멍하니 바라보았다.
HTML
CSS
SCRIPT
<div class="esample2">
    <div>난 대꾸도 잊은채<br> 환화게 웃는그녀를 잠시 멍하니 바라보았다.</div>
</div>
@import url('https://webfontworld.github.io/iropke/IropkeBatang.css');

.esample2 {
    height: 100%;
    background:
        radial-gradient(circle closest-side at 60% 43%, #b03 26%, rgba(187,0,51,0) 27%),
        radial-gradient(circle closest-side at 40% 43%, #b03 26%, rgba(187,0,51,0) 27%),
        radial-gradient(circle closest-side at 40% 22%, #d35 45%, rgba(221,51,85,0) 46%),
        radial-gradient(circle closest-side at 60% 22%, #d35 45%, rgba(221,51,85,0) 46%),
        radial-gradient(circle closest-side at 50% 35%, #d35 30%, rgba(221,51,85,0) 31%),
        radial-gradient(circle closest-side at 60% 43%, #b03 26%, rgba(187,0,51,0) 27%) 50px 50px,
        radial-gradient(circle closest-side at 40% 43%, #b03 26%, rgba(187,0,51,0) 27%) 50px 50px,
        radial-gradient(circle closest-side at 40% 22%, #d35 45%, rgba(221,51,85,0) 46%) 50px 50px,
        radial-gradient(circle closest-side at 60% 22%, #d35 45%, rgba(221,51,85,0) 46%) 50px 50px,
        radial-gradient(circle closest-side at 50% 35%, #d35 30%, rgba(221,51,85,0) 31%) 50px 50px;
    background-color:#b03;
    background-size:100px 100px;
    color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    font-family: 'IropkeBatang';
    text-align: center;
}
// Javascript none

실습3(Example)

radial-gradient를 이용한 예제입니다.

난 대꾸도 잊은채
환화게 웃는그녀를 잠시 멍하니 바라보았다.
HTML
CSS
SCRIPT
<div class="esample3">
    <div>난 대꾸도 잊은채<br> 환화게 웃는그녀를 잠시 멍하니 바라보았다.</div>
</div>
@import url('https://webfontworld.github.io/iropke/IropkeBatang.css');

.esample3 {
    height: 100%;
    background:
        radial-gradient(black 15%, transparent 16%) 0 0,
        radial-gradient(black 15%, transparent 16%) 8px 8px,
        radial-gradient(rgba(255,255,255,.1) 15%, transparent 20%) 0 1px,
        radial-gradient(rgba(255,255,255,.1) 15%, transparent 20%) 8px 9px;
        background-color:#282828;
        background-size:16px 16px;
    color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    font-family: 'IropkeBatang';
    text-align: center;
}
// Javascript none

호환성(Compatibility)

크롬 아이콘 파이어폭스 아이콘 사파리 아이콘 오페라 아이콘 네이버 웨일 익스플로러6 아이콘6 익스플로러7 아이콘7 익스플로러8 아이콘8 익스플로러9 아이콘9 익스플로러10 아이콘10 익스플로러11 아이콘11 엣지 아이콘 안드로이드 아이콘 ios 아이콘
background-image

참고(Reference)


댓글