Css3之画哆啦A梦

最近学习完css3画图,然后就百度找了看有没有好的练手机会,看到别人博客上面有画哆啦A梦,还有小黄人,就自己看了哆啦A梦的来巩固下Css3的知识,先看看效果图
在这里插入图片描述
我们把这个图拆分开来,分为上下两部分,上面是头部和身体,头部主要难画的是胡须,胡须的画法是通过画椭圆,然后用border-bottom:1px solid #000,椭圆的背景颜色设置为透明background:transparent,然后通过定位旋转完成,还有一个比较不好做的就是鞋子是用渐变做出有点3D的效果,其实做这种不然,就是需要耐心,大家也去动手做下

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>哆啦A梦</title>
	</head>
	<body>
		<div class="robot">
			<div class="head">
				<div class="face">
					<!--眼睛-->
					<div class="yes">
						<div class="robot-res">
							<div class="linear"></div>
							<div class="left-yes"></div>
						</div>
						<div class="robot-res">
							<div class="linear"></div>
							<div class="right-yes"></div>
						</div>
					</div>
					<!--鼻子-->
					<div class="nose"></div>
					<!--嘴巴-->
					<div class="mouth">
				        <div></div>
				        <div></div>
				    </div>
				    <!--胡须-->
				    <div class="beard-left"></div>
				    <div class="beard-right"></div>
				</div>
			</div>
			<div class="neck"></div>
			<div class="bell">
				<div class="line"></div>
			</div>
			<div class="body">
				<div class="pocket-bg"></div>
				<div class="hand">
					<div class="left-hand"></div>
					<div class="right-hand"></div>
				</div>
				<div class="foot">
					<div class="left-foot"></div>
					<div class="right-foot"></div>
				</div>
			</div>
		</div>
	</body>
	<style>
		body{
			margin: 0;
			padding: 0;
			background: #fff;
			width:100%;
		}
		.robot{
			position: relative;
		}
		.head{
			width:400px;
			margin: 10px auto;
			margin-bottom: 0;
			height:350px;
			/*background-color:#53a8d9;*/
			background-image:radial-gradient(ellipse at top right,#73c1ef,#53a8d9);
			border-radius:50% 50% 25% 25% / 55% 55% 45% 45%;
			position:relative;
			z-index: 4;
		}
		.face{
			width:310px;
			height:260px;
			background-color:white;
			border-radius:50% 50% 25% 25% / 55% 55% 45% 45%;
			position:absolute;
			bottom: 0;
			left:45px;
			z-index: 4;
			cursor:pointer;
		}
		.yes{
			display: flex;
			flex-direction: row;
			position: absolute;
			left: 70px;
			top:-40px;
			z-index: 10;
		}
		.robot-res{
			width:80px;
			height:100px;
			border-radius: 50%;
			background: #fff;
			border:2px solid #000;
			z-index: 5;
			position: relative;			
		}
		.robot-res .linear{
			width:100%;
			height:2px;
			background: #000;
			position: absolute;
			top:45px;
			display: none;
			transition: all 1s;
		}
		.left-yes{
			width:20px;
			height:25px;
			border-radius: 50%;
			background: #000;
			position: absolute;
			right:0px;
			top:45px;
			border:2px solid #000;
			z-index: 5;
		}
		.left-yes:before{
			content: '';
			width:10px;
			height:10px;
			border-radius: 50%;
			background: #fff;
			position: absolute;
			right:0px;
			top:7px;
			z-index: 15;
		}
		.right-yes{
			width:20px;
			height:25px;
			border-radius: 50%;
			background: #000;
			position: absolute;
			left:0px;
			top:45px;
			border:2px solid #000;
			z-index: 5;
			transition: all 1s;
		}
		.right-yes:before{
			content: '';
			width:10px;
			height:10px;
			border-radius: 50%;
			background: #fff;
			position: absolute;
			right:0px;
			top:7px;
			z-index: 15;
		}
		.nose{
			width:30px;
			height: 30px;
			background:#c70000;
			border-radius: 50%;
			position: absolute;
			top:40px;
			left:50%;
			margin-left:-15px;
			z-index: 5;
		}
		.nose:before{
			content: '';
			width:10px;
			height:10px;
			border-radius: 50%;
			background: #fff;
			position: absolute;
			right:0px;
			top:10px;
			z-index: 15;
		}
		.mouth{
			width:250px;
			height:200px;
			background:snow;
			border-radius: 50%;
			border-bottom: 2px #000 solid;
			position: absolute;
			left:50%;
			margin-left:-125px;
			top:30px;
			z-index: 4;
		}
		.mouth:before{
			content: '';
			height:140px;
			width:2px;
			margin-left:-1px;
			background:#000;
			position:absolute;
			left:50%;
			top:20px;
			
		}
		.face:hover .mouth{
			position: absolute;
			left:50%;
			margin-left:-90px;
			width: 180px;
			height: 200px;
			border-radius: 0;
			z-index: 2;
		}
		.face:hover .right-yes{
			left:57px;
		}
		.face:hover .linear{
			display: block;
		}
		.beard-left{
			width:130px;
			height:40px;
			border-radius: 50%;
			background:transparent;
			z-index: 999;
			border-bottom:2px solid #000;
			position: absolute;
			top:70px;
			left:-20px;
			transform: rotate(190deg);
		}
		.beard-left:before{
			content: '';
			width:130px;
			height:40px;
			border-radius: 50%;
			background:transparent;
			z-index: 999;
			border-bottom:2px solid #000;
			position: absolute;
			top:-30px;
			left:-5px;
			transform: rotate(-5deg);
		}
		.beard-left:after{
			content: '';
			width:130px;
			height:40px;
			border-radius: 50%;
			background:transparent;
			z-index: 999;
			border-bottom:2px solid #000;
			position: absolute;
			top:-60px;
			left:-5px;
			transform: rotate(-10deg);
		}
		.beard-right{
			width:130px;
			height:40px;
			border-radius: 50%;
			background:transparent;
			z-index: 999;
			border-bottom:2px solid #000;
			position: absolute;
			top:70px;
			left:200px;
			transform: rotate(170deg);
		}
		.beard-right:before{
			content: '';
			width:130px;
			height:40px;
			border-radius: 50%;
			background:transparent;
			z-index: 999;
			border-bottom:2px solid #000;
			position: absolute;
			top:-30px;
			left:5px;
			transform: rotate(5deg);
		}
		.beard-right:after{
			content: '';
			width:130px;
			height:40px;
			border-radius: 50%;
			background:transparent;
			z-index: 999;
			border-bottom:2px solid #000;
			position: absolute;
			top:-60px;
			left:5px;
			transform: rotate(10deg);
		}
		.neck{
			width:330px;
			height:200px;
			background: #e30000;
			border-radius: 50% 50% 20% 20%/50% 50% 50% 50%;
			position: absolute;
			left:50%;
			margin-left:-165px;
			bottom:-22px;		
			z-index: 2;	
		}	
		.neck:before{
			content: '';
			width:60px;
			height:4px;
			background: snow;
			border-radius: 10px;
			position: absolute;
			left:60px;
			bottom: 16px;
			z-index: 4;			
		}
		.bell{
			width:40px;
			height:40px;
			background: #ffdd2e;
			border-radius: 50%;
			position: absolute;
			left:50%;
			margin-left:-22px;
			bottom:-43px;
			border:2px solid #000;			
			transition: all 1s ease-in-out; 
			z-index: 2;
		}
		.bell:before{
			content: '';
			width:42px;
			height:5px;
			background: #ffdd2e;
			border-radius: 10px;
			position: absolute;
			left:50%;
			margin-left:-23px;
			top:12px;
			z-index: 5;
			border:2px solid #000;	
		}
		.bell:after{
			content: '';
			width:10px;
			height:10px;
			background: #6c5844;
			border-radius: 50%;
			position: absolute;
			left:50%;
			margin-left:-6px;
			bottom:5px;
			border:1px solid #000;	
		}
		.bell:hover{
			transform: scale(1.5);
			bottom:-55px;
		}
		.line{
			width:2px;
			height:5px;
			background: #000;
			position: absolute;
			left:50%;
			margin-left:-1px;
			bottom:0;
		}
		.body{
			width:280px;
			height:220px;
			background: #53a8d9;
			position: absolute;
			left:50%;
			margin-left:-140px;	
			border:1px solid #000;	
		}
		.pocket-bg{
			width:200px;
			height:200px;
			background:#fff;
			border-radius:50%;
			position: absolute;
			left: 50%;
			top:-20px;
			margin-left: -100px;
			border: 1px solid #000;
		}
		.pocket-bg:before{
			content: "";
			width:150px;
			height:75px;
			border-radius: 0 0 75px 75px;
			border:1px solid #000;
			position: absolute;
			top: 100px;
			left: 50%;
			margin-left:-76px;
		}
		.left-hand{
			width:110px;
			height:50px;
			background: #53a8d9;
			position: absolute;
			top:13px;
			left: -80px;
			border:1px solid #000;
			border-right: 0;
			border-bottom:0;
			transform: rotate(-38deg);
			z-index: 1;
		}
		.left-hand:before{
			content: '';
			width:65px;
			height:65px;
			background-color: #fff;
			border: 1px solid #000;
			border-radius: 50%;
			position: absolute;
			left: -25px;
			top:-9px
		}
		.left-hand:after{
			content: '';
			width:40px;
			height:1px;
			background-color: #000;
			position: absolute;
			left: 27px;
			bottom:0px
		}
		.right-hand{
			width:110px;
			height:50px;
			background: #53a8d9;
			position: absolute;
			top:13px;
			right: -75px;
			border:1px solid #000;
			border-left: 0;
			border-bottom:0;
			transform: rotate(38deg);
			z-index: 1;
		}
		.right-hand:before{
			content: '';
			width:65px;
			height:65px;
			background-color: #fff;
			border: 1px solid #000;
			border-radius: 50%;
			position: absolute;
			right: -35px;
			top:-8px
		}
		.right-hand:after{
			content: '';
			width:40px;
			height:1px;
			background-color: #000;
			position: absolute;
			right: 20px;
			bottom:0px
		}
		.left-foot{
			width:145px;
			height:30px;
			background:#fff;
			background: -webkit-gradient(linear, right top, left bottom, from(#fff),color-stop(0.75,#fff),color-stop(0.85,#eee), to(#999));
			border:1px solid #000;
			position: absolute;
			bottom: -30px;
			left:-20px;
			border-radius: 80px 60px 60px 40px;
			box-shadow: -6px 0 10px rgba(0, 0, 0, 0.35);
		}
		.right-foot{
			width:145px;
			height:30px;
			background:#fff;
			background: -webkit-gradient(linear, left top, right bottom, from(#fff),color-stop(0.75,#fff),color-stop(0.85,#eee), to(#999));
			border:1px solid #000;
			position: absolute;
			bottom: -30px;
			right:-22px;
			/*transform: rotate(-180deg);*/
			border-radius: 60px 80px 40px 60px;
			box-shadow: -6px 0 10px rgba(0, 0, 0, 0.35);
		}
		.body:before{
			content: '';
			width:40px;
			height:20px;
			background: #fff;
			position: absolute;
			border: 1px solid #000;
			border-bottom: 0;
			border-radius: 20px 20px 0 0;
			bottom:-1px;
			left: 50%;
			margin-left: -20px;
		}
	</style>
</html>

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是一个用HTML+CSS画哆啦A梦的示例: 1. 首先,我们需要一个HTML文件,可以使用以下代码: ``` <!DOCTYPE html> <html> <head> <title>哆啦A梦</title> <style> #doraemon { position: relative; width: 200px; height: 200px; background-color: #4d4d4d; border-radius: 100px; overflow: hidden; } #doraemon:before { content: ""; position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-color: #fff; border-radius: 100px; transform: translate(30px, 30px); } #doraemon .face { position: absolute; top: 30px; left: 30px; width: 140px; height: 140px; background-color: #fff; border-radius: 70px; overflow: hidden; } #doraemon .face:before { content: ""; position: absolute; top: 5px; left: 5px; width: 130px; height: 130px; background-color: #4d4d4d; border-radius: 65px; } #doraemon .face:after { content: ""; position: absolute; top: 50px; left: 50px; width: 40px; height: 40px; background-color: #fff; border-radius: 20px; } #doraemon .eyes { position: absolute; top: 50px; left: 70px; width: 60px; height: 45px; background-color: #000; border-radius: 30px; overflow: hidden; } #doraemon .eyes:before { content: ""; position: absolute; top: 5px; left: 5px; width: 50px; height: 35px; background-color: #fff; border-radius: 25px; } #doraemon .eyes:after { content: ""; position: absolute; top: 15px; left: 15px; width: 20px; height: 15px; background-color: #000; border-radius: 10px; } #doraemon .mouth { position: absolute; top: 110px; left: 40px; width: 120px; height: 50px; border-radius: 25px; border-top: 2px solid #000; background-color: #fff; transform: rotate(-20deg); } #doraemon .mouth:before { content: ""; position: absolute; top: 5px; left: 5px; width: 110px; height: 40px; background-color: #4d4d4d; border-radius: 20px; transform: rotate(20deg); } #doraemon .whiskers { position: absolute; top: 75px; left: 50px; width: 100px; height: 1px; background-color: #000; transform: rotate(10deg); } #doraemon .whiskers:before { content: ""; position: absolute; top: -5px; left: 0; width: 5px; height: 10px; background-color: #000; transform: rotate(-20deg); } #doraemon .whiskers:after { content: ""; position: absolute; top: 5px; left: 0; width: 5px; height: 10px; background-color: #000; transform: rotate(-20deg); } #doraemon .whiskers:nth-child(2) { transform: rotate(-10deg); } #doraemon .whiskers:nth-child(2):before { transform: rotate(20deg); } #doraemon .whiskers:nth-child(2):after { transform: rotate(20deg); } #doraemon .whiskers:nth-child(3) { transform: rotate(10deg); } #doraemon .whiskers:nth-child(3):before { transform: rotate(-20deg); } #doraemon .whiskers:nth-child(3):after { transform: rotate(-20deg); } </style> </head> <body> <div id="doraemon"> <div class="face"></div> <div class="eyes"></div> <div class="mouth"></div> <div class="whiskers"></div> <div class="whiskers"></div> <div class="whiskers"></div> </div> </body> </html> ``` 2. 接下来,我们来解释一下上面的代码: - 通过`position: relative`设置`#doraemon`为相对定位,以便于后面的绝对定位。 - 设置`width`和`height`为200px,使得`#doraemon`呈现为一个圆形。 - 设置`background-color`为#4d4d4d,使得`#doraemon`呈现为蓝色。 - 通过`border-radius: 100px`将`#doraemon`设置为圆形。 - 通过`overflow: hidden`将`#doraemon`内部的元素裁剪为圆形。 3. 接下来,我们需要用伪元素`::before`来实现哆啦A梦的脸部分: - 通过`content: ""`设置伪元素的内容为空。 - 通过`position: absolute`将伪元素绝对定位在`#doraemon`内部。 - 通过`top`和`left`属性将伪元素相对于`#doraemon`进行定位。 - 通过`width`和`height`设置伪元素的大小。 - 通过`background-color`设置伪元素的颜色。 - 通过`border-radius`将伪元素设置为圆形。 - 通过`transform: translate(30px, 30px)`将伪元素向右下方平移,实现哆啦A梦的脸颊。 4. 接下来,我们需要用`div`元素来实现哆啦A梦的眼睛: - 通过`position: absolute`将眼睛绝对定位在脸部内部。 - 通过`top`和`left`属性将眼睛相对于脸部进行定位。 - 通过`width`和`height`设置眼睛的大小。 - 通过`background-color`设置眼睛的颜色。 - 通过`border-radius`将眼睛设置为半圆形。 - 通过`overflow: hidden`将眼睛内部的元素裁剪为半圆形。 5. 接下来,我们需要用伪元素`::before`来实现哆啦A梦的眼珠: - 通过`content: ""`设置伪元素的内容为空。 - 通过`position: absolute`将伪元素绝对定位在眼睛内部。 - 通过`top`和`left`属性将伪元素相对于眼睛进行定位。 - 通过`width`和`height`设置伪元素的大小。 - 通过`background-color`设置伪元素的颜色。 - 通过`border-radius`将伪元素设置为圆形。 6. 接下来,我们需要用`div`元素来实现哆啦A梦的嘴巴: - 通过`position: absolute`将嘴巴绝对定位在脸部内部。 - 通过`top`和`left`属性将嘴巴相对于脸部进行定位。 - 通过`width`和`height`设置嘴巴的大小。 - 通过`border-radius`将嘴巴设置为半圆形。 - 通过`border-top`设置嘴巴的上边框。 - 通过`background-color`设置嘴巴的颜色。 - 通过`transform: rotate(-20deg)`将嘴巴旋转20度,使得它看起来更加生动。 7. 最后,我们需要用`div`元素和伪元素来实现哆啦A梦的小胡须: - 通过`position: absolute`将小胡须绝对定位在脸部内部。 - 通过`top`和`left`属性将小胡须相对于脸部进行定位。 - 通过`width`和`height`设置小胡须的大小。 - 通过`background-color`设置小胡须的颜色。 - 通过`transform: rotate(10deg)`将小胡须旋转10度,使得它看起来更加生动。 - 通过伪元素来实现小胡须的两端。 到这里,一个用HTML+CSS画的哆啦A梦就完成了。希望这个示例对你有所帮助!

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值