โค้ด CSS นี้สร้างภาพประกอบ กระต่าย (Rabbit) ที่น่ารักและมีรายละเอียด
โค้ด CSS:root {
--fur: #f2f2f2;
--fur-shadow: #e6e6e6;
--inner-ear: #ffb6c1;
--eye: #2c2c2c;
--nose: #ff7b7b;
--cheek: #ffd6e0;
--bg: #cde9ff;
--ground: #bde2ff;
}
* { box-sizing: border-box; }
body {
margin: 0;
background: linear-gradient(180deg, var(--bg), var(--ground));
font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
display: grid;
place-items: center;
min-height: 100vh;
}
.scene {
width: 320px;
height: 360px;
position: relative;
filter: drop-shadow(0 12px 18px rgba(0,0,0,0.15));
}
.rabbit {
position: absolute;
left: 50%;
top: 55%;
transform: translate(-50%, -50%);
width: 220px;
height: 260px;
}
/* Ears */
.ear {
position: absolute;
width: 54px;
height: 120px;
background: var(--fur);
border-radius: 30px 30px 50px 50px;
box-shadow: inset 0 -10px 0 var(--fur-shadow);
}
.ear::after {
content: "";
position: absolute;
left: 50%;
transform: translateX(-50%);
top: 10px;
width: 28px;
height: 90px;
background: var(--inner-ear);
border-radius: 16px;
opacity: 0.9;
}
.ear-left {
left: 35px;
top: -40px;
transform: rotate(-8deg);
}
.ear-right {
right: 35px;
top: -50px;
transform: rotate(10deg);
}
/* Head */
.head {
position: absolute;
left: 50%;
transform: translateX(-50%);
top: 20px;
width: 170px;
height: 140px;
background: var(--fur);
border-radius: 50% / 45%;
box-shadow: inset 0 -14px 0 var(--fur-shadow);
}
/* Eyes */
.eye {
position: absolute;
width: 18px;
height: 18px;
background: var(--eye);
border-radius: 50%;
top: 55px;
}
.eye::after {
content: "";
position: absolute;
width: 6px;
height: 6px;
background: white;
border-radius: 50%;
top: 3px;
left: 3px;
opacity: 0.8;
}
.eye-left { left: 44px; }
.eye-right { right: 44px; }
/* Nose + mouth */
.nose {
position: absolute;
left: 50%;
transform: translateX(-50%);
top: 78px;
width: 16px;
height: 12px;
background: var(--nose);
border-radius: 50% 50% 60% 60%;
}
.mouth {
position: absolute;
left: 50%;
transform: translateX(-50%);
top: 94px;
width: 26px;
height: 16px;
}
.mouth::before,
.mouth::after {
content: "";
position: absolute;
width: 14px;
height: 10px;
border-bottom: 2px solid #333;
border-radius: 0 0 12px 12px;
top: 0;
}
.mouth::before { left: 0; }
.mouth::after { right: 0; }
/* Cheeks */
.cheek {
position: absolute;
width: 30px;
height: 18px;
background: var(--cheek);
border-radius: 50%;
top: 92px;
filter: blur(0.3px);
opacity: 0.9;
}
.cheek-left { left: 22px; }
.cheek-right { right: 22px; }
/* Body */
.body {
position: absolute;
left: 50%;
transform: translateX(-50%);
top: 120px;
width: 160px;
height: 120px;
background: var(--fur);
border-radius: 60% 60% 50% 50% / 60% 60% 40% 40%;
box-shadow: inset 0 -16px 0 var(--fur-shadow);
}
/* Belly */
.belly {
position: absolute;
left: 50%;
transform: translateX(-50%);
top: 24px;
width: 90px;
height: 70px;
background: white;
opacity: 0.9;
border-radius: 50%;
}
/* Arms */
.arm {
position: absolute;
width: 40px;
height: 52px;
background: var(--fur);
top: 42px;
border-radius: 30px;
box-shadow: inset 0 -8px 0 var(--fur-shadow);
}
.arm-left {
left: -6px;
transform: rotate(12deg);
}
.arm-right {
right: -6px;
transform: rotate(-12deg);
}
/* Feet */
.foot {
position: absolute;
width: 60px;
height: 36px;
background: var(--fur);
bottom: -10px;
border-radius: 24px 24px 26px 26px;
box-shadow: inset 0 -8px 0 var(--fur-shadow);
}
.foot-left {
left: 24px;
transform: rotate(6deg);
}
.foot-right {
right: 24px;
transform: rotate(-6deg);
}
/* Tail */
.tail {
position: absolute;
width: 34px;
height: 34px;
background: white;
border-radius: 50%;
right: -8px;
top: 160px;
box-shadow: inset 0 -6px 0 #f7f7f7;
}
/* Subtle bounce animation for life */
.rabbit {
animation: bounce 2.4s ease-in-out infinite;
}
@keyframes bounce {
0%, 100% { transform: translate(-50%, -50%) }
50% { transform: translate(-50%, -52%) }
}
โค้ด HTML
<div class="scene">
<div class="rabbit">
<div class="ear ear-left"></div>
<div class="ear ear-right"></div>
<div class="head">
<div class="eye eye-left"></div>
<div class="eye eye-right"></div>
<div class="nose"></div>
<div class="mouth"></div>
<div class="cheek cheek-left"></div>
<div class="cheek cheek-right"></div>
</div>
<div class="body">
<div class="arm arm-left"></div>
<div class="arm arm-right"></div>
<div class="belly"></div>
</div>
<div class="foot foot-left"></div>
<div class="foot foot-right"></div>
<div class="tail"></div>
</div>
</div>
โดยใช้เพียง CSS และองค์ประกอบ HTML พื้นฐานเท่านั้น มีการใช้ตัวแปร CSS (Custom Properties) เพื่อกำหนดสีต่างๆ เช่น สีขน (fur), สีหูชั้นใน (inner-ear), สีตา (eye) และสีพื้นหลัง (bg, ground)
องค์ประกอบหลักของกระต่ายประกอบด้วย:นอกจากนี้ ยังมีการเพิ่ม แอนิเมชัน (Animation) ชื่อ bounce เพื่อให้กระต่ายขยับขึ้นลงเล็กน้อยอย่างต่อเนื่อง ทำให้ภาพมีชีวิตชีวามากยิ่งขึ้น