Kitty用HTML和css咋做,使用CSS3代码绘制可爱的Hello Kitty猫

感觉这个 Hello Kitty 画的还不错,心血来潮也用 CSS3 画了个 Hello Kitty,现在在这里记录一下详细的绘制过程。想要源码、素材、在线演示的同学可以直接拉到最下面。我们先看下原图:

a92035e6b042d994f2d80b0e3fc23fe1.png

结构分解

从上图可以看出,Hello Kitty 由脸蛋、耳朵、红色蝴蝶结、眼睛、鼻子和六根胡须构成,所以 DOM 结构也相对简单:

CSS Code复制内容到剪贴板

开始绘制

可以利用 Photoshop 的参考线精确的计算出元素的 left、top、width、height、border-width 以及四个角的水平 radius 值和垂直 radius 值,有偏差的地方再微调一下基本就可以了。

7fb2278f7d984d2888a2f3caa9ece911.png

脸蛋

CSS Code复制内容到剪贴板

.hello-kitty-div .face {

left:107px;

top:77px;

width:747px;

height:566px;

border-top:35pxsolidblack;

border-bottom:31pxsolidblack;

border-left:29pxsolidblack;

border-right:30pxsolidblack;

border-top-left-radius:355px333px;

border-top-rightright-radius:355px333px;

border-bottom-left-radius:370px285px;

border-bottom-rightright-radius:330px255px;

background-color:white;

z-index: 100;

}

a831dd36d97fc73d45b593a72dc213ba.png

左耳

CSS Code复制内容到剪贴板

.hello-kitty-div .left-ear {

left:112px;

top:61px;

width:250px;

height:250px;

border-top:33pxsolidblack;

border-bottom:30pxsolidblack;

border-left:28pxsolidblack;

border-right:30pxsolidblack;

border-top-left-radius:138px100px;

border-bottom-left-radius:334px310px;

background-color:white;

transform: rotate(23deg);

z-index: 99;

}

8074808980d0d3ed6ec7d4e5254f4459.png

让耳朵和脸蛋连为一体:

CSS Code复制内容到剪贴板

.hello-kitty-div .left-ear-clean {

left:146px;

top:96px;

width:250px;

height:250px;

border-top-left-radius:138px100px;

border-bottom-left-radius:360px310px;

background-color:white;

transform: rotate(23deg);

z-index: 101;

}

0b85c0a2f70fc5c3e389f2a5b0e5e84e.png

再稍加点缀,美化一下:

CSS Code复制内容到剪贴板

.hello-kitty-div .left-ear-beautify {

left:149px;

top:221px;

width:60px;

height:30px;

border-top-left-radius:20px15px;

border-top-rightright-radius:25px15px;

border-bottom-left-radius:20px15px;

border-bottom-rightright-radius:25px15px;

background-color:black;

transform: rotate(-52deg);

z-index: 102;

}

8730df72ffa11f9aa74c6b909596fc99.png

右耳

CSS Code复制内容到剪贴板

.hello-kitty-div .rightright-ear {

left:600px;

top:50px;

width:250px;

height:250px;

border-top:33pxsolidblack;

border-bottom:28pxsolidblack;

border-left:30pxsolidblack;

border-right:29pxsolidblack;

border-top-left-radius:220px170px;

border-top-rightright-radius:90px57px;

border-bottom-rightright-radius:334px245px;

background-color:white;

transform: rotate(-21deg);

z-index: 99;

}

.hello-kitty-div .rightright-ear-clean {

left:700px;

top:105px;

width:120px;

height:120px;

background-color:white;

z-index: 101;

}

9c8faf44f6914521fe65b5b4139d31aa.png

右耳画的比较粗糙,因为马上就要画蝴蝶结了。

蝴蝶结

蝴蝶结分为两个外边,三个圆。外边是整个绘画过程中最难画的地方,用矩形调整 radius 参数很难做到没有偏差,因为它不像是更圆润的矩形,而像是更圆润的三角形。在这里,我们把它分成四块,各个外边各两块,在块内绘制好对应的区域,再利用 overflow: hidden; 来隐藏多余的部分。然后是三个圆,相对简单。

代码量实在太多,就不贴出来了,大概思路就这样子。

8779ebdd108884946f89f866e4b94a73.png

f84a2194e22a7ebc468c4e20f5029311.png

59c532b7e0e0e9a9747ea310170078e4.png

280f39dba07edd249f651236be1ffa89.png

眼睛,鼻子

眼睛和鼻子相对简单,就不贴代码了。

eda0340f23b1e00426b3c48cda71f6d7.png

胡须

因为胡须是弯弯的,所以每根胡须需要两个元素来实现,我们就用 :before 和 :after 吧。

某一根胡须的代码:

CSS Code复制内容到剪贴板

.hello-kitty-div .left-moustache-1:before {

content:'\20';

display:block;

position:absolute;

left:20px;

top:420px;

width:100px;

height:24px;

border-top-left-radius:80px30px;

border-bottom-left-radius:20px;

background-color:black;

transform: rotate(-5deg);

z-index: 101;

}

.hello-kitty-div .left-moustache-1:after {

content:'\20';

display:block;

position:absolute;

left:131px;

top:418px;

width:60px;

height:24px;

border-top-rightright-radius:100px30px;

border-bottom-rightright-radius:20px;

background-color:black;

transform: rotate(2deg);

z-index: 101;

}

现在,整个 Hello Kitty 就画完了,有没有觉得很可爱?~~(ฅ>ω

ddbbce69c8fc02f54dafd15047586534.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值