css制作圆脸表情
使用CSS制作圆脸表情
通过CSS的border-radius属性可以轻松创建圆形脸,结合其他CSS属性设计眼睛、嘴巴等细节。
HTML结构
<div class="face">
<div class="eyes">
<div class="eye left"></div>
<div class="eye right"></div>
</div>
<div class="mouth"></div>
</div>
CSS样式
.face {
width: 200px;
height: 200px;
background-color: #FFCC00;
border-radius: 50%;
position: relative;
margin: 50px auto;
}
.eyes {
display: flex;
justify-content: space-between;
width: 120px;
position: absolute;
top: 60px;
left: 40px;
}
.eye {
width: 40px;
height: 40px;
background-color: #333;
border-radius: 50%;
}
.mouth {
width: 80px;
height: 20px;
background-color: #333;
border-radius: 0 0 40px 40px;
position: absolute;
bottom: 50px;
left: 60px;
}
添加表情变化
通过修改CSS类实现不同表情变化,例如笑脸和哭脸。
笑脸样式
.smile .mouth {
border-radius: 0 0 40px 40px;
height: 20px;
}
哭脸样式

.sad .mouth {
border-radius: 40px 40px 0 0;
height: 20px;
}
添加动画效果
使用CSS动画让表情动起来,例如眨眼或说话动作。
眨眼动画
@keyframes blink {
0%, 100% { height: 40px; }
50% { height: 5px; }
}
.eye {
animation: blink 3s infinite;
}
说话动画

@keyframes talk {
0%, 100% { height: 20px; }
50% { height: 10px; }
}
.mouth {
animation: talk 1s infinite;
}
响应式调整
通过媒体查询确保表情在不同设备上显示正常。
@media (max-width: 600px) {
.face {
width: 150px;
height: 150px;
}
.eyes {
width: 90px;
top: 45px;
left: 30px;
}
.eye {
width: 30px;
height: 30px;
}
.mouth {
width: 60px;
bottom: 40px;
left: 45px;
}
}
进阶技巧
使用伪元素添加更多细节,例如眉毛或腮红。
添加眉毛
.eye.left::before, .eye.right::before {
content: '';
width: 30px;
height: 5px;
background-color: #333;
position: absolute;
top: -15px;
left: 5px;
border-radius: 5px;
}
添加腮红
.face::after {
content: '';
width: 40px;
height: 20px;
background-color: #FF9999;
border-radius: 50%;
position: absolute;
top: 100px;
left: 20px;
opacity: 0.5;
}
.face::before {
content: '';
width: 40px;
height: 20px;
background-color: #FF9999;
border-radius: 50%;
position: absolute;
top: 100px;
right: 20px;
opacity: 0.5;
}






