๐ŸŒˆ CSS๋กœ ํ…์ŠคํŠธ ์˜ค๋ฒ„๋ ˆ์ด ํšจ๊ณผ ์ฃผ๊ธฐ (ํ›ผ์ดํฌ ์“ฐ๊ธฐ)

๊น€๋ผ๋น„ยท2023๋…„ 12์›” 12์ผ
1

Html / Css / Scss

๋ชฉ๋ก ๋ณด๊ธฐ
3/3
post-thumbnail

์˜ค๋Š˜์€ ์ด๋Ÿฐ UI๋ฅผ css๋กœ ๊ตฌํ˜„ํ•ด๋ณผ ๊ฒƒ์ž„. ์ด์œ ๋Š” ๋ˆ„๊ฐ€ ์–ด๋–ป๊ฒŒ ํ•˜๋ƒ๊ณ  ๋ฌผ์–ด๋ด์„œ.

๋””์ž์ธ์œผ๋กœ ๋ณด๋ฉด ๋Œ€์ถฉ ์ด๋Ÿฐ ๊ตฌ์กฐ์ž„

HTML

<div class="wrap">
  <div class="img-box">
	<img src="์ด๋ฏธ์ง€URL" alt="์ด๋ฏธ์ง€"/>
    <p class="color-red">Christmas</p>
  </div>
  <p class="color-green">Christmas</p>
</div>

.img-box ๋‚ด์— ์ด๋ฏธ์ง€, ๋นจ๊ฐ„์ƒ‰ ํ…์ŠคํŠธ ๋ถ€๋ถ„์„ ๊ฐ™์ด ๋„ฃ์–ด์คŒ
์ดˆ๋ก์ƒ‰ ํ…์ŠคํŠธ ๋ถ€๋ถ„์€ .img-box ๋ฐ–์—๋‹ค ๋ฐฐ์น˜

CSS

/*์ตœ์ƒ์œ„ ๊ป๋ฐ๊ธฐ ์ƒ์„ฑ*/
.wrap {
  margin: 30px;
  position: relative;
  width: 155px;
  height: 155px;
}

/*์ด๋ฏธ์ง€ ๋ฐ•์Šค ํšจ๊ณผ ์ฃผ๊ธฐ*/
.img-box {
  z-index: 1;
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0px 4px 4px 0px rgba(52, 70, 83, 0.25);
}

.img-box img{
  width: 100%;
  height: 100%;
}

/*ํ…์ŠคํŠธ ์Šคํƒ€์ผ ๊ฐ’*/
p{
  margin: 0;
  position: absolute;
  text-align: center;
  left: 50%; 
  transform: translate(-50%, -50%); 
}

.color-red{
  top: 0;
  color: #FF2424;
}

.color-green {
  top:0;
  color: #167230;
}
  1. .img-box์— ์ดˆ๋ก์ƒ‰ ํ…์ŠคํŠธ๋ฅผ ๋ฐ˜ ์ฏค ๊ฑธ์ณ์ฃผ์–ด์•ผ ํ•˜๋‹ˆ๊นŒ .wrap์—๋„ position: relative;๊ฐ€ ๋“ค์–ด๊ฐ€์•ผํ•จ

  2. .img-box๊ฐ€ ์ดˆ๋ก์ƒ‰ ํ…์ŠคํŠธ๋ณด๋‹ค ์œ„์— ์™€์•ผํ•˜๋‹ˆ๊นŒ z-index ์ถ”๊ฐ€

  3. ํ…์ŠคํŠธ ์ค‘์•™ ์ •๋ ฌ text-align ๋ง๊ณ  position ์œผ๋กœ ์กฐ์ ˆ

์™„์„ฑ

(์ด๋ฏธ์ง€ svg๋กœ ๋ณต๋ถ™ ํ•ด์˜ค๋А๋ผ ์ฝ”๋“œ ๊ธด ๊ฑฐ ๋ฌด์‹œํ•ด์ฃผ์„ธ์šฉ.)

profile
UI๋””์ž์ธ, ๋งˆํฌ์—…๊ฐœ๋ฐœ(ํผ๋ธ”๋ฆฌ์‹ฑ)

0๊ฐœ์˜ ๋Œ“๊ธ€