์๊ตฌ์ฌํญ
- HTML ๊ตฌ์กฐ:
- <button class="tooltip-btn"> ํ๊ทธ๋ฅผ ๋ง๋ญ๋๋ค. ๋ฒํผ ๋ด๋ถ์ ํ ์คํธ("๋์๋ง")๋ฅผ ๋ฃ์ต๋๋ค.
- ๋ฒํผ ์์ <span class="tooltip-text">๋ฅผ ๋ง๋ค๊ณ ํดํ์ผ๋ก ํ์๋ ํ ์คํธ("์ฌ๊ธฐ์ ์ค์ํ ์ ๋ณด๊ฐ ์์ต๋๋ค.")๋ฅผ ๋ฃ์ต๋๋ค.
- CSS - ๋ฒํผ ๋ฐ ๊ธฐ๋ณธ ์ค์ :
- .tooltip-btn์ padding: 10px 20px, background-color: #007bff, color: white, border: none์ ์ ์ฉํฉ๋๋ค.
- .tooltip-btn์ด ํดํ์ ๊ธฐ์ค์ ์ด ๋๋๋ก ์์น ์ง์ ์์ฑ์ ์ค์ ํฉ๋๋ค.
- CSS - ํดํ ํ
์คํธ ์คํ์ผ:
- .tooltip-text์ ๋ค์ ์คํ์ผ์ ์ ์ฉํฉ๋๋ค:
- ๋ฐฐ๊ฒฝ์: #333 (์ด๋์ด ํ์)
- ๊ธ์์: white
- ํจ๋ฉ: 8px 12px
- ๋ชจ์๋ฆฌ ๋ฅ๊ธ๊ฒ: 4px
- ์ด๊ธฐ ์ํ: ํดํ์ด ์จ๊ฒจ์ ธ ์๋๋ก ์ค์ ํฉ๋๋ค.
- .tooltip-text์ ๋ค์ ์คํ์ผ์ ์ ์ฉํฉ๋๋ค:
- CSS - ํดํ ์์น ์ง์ :
- .tooltip-text๋ฅผ ๋ฒํผ ์์ชฝ ์ค์์ ์ค๋๋ก ์์น ์ง์ ์์ฑ์ ์ค์ ํฉ๋๋ค. (ํํธ: ๋ทฐํฌํธ ๊ธฐ์ค์ด ์๋ ๋ถ๋ชจ ์์ ๊ธฐ์ค)
- ํดํ์ด ๋ฒํผ์ผ๋ก๋ถํฐ ์ฝ -40px ์ ๋ ์์ ๋ฐฐ์น๋๋๋ก ํฉ๋๋ค.
- ํดํ์ ๊ฐ์ด๋ฐ ์ ๋ ฌํ๋๋ก ๋ณํ(transform) ์์ฑ์ ์ฌ์ฉํฉ๋๋ค. (ํํธ: ํดํ ๋๋น๋ฅผ ๋ชจ๋ฅด๋ ๊ฒฝ์ฐ ์ ์ฉํจ)
- CSS - ํ์ดํ (๊ฐ์ ์์):
- ํดํ ์๋์ชฝ์ ์์ ์ผ๊ฐํ ๋ชจ์์ ํ์ดํ๊ฐ ๋ฒํผ์ ๊ฐ๋ฆฌํค๋๋ก ๊ฐ์ ์์๋ฅผ ์ฌ์ฉํฉ๋๋ค. (ํํธ: ::after ์ฌ์ฉ)
- ํ์ดํ๋ ํดํ๊ณผ ๊ฐ์ #333 ๋ฐฐ๊ฒฝ์์ ์ฌ์ฉํ๊ณ ํดํ์ ์ค์ ์๋์ ์์นํด์ผ ํฉ๋๋ค.
- CSS - ํธ๋ฒ ํจ๊ณผ:
- .tooltip-btn์ ๋ง์ฐ์ค๋ฅผ ์ฌ๋ ธ์ ๋ (:hover), .tooltip-text๊ฐ ๋ณด์ด๋๋ก ์ค์ ํฉ๋๋ค.
๋๋ณด๊ธฐ
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200&icon_names=search" />
<style>
body {
padding: 80px;
}
.tooltip-btn {
position: relative;
padding: 10px 20px;
background-color: #007bff;
border: none;
color: #fff;
}
.tooltip-btn .tooltip-text {
position: absolute;
left: 50%;
top: -40px;
transform: translateX(-50%);
opacity: 0;
padding: 8px 12px;
background-color: #333;
border-radius: 4px;
white-space: nowrap;
color: #fff;
}
.tooltip-btn .tooltip-text::before {
content: '';
position: absolute;
top: 100%;
left: 50%;
display: inline-block;
border-style: solid;
border-width: 6px 6px 0 6px;
border-color: #333 transparent transparent transparent;
transform: translateX(-50%);
transform-origin: left center;
}
.tooltip-btn:hover .tooltip-text {
opacity: 1;
transition: opacity 0.3s linear;
}
</style>
</head>
<body>
<button class="tooltip-btn">
๋์๋ง
<span class="tooltip-text"><i class="material-symbols-outlined"></i> ์ฌ๊ธฐ์ ์ค์ํ ์ ๋ณด๊ฐ ์์ต๋๋ค.</span>
</button>
</body>
</html>
