css百度图片布局,css3绘制百度的小度熊

前几天看到一篇文章是写用css3绘制腾讯企鹅的。趁着今天有空,就用css3来写一个百度的小度熊。话不多说,开始上码。

爆照

先来一张呆萌小度熊的成果照。

c4e038d9f0d25a4bc6fa1f4c621937e2.png

在绘制小度熊之前,首先要对小度熊布局上进行一个分解,便于我们组织代码结构。 从整体结构上主要分成耳朵,头部和身体。我们统一对将胳膊,肚子和腿都放到了身体的部分里。

纯css度熊

结构调整好之后,我们先把背景容器的位置和大小设置一下。在开发的时候,可以先给背景设置一个深色背景,便于我们看各部分的位置,最后的时候注释掉就可以了。

/*背景容器*/

.bac {

width: 345px;

height: 500px;

top: 50%;

position: relative;

left: 50%;

transform: translate(-50%,-50%);

/* background-color: #333333; */

}

头部

然后我们就可以在容器中,放置各个部分了,我是按从上到下的顺序写的,所以最开始放置的是头部。

93c6df0c9011c0d01694a7577267f67c.png

/*头部*/

.bac .head {

width: 346px;

height: 288px;

/* background-color: #e1b79b; */

border: 3px solid #a57662;

border-radius: 50% 50% 50% 50% / 70% 60% 40% 40%;

position: relative;

z-index: 88;

}

知识点来了,怎么样可以画出这种不规则的形状呢?绘制这种带有弧线的形状,可以使用border-radius属性,具体使用方法这里不深入讨论,简单来说通过设置元素的border-radius值,可以轻松给元素设置圆角边框,甚至实现绘制圆、半圆、四分之一的圆等各种圆角图形。因为我没有准确的尺寸图,所以就用百分比来实现了。

“/”前的四个数值表示圆角的水平半径,后面四个值表示圆角的垂直半径。这个方法我们在后面还会很频繁的使用到。

耳朵

绘制完头部轮廓之后,我们可以把耳朵的轮廓也加上,本来计划是将耳朵写在头部

内部的,但是因为要考虑层级压盖的情况,还是把耳朵要素单独的放在了外面。这里有一个关键属性就是transform: rotate(Xdeg)用来对要素做旋转,我们可以将耳朵旋转成对应的角度。

9c5cc440d4e50af276a79635ba24bcea.png

/*左耳朵*/

.earLeft {

height: 50px;

width: 70px;

/* background-color: #e1b79b; */

border-radius: 200px 200px 100px 100px;

border: 3px solid #a57662;

transform: rotate(-49deg);

position: absolute;

top: 10px;

left: 12px;

}

/*右耳朵*/

.earRight {

height: 50px;

width: 70px;

/* background-color: #e1b79b; */

border-radius: 200px 200px 100px 100px;

border: 3px solid #a57662;

transform: rotate(40deg);

position: absolute;

top: 10px;

right: 0;

}

眼睛

接下来就开始填充绘制头部里面的内容,头部里面主要是眼睛,鼻子和嘴巴,我们先来画眼睛,为了看的清楚,我们就把头部填充上颜色了。

e861d85765daae2021af7357b0d9c576.png

/*左眼白*/

.head .eyeLeft {

height: 78px;

width: 67px;

background-color: #ffffff;

border-radius: 50% / 50%;

transform: rotate(20deg);

position: absolute;

top: 113px;

left: 68px;

}

/*左眼珠*/

.head .eyeConLeft {

width: 28px;

height: 33px;

background-color: #511313;

position: absolute;

border-radius: 50%/50%;

transform: rotate(-13deg);

top: 20px;

right: 15px;

}

/*右眼白*/

.head .eyeRight {

height: 78px;

width: 67px;

background-color: #ffffff;

border-radius: 50% / 50%;

transform: rotate(-20deg);

position: absolute;

top: 113px;

right: 68px;

}

/*右眼珠*/

.head .eyeConRight {

width: 28px;

height: 33px;

background-color: #511313;

position: absolute;

border-radius: 50%/50%;

transform: rotate(13deg);

top: 20px;

left: 15px;

}

嘴巴

绘制了眼睛之后,我们来绘制嘴巴,嘴巴没有太特殊的地方,我们用正常椭圆就可以。

6ff0385a2d320cc9abb7b6bfd3f5cd92.png

/*嘴巴*/

.head .mouse {

width: 99px;

height: 76px;

background-color: #f7f9e5;

position: absolute;

left: 50%;

transform: translate(-50%,0);

border-radius: 50% / 50%;

top: 187px;

}

鼻子

虽然嘴巴就是一个普通的椭圆,但是鼻子比较特殊,鼻子我们可以看作是一个半椭圆+三角形组成。

bd35a443f0e9eb7a20759fe03dbfe9dd.png

知识点又来了,怎么样用css画半椭圆和三角形呢?

我们可以利用 border-radius: 50%/100% 100% 0 0; 来实现半椭圆的绘制。

1dfab5c6fa6dea8dfa491606f9fce450.png

我们利用将width和height设置为0,通过border属性来实现三角形的绘制。

9dbd16aa023276534b6be9ee0835562e.png

我为了操作方便,在给鼻子设置来一个容器,使其居中,便于调整。

/*鼻子容器*/

.head .nose {

width: 18px;

height: 14px;

position: absolute;

left: 50%;

margin-left: -9px;

top: 13px;

}

/* 鼻子上部分-半椭圆*/

.nose .noseTop {

width: 18px;

height: 8px;

background-color: #511313;

border-radius: 50%/100% 100% 0 0;

}

/* 鼻子下部分-三角形*/

.nose .noseBottom {

width: 0;

height: 0;

border-width: 9px 9px 0;

border-style: solid;

border-color: #511313 transparent transparent;

position: relative;

}

耳朵内部

终于完成了头部的操作,结果发现耳朵少了点什么,原来耳朵少了内部的要素,我们就分别给耳朵内部加点东西。

f4761ca94e3d91e7d4123fc132d8840b.png

/* 左耳朵内部*/

.earLeft .earCon {

width: 40px;

height: 60px;

background-color: #eed8c5;

border-radius: 50%/ 40% 40% 30% 30%;

margin-left: 17px;

margin-top: 15px;

transform: rotate(-3deg);

}

/*右耳朵内部*/

.earRight .earCon {

width: 40px;

height: 60px;

background-color: #eed8c5;

border-radius: 50%/ 40% 40% 30% 30%;

margin-left: 17px;

margin-top: 15px;

transform: rotate(-3deg);

}

辅助要素

小度熊的头部绘制完了,但是耳朵的地方还不够完美,因为头部的轮廓线把耳朵遮住了,我们想让头部和耳朵连在一起,这就用到了我们的辅助要素。我们可以把辅助要素设置成和头部一样的颜色,将头部与耳朵间的轮廓线盖住,这样就看起来好多了。

2e054133b521dd3e73bbf094dfa6f8f3.png

/*左侧辅助要素*/

.head .arcLeft {

position: absolute;

top: 36px;

left: 23px;

width: 80px;

height: 30px;

background-color: #e1b79b;

border-radius: 50%/ 50%;

transform: rotate(-45deg);

}

/*右侧辅助要素*/

.head .arcRight {

position: absolute;

top: 34px;

right: 16px;

width: 80px;

height: 30px;

background-color: #e1b79b;

border-radius: 50%/ 50%;

transform: rotate(43deg);

}

身体

终于完成了头部的绘制,接下来就开始身体的绘制,同样需要先分析一下身体里包括那些部分,我们可以看到身体里主要包括胳膊,肚子和腿。

61b6eed9ecc8ec163db9f6de7ca7fda3.png

我们为了看清楚各部分位置,可以先给身体容器加上背景颜色,最后再去掉。

/*度熊身体*/

.body {

width: 208px;

height: 217px;

margin: -10px auto;

position: relative;

}

胳膊

我们先来添加小度熊的胳膊,最后位置可以再微调。

db0700b0612ff14378bce492673b379d.png

/*左侧胳膊*/

.body .armLeft {

width: 53px;

height: 150px;

background-color: #e1b79b;

border: 2px solid #a57662;

border-radius: 50% 50%/60% 30%;

transform: rotate(10deg);

left: 6px;

position: absolute;

}

/*右侧胳膊*/

.body .armRight {

width: 53px;

height: 150px;

background-color: #e1b79b;

border: 2px solid #a57662;

border-radius: 50% 50%/60% 30%;

transform: rotate(-14deg);

position: absolute;

right: 6px;

}

肚子

绘制好胳膊我们就可以绘制小度熊,肉嘟嘟的肚子了。

ba82598724e95769555e98b8ed18227b.png

知识点来了,这里绘制的肚子有一点想鸡蛋形,其实还是利用border-radius: 50% 50% 50% 50% / 70% 70% 30% 30%;这个属性来设置的,通过改变半径大小,实现这种鸡蛋形的图案绘制。

之前说的可能漏了一句,我们的要素大部分是基于position: absolute来定位的,因为这个属性可以设置层级,便于我们图案的压盖。这里的肚子就要设置高一点的层级,压盖住之前绘制的胳膊图案。

/*肚子*/

.body .tummy {

width: 144px;

height: 200px;

background-color: #e1b79b;

position: absolute;

left: 50%;

transform: translate(-50%,0);

border-radius: 50% 50% 50% 50% / 70% 70% 30% 30%;

margin-top: -30px;

border: 2px solid #a57662;

}

肚子图案

在小度熊的肚子上还有一个小图案,我们直接添加覆盖上去就可以了。

82fbff8b3b3779cf126a6bc5cfc0774f.png

/*肚子图案*/

.body .tummyCon {

width: 83px;

height: 90px;

background-color: #f7f9e5;

-webkit-border-radius: 63px 63px 63px 63px / 108px 108px 72px 72px;

border-radius: 50% 50% 50% 50% / 70% 70% 30% 30%;

position: absolute;

top: 60px;

left: 50%;

transform: translate(-50%, 0);

}

绘制好肚子之后,我们来绘制腿,腿上面没有什么太多难点,就是注意边框和脚的弧度就行。

e2ae1843f7d646ea5d7a8b84a4d63381.png

/*左腿*/

.body .legLeft {

width: 53px;

height: 100px;

background-color: #e1b79b;

position: absolute;

bottom: 0px;

left: 30px;

border: 2px solid #a57662;

border-color: transparent transparent #a57662 #a57662;

border-radius: 50% 50% 50% 50%/0 0 10% 50%;

}

/*右腿*/

.body .legRight {

width: 53px;

height: 100px;

background-color: #e1b79b;

position: absolute;

bottom: 0px;

right: 30px;

border: 2px solid #a57662;

border-color: transparent #a57662 #a57662 transparent;

border-radius: 50% 50% 50% 50%/0 0 50% 10%;

}

辅助要素

到这里我们基本的要素就绘制齐了,身体容器的背景颜色就可以去掉了,然后同样要绘制一些辅助元素,来让我们的小度熊看起来更好看。

我们要给小度熊添加一个脖子,盖住身体的线条。

204a345614fa3c6567a7ce6f2d96bf0c.png

给肚子添加一个曲线,让肚子和腿更立体。

d8f83f73b5753020e99e12ae45c41f25.png

最后就是要用辅助线条把脚展示出来。

e3cd9093f5f915563af5b61463090798.png

把这几个步骤完成,我们的小度熊整体就全部完成了。

7cde7a25f137ec1d91de9976a764491c.png

/*脖子遮盖*/

.body .neck {

width: 120px;

height: 30px;

background-color: #e1b79b;

position: absolute;

left: 50%;

transform: translate(-50%,0);

}

/*肚子辅助线*/

.body .arc {

border-bottom: 2px solid #511313;

position: absolute;

top: 70px;

left: 50%;

transform: translate(-50%, 0);

width: 100px;

height: 100px;

border: solid 2px #a57662;

border-color: transparent transparent #a57662 transparent;

border-radius: 50%/ 0 0 30% 30%;

}

/*左脚辅助线*/

.body .arcLeft {

border-bottom: 2px solid #511313;

position: absolute;

bottom: -30px;

left: 43px;

width: 35px;

height: 50px;

border: solid 2px #a57662;

border-color: #a57662 transparent transparent transparent;

border-radius: 50%/ 20% 20% 0 0;

}

/*右脚辅助线*/

.body .arcRight {

border-bottom: 2px solid #511313;

position: absolute;

bottom: -30px;

right: 43px;

width: 35px;

height: 50px;

border: solid 2px #a57662;

border-color: #a57662 transparent transparent transparent;

border-radius: 50%/ 20% 20% 0 0;

}

阴影

最后一步,给小度熊的脚底加一个阴影,我们就大功告成了。

a23f29e2e43ef97a16af6a5b0577db54.png

/*阴影*/

.shaodw {

width: 217px;

height: 39px;

background-color: #e9ecee;

margin: -20px auto;

border-radius: 50%/50%;

}

总结

绘制小度熊的关键是一个是对于布局的分析,一个是css的border-radius和transform: rotate属性的使用。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值