์ฝํ ์ธ ์ ๋ฐ์ ํ ์ฐ๊ด์ด ์๋ ์ด๋ฏธ์ง ์ฌ์ฉ ์์ ์ ํฉ
// html
<img src="์ด๋ฏธ์ง ์ฃผ์" alt="์ด๋ฏธ์ง ์ค๋ช
">
alt=""
๋ถ๋ถ์ ์ด๋ฏธ์ง ์ค๋ช
์ ๋ฃ์ด ์น ์ ๊ทผ์ฑ์ ์ค์ํ ์ ์๋ค.
์ด๋ฏธ์ง ์ค๋ช
์ด h2, p, span ๋ฑ์ ํ๊ทธ๋ก ๊ธฐ์ฌ๋๋ค๋ฉด, alt
๋ค์ =""
์ ์ญ์ ํ์ฌ '์ด๋ฏธ์ง ์ค๋ช
์ ๊ณตํ์ง ์๋๋ค.' ๋ผ๋ ์๋ฏธ์ธ alt
๋ก๋ง ์์ฑํ๋ฉด ๋๋ค.
๋จ์ํ ๋์์ธ์ ์ผ๋ก ์ฌ์ฉ๋ ์ด๋ฏธ์ง ์ฌ์ฉ ์์ ์ ํฉ (๋ฐฐ๊ฒฝ, ์์ด์ฝ ๋ฑ)
// css
.image {
background-image: url('์ด๋ฏธ์ง ์ฃผ์');
background-repeat: no-repeat;
width: 20px;
height: 20px;
display: block;
}
background-position: x-position y-position;
x-position y-position
: ๊ฐ๋ก ์์น์ ์ธ๋ก ์์น ์ง์
ย ย ย ใด ์ฌ์ฉ ๊ฐ๋ฅํ ์์ฑ๊ฐ : right
left
top
bottom
center
%
px
initial
: ๊ธฐ๋ณธ๊ฐ์ผ๋ก ์ค์
inherit
: ๋ถ๋ชจ ์์์ ์์ฑ๊ฐ์ ์์๋ฐ์
โ ํ์ฉ
// ์ค๋ฅธ์ชฝ ์๋จ
background-position: right top;
background-position: 100% 0%;
// ์ค์ ํ๋จ
background-position: center bottom;
background-position: 50% 100%;
// px ์ฌ์ฉ
background-position: -50px 0;
// calculate ํ์ฉ
background-position: calc(100% - 18px) center;
โ๏ธTip!
center center;
๊ฐ ์๋ center;
ํ ๋ฒ๋ง ๊ธฐ์ฌํ์ฌ๋ ๋๋ค.background-position: center;
background-size: width height | contain | cover;
auto
: ๊ธฐ๋ณธ๊ฐ, ์ด๋ฏธ์ง์ ์๋ ํฌ๊ธฐ ๊ทธ๋๋ก ๋ณด์ฌ์ง๋ค.
px
: ํ ๊ฐ์ง ๊ฐ๋ง ์ง์ ํ๋ฉด ๋๋จธ์ง๋ ์๋์ผ๋ก auto ๊ฐ์ด ๋ค์ด๊ฐ๋ค.
%
: ๋ถ๋ชจ ์์์ ๋น๋กํ % ๊ฐ์ผ๋ก ์ง์ ๋๋ค. ์ญ์ ํ ๊ฐ์ง ๊ฐ๋ง ์ง์ ํ๋ฉด ๋๋จธ์ง๋ ์๋์ผ๋ก auto ๊ฐ์ด ๋ค์ด๊ฐ๋ค.
cover
: ์์ญ์ ๋น๊ณต๊ฐ ์์ด ๊ฝ ์ฑ์ด๋ค(ํ๋). ์ด๋ฏธ์ง์ ์ผ๋ถ๊ฐ ์๋ฆด ์ ์๋ค.
contain
: ๋น์จ์ ์ ์งํ๋ฉฐ ์์ญ์ ๊ฐ๋ก ๋๋ ์ธ๋ก ๊ฐ์ ๋ง๊ฒ ํฌ๊ธฐ๊ฐ ์กฐ์ ๋๋ฉฐ, ๊ฐ๋ก ๋๋ ์ธ๋ก ๊ธธ์ด์ ๋ฑ ๋ง์ถ๊ธฐ ๋๋ฌธ์ ์ฌ๋ฐฑ์ด ์๊ธธ ์ ์๋ค.
initial
: ๊ธฐ๋ณธ๊ฐ์ผ๋ก ์ด๊ธฐํ ๋๋ค.
โ ํ์ฉ
background-size: 100px 100px;
background-size: 20% 20%;
background-size: cover;
background-size: 15px auto;
repeat
์ด๋ค.no-repeat
์ผ๋ก ์ด๋ฏธ์ง๊ฐ ๋ฐ๋ณต๋์ง ์๊ฒ ํ๋ค.initial
๊ณผ inherit
์ฌ์ฉ ๊ฐ๋ฅํ๋ค.background-repeat: ;
โ ํ์ฉ
background-repeat: repeat-x;
background-repeat: repeat-y;
background-repeat: repeat;
background-repeat: no-repeat;
background-repeat: initial;
background-repeat: inherit;
scroll
์ด๋ค.background-attachment: scroll | fixed | local;
scroll
: ๊ธฐ๋ณธ๊ฐ, ์ด๋ฏธ์ง๊ฐ ์์๋ฅผ ๊ธฐ์ค์ผ๋ก ์๋์ ์ธ ์์น๋ฅผ ๊ฐ๋๋ค.
fixed
: ์ด๋ฏธ์ง๊ฐ ๋ธ๋ผ์ฐ์ ์ฐฝ์ ์๋์ ์ธ ์์น๋ฅผ ๊ฐ๋๋ค. ์คํฌ๋กค์ ๋ด๋ ค๋ ์ด๋ฏธ์ง ์์น๋ ๊ณ ์ ๋์ด ์๋ค.
local
: ์คํฌ๋กคํ ๋ ๋ด์ฉ์ ๊ธฐ์ค์ผ๋ก ์๋์ ์ธ ์์น๋ฅผ ๊ฐ๋๋ค.
initial
: ๊ธฐ๋ณธ๊ฐ์ผ๋ก ์ค์
inherit
: ๋ถ๋ชจ ์์์ ์์ฑ๊ฐ์ ์์๋ฐ์
โ๏ธTip!
overflow: auto;
์ฒ๋ผ ์๋ ์คํฌ๋กค์ด ์๊ธธ ๊ฒฝ์ฐ, ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง๋ ์คํฌ๋กค๋์ง ์๋๋ค. ์ด ๊ฒฝ์ฐ local
์ ์ฌ์ฉํ๋ฉด ๋ด์ฉ๊ณผ ํจ๊ป ์คํฌ๋กค ๋๋ค.
์ฐธ๊ณ ์๋ฃ
https://homzzang.com/b/css-36
https://aboooks.tistory.com/165
https://www.codingfactory.net/10571