首先,大家需要创建一个div元素来盛放大家的嘴巴。
<div class="mouth"></div>
然后,大家需要为这个div元素设置宽度和高度,并设置一个背景颜色。
.mouth { width: 80px; height: 40px; background-color: pink; }
现在,大家可以开始画嘴巴了。大家可以使用border-radius属性来画出圆角。
.mouth { width: 80px; height: 40px; background-color: pink; border-radius: 0 0 40px 40px; }
接下来,大家可以使用伪元素来画出嘴唇。大家可以使用::before和::after伪元素分别画出上嘴唇和下嘴唇。
.mouth::before { content: ""; display: block; width: 80px; height: 20px; border: 2px solid pink; border-radius: 0 0 40px 40px; border-bottom: none; transform: translateY(-10px); } .mouth::after { content: ""; display: block; width: 80px; height: 20px; border: 2px solid pink; border-radius: 40px 40px 0 0; border-top: none; transform: translateY(10px); }
最后,大家可以为上嘴唇和下嘴唇添加渐变效果,使嘴巴更加逼真。
.mouth::before { content: ""; display: block; width: 80px; height: 20px; border: 2px solid pink; border-radius: 0 0 40px 40px; border-bottom: none; transform: translateY(-10px); background: linear-gradient(to bottom, pink, white); } .mouth::after { content: ""; display: block; width: 80px; height: 20px; border: 2px solid pink; border-radius: 40px 40px 0 0; border-top: none; transform: translateY(10px); background: linear-gradient(to top, pink, white); }
现在,大家就成功地画出了一对逼真的嘴唇。CSS3的强大功能让大家可以用很少的代码画出非常漂亮的图形,无需使用图片和复杂的JavaScript代码。