Frontend/CSS

html - img VS css - background

2-doooo-2 2023. 4. 21. 20:20
728x90
๋ฐ˜์‘ํ˜•

๐Ÿ“Œhtml - img

 <div class="item">
            <h1>html-img</h1>
            <img src="./all_image/summer.JPG" alt="๋Œ€์ฒด์ด๋ฏธ์ง€">
 </div>

-์ฃผ๋กœ ์ฝ˜ํ…์ธ  ์š”์†Œ๋กœ ์‚ฌ์šฉ๋จ  

๐Ÿ“Œcss - background

   <div class="item">
            <h2>css-background</h2>
            <div class="item-bg"></div>
   </div>

 - width, height๊ฐ’์„ ์ง€์ •ํ•ด์ค˜์•ผํ•จ * ํ•˜์ง€๋งŒ ์ง€์ •ํ•ด์ค˜๋„ image์˜ ๋ณธ์—ฐ์˜ ํฌ๊ธฐ์— ๋งž์ถฐ ์ƒ์„ฑ๋จ

-  ๋‚ด๊ฐ€ ์„ค์ •ํ•œ ๊ฐ’์œผ๋กœ image๊ฐ€ ๊ฝ‰์ฐจ๊ฒŒ ํ•ด์ฃผ๊ณ  ์‹ถ์œผ๋ฉด background-size:cover; 

(*width:100%; image์ž์‹ ์˜ ํฌ๊ธฐ์—์„œ 100%์ด๊ณ  background-size:cover;  ๋ถ€๋ชจ์š”์†Œ์˜ width๊ฐ’์— ๋”ฑ ๋งž์ถฐ์ง )

 

 

background-repeat:repeat-x /repeat-y /repeat /no-repeat

 

background-position

์š”์†Œ์— ์ง€์ •๋œ ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€์˜ ์œ„์น˜๋ฅผ ๋ณ€๊ฒฝํ•˜๊ณ ์ž ํ•  ๋•Œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.  

center, center top, right center, center bottom, left center๋“ฑ 

.item-bg{ background-position:left top;}

 

background-color

 

background-image:url()

 

background-size

cover:๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€๋ฅผ ๋Š˜์—ฌ ์ ์šฉ๋˜๋Š” ์š”์†Œ ์ „์ฒด์˜ ํ‘œ์‹œ 

contain:๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€์˜ ๊ฐ€๋กœ ์„ธ๋กœ ๋น„์œจ์„ ๋งž์ถฐ ์š”์†Œ์— ํ‘œ์‹œํ•  ์ˆ˜ ์žˆ๋Š” ์ตœ๋Œ€ ํฌ๊ธฐ๋กœ ํ‘œ์‹œ

 

background-attachment

์š”์†Œ์— ์ง€์ •๋œ ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€๋ฅผ ์Šคํฌ๋กค๋˜์–ด๋„ ํ•ญ์ƒ ๊ฐ™์€ ์œ„์น˜์— ๊ณ ์ •์‹œํ‚ค๊ณ ์ž ํ•  ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค. 

scroll:์Šคํฌ๋กค ์ ์šฉ

fixed:์ง€์ •ํ•œ ์Šคํฌ๋ฆฐ ์œ„์น˜์— ๊ทธ๋Œ€๋กœ ๋‚จ์Œ

 

background 

font ์†์„ฑ๊ณผ ๊ฐ™์ด ๋ฐฐ๊ฒฝ๊ณผ ๊ด€๋ จ๋œ 5๊ฐ€์ง€ ์†์„ฑ์„ ๋‹จ์ถ•ํ•ด์„œ ํ•œ๋ฒˆ์— ์„ ์–ธํ•˜๊ณ ์ž ํ•  ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค.

color/ image/ repeat/ position/ attachment/ inherit 

  .item-bg{ background:red url(./all_image/summer.JPG) no-repeat center scroll;}

 

 

๐Ÿ“Œ html - img  VS css - background

 

 

 

html - img ์†์„ฑ์€ ๋ธŒ๋ผ์šฐ์ €์˜ ํฌ๊ธฐ์— ๋ฐ˜์‘ํ•˜๋Š”๋ฐ ๋ฐ˜ํ•ด 

css - background ๊ทธ๋ ‡์ง€ ์•Š๋‹ค. 

๊ทธ ์†์„ฑ์„ ๋ฐ”๊พธ๊ธฐ ์œ„ํ•ด background - position, size ๋“ฑ์„ ํ™œ์šฉํ•˜๋Š” ๊ฒƒ์ด๋‹ค. 

 

728x90
๋ฐ˜์‘ํ˜•