css案例:小黄人案例

css案例:小黄人案例

  1. 先看效果图
    眼睛和嘴巴有做动画的,但是我懒得上传gif了。
    在这里插入图片描述3. 源码 html
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<style>
		.contain {
			width: 400px;
			height: 600px;
			border: 1px solid #000;
			margin: 0 auto;

			position: relative;
			z-index: -2;
			background-color: pink;
		}
		/* 身体 */
		.body {
			width: 250px;
			height: 400px;
			background-color: #FBF404;
			border: 5px solid #000;
			border-radius: 120px;
			box-shadow: 6px 0px 6px rgba(0, 0, 0, 0.3);
			position: absolute;
			top: 50%;
			left: 50%;
			transform: translate(-50%, -50%);
			overflow: hidden;
		}
		/* 头发 */
		.hair_l,
		.hair_r {
			width: 130px;
			height: 100px;
			/* background-color: #000; */
			border-top: 10px solid #000;
			border-radius:50%;
			position: absolute;
			transform: rotate(48deg);
			z-index: -1;

		}
		.hair_l {
			top: 89px;
			left: 98px;
		}
		.hair_r {
			top: 80px;
			left: 99px;
		}
		/* 眼睛 */
		.eyes {
			width: 100%;
			height: 100px;
			/* border: 1px solid #000; */
			position: absolute;
			top: 75px;
			overflow: hidden;
		}
		/* 眼戴直接用父亲伪元素做 */
		.eyes::before {
			content: "";
			width: 60px;
			height: 20px;
			background-color: #000;
			position: absolute;
			top: 31px;
			left: -15px;
			transform: rotate(25deg);
		}

		.eyes::after {
			content: "";
			width: 60px;
			height: 20px;
			background-color: #000;
			position: absolute;
			top: 31px;
			right: -15px;
			transform: rotate(-25deg);
		}

		/* 大眼眶 */
		.eyes .eyes_l,
		.eyes .eyes_r {
			width: 90px;
			height: 90px;
			border-radius: 50%;
			border: 5px solid #000;
			position: absolute;
			background-color: #fff;
			z-index: 999;
		}
		.eyes .eyes_l {
			left: 25px;
		}
		.eyes .eyes_r {
			right: 25px;
		}
		/* 黑眼珠 */
		.eyes .eyes_l .black_l,
		.eyes .eyes_r .black_r {
			width: 50px;
			height: 50px;
			background-color: #000;
			border-radius: 50%;
			position: absolute;
			top: 20px;
			left: 20px;
			/* 如果用transform定位,再加动画时这个定位就失效了 */
			/* transform: translate(-50%, -50%); */
			/* animation: eye 3s ease infinite; */

		}
		
		/* 白眼珠 */
		.eyes .eyes_l .black_l .white_l,
		.eyes .eyes_r .black_r .white_r {
			width: 20px;
			height: 20px;
			background: #fff;
			border-radius: 50%;
			position: absolute;
			top: 15px;
			
            
		}
		.eyes .eyes_l .black_l .white_l {
			left: 23px;
		}
		.eyes .eyes_r .black_r .white_r {
            left: 6px;
		}
		/* 嘴巴 */
		.mouth {
			width: 80px;
			height: 40px;
			background-color: #fff;
			position: absolute;
			border: 5px solid #000;
			top: 190px;
			left: 80px;
			border-radius: 0 0 45px 45px;
		}
		.mouth::before {
			content: "";
			width: 5px;
			height: 40px;
			background-color: #000;
			position: absolute;
			left: 20px;
		}
		.mouth::after {
			content: "";
			width: 5px;
			height: 40px;
			background-color: #000;
			position: absolute;
			left: 52px;
		}
		
		/* 手臂 */
		.hand_l,
		.hand_r {
			width: 100px;
			height: 100px;
			border: 5px solid #000;
			background-color: #FBF404;
			border-radius: 24px;
			position: absolute;
			top: 300px;		
			z-index: -1;
			

		}
		.hand_l {
			transform: rotate(45deg);
			left:50px;

		}
		.hand_r {
			transform: rotate(-45deg);
			right: 50px;
		}
		.hand_l::after,
		.hand_r::after {
			content: "";
			width: 20px;
			height: 20px;
			background-color: #000;
			border-radius: 7px;
			position: absolute;
			top: 64px;
			/* z-index: 9999; */


		}
		.hand_l::after {
           left: 18px;
		}
		.hand_r::after {
			right: 18px;

		}

		/* 衣服 */
		.clothes {
			width: 260px;
			height: 140px;
			/* border: 1px solid #000; */
			position: absolute;
			bottom: 0;
			left: -5px;
		}
		/* 衣服肩带 */
		.clothes .clothes_jl {
			content: "";
			width: 110px;
			height: 15px;
			border: 5px dashed #000;
			background-color: blue;
			position: absolute;
			top:-15px;
			left: -22px;
			z-index: 2;
			transform: rotate(24deg);

		}
		.clothes .clothes_jr {
			content: "";
			width: 110px;
			height: 15px;
			border: 5px dashed #000;
			background-color: blue;
			position: absolute;
			top:-15px;
			right: -22px;
			z-index: 2;
			transform: rotate(-24deg);

		}
		/* 肩带圆点 */
		.clothes .clothes_jl::after {
			content: "";
			width: 10px;
			height: 10px;
			background-color: #000;
			border-radius: 50%; 
			position: absolute;
			top: 2px;
			right: 3px;
		}
		.clothes .clothes_jr::after {
			content: "";
			width: 10px;
			height: 10px;
			background-color: #000;
			border-radius: 50%; 
			position: absolute;
			top: 2px;
			left: 3px;

		}
		.clothes .clothes_t {
			width: 100px;
			height: 40px;
			background-color: blue;
			border: 5px dashed #000;
			border-bottom: 0;
			position: absolute;
			left: 50%;
			transform: translate(-50%, 0);
			z-index: 1;

		}
		.clothes .clothes_b {
			width: 100%;
			height: 100px;
			background-color: blue;
			border: 5px dashed #000;
			position: absolute;
			bottom: -10px;

		}
		/* 口袋 */
		.clothes .clothes_k {
			width: 80px;
			height: 50px;
			background-color: blue;
			border-radius: 0 0 25px 25px;
			border: 3px dashed #000;
			position: absolute;
			top: 60px;
			left: 88px;
		}
		/* 口袋里面的圆形 */
		.clothes .clothes_k .clothes_k_y {
			content: "";
			width: 30px;
			height: 30px;
			border-radius: 50%;
			/* background-color: ; */
			background-color: #000;
			border: 2px dashed #000;
			position: absolute;
			top: 50%;
			left: 50%;
			transform: translate(-50%, -50%);

		}
		 /* .clothes_k .clothes_k_y {
			background-color: yellow;
		} */
		/* 正方形 */
		.clothes .clothes_k .clothes_k_y::after {
			content: "";
			width: 20px;
			height: 20px;
			background-color: blue;
			border: 2px solid #000;
			position: absolute;
			top: 3px;
			left: 3px;
			transform: rotate(45deg);


		}
		/* 小圆点 */
		.clothes .clothes_k .clothes_k_y::before {
			content: "";
			width: 10px;
			height: 10px;
			border-radius: 50%;
			background-color: #000;
			position: absolute;
			top: 10px;
			left: 10px;
			z-index: 999;
		}
		/* 脚部 */
		.foot .foot_l,
		.foot .foot_r {
			width: 30px;
			height: 80px;
			background-color: #000;

			position: absolute;
			bottom: 80px;
			z-index: -1;		
		}

		.foot .foot_l {
			left: 165px;

		}
		.foot .foot_r {
			left: 220px;

		}
		.foot .foot_l::after,
		.foot .foot_r::after {
			content: "";
			width: 60px;
			height: 30px;
			background-color: #000;
			box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.3);
			position: absolute;
			bottom: -30px;
					
		}
		.foot .foot_l::after {
			left: -30px;
			border-radius: 15px 0 0 15px;
		}
		.foot .foot_r::after {
			right: -30px;
			border-radius: 0px 15px 15px 0px;
		}
		/* 动画 */
		/* 黑眼珠动画 */
		.eyes .black_l,
		.eyes .black_r {
          animation: black_eye 3s infinite;
		}
		@keyframes black_eye {
			0% {
				transform: translate(0, 0);
			}
			25% {
				transform: translate(18px, 0);
			}
			50% {
				transform: translate(0px, 0);
			}
			75% {
				transform: translate(-18px, 0);
			}
			100% {
				transform: translate(0px, 0);
			}

		}
		/* 白眼珠动画 */
		.eyes .black_l .white_l,
		.eyes .black_r .white_r {
			animation: white_eye 3s infinite;
		}
		@keyframes white_eye {
			0% {
				transform: translate(0, 0);
			}
			25% {
				transform: translate(0px, 5px);
			}
			50% {
				transform: translate(0px, 0);
			}
			75% {
				transform: translate(0px, -5px);
			}
			100% {
				transform: translate(0px, 0);
			}

		}
		/* 手臂动画 */
		.hand_l{
			animation: hand_l_mov 3s linear infinite;
		}
		@keyframes hand_l_mov {
			0% {
				transform: rotate(45deg);
			}
			25% {
				transform: rotate(52deg);
				
			}
			50% {
				transform: rotate(45deg);
				
			}
			75% {
				transform: rotate(52deg);
				
			}
			100% {
				transform: rotate(45deg);
				
			}

		}

		.hand_r{
			animation: hand_r_mov 3s linear infinite;
		}
		@keyframes hand_r_mov {
			0% {
				transform: rotate(-45deg);
			}
			25% {
				transform: rotate(-52deg);
				
			}
			50% {
				transform: rotate(-45deg);
				
			}
			75% {
				transform: rotate(-52deg);
				
			}
			100% {
				transform: rotate(-45deg);
				
			}

		}
		/* 头发动画 */
		.hair_l,.hair_r {
			animation: hair_mov 3s linear infinite;
		}
		@keyframes hair_mov {
			0% {
				transform: rotate(48deg);
			}
			25% {
				transform: rotate(55deg);
				
			}
			50% {
				transform: rotate(48deg);
				
			}
			75% {
				transform: rotate(55deg);
				
			}
			100% {
				transform: rotate(48deg);
				
			}

		}
		/* 嘴巴动画 */
		.mouth {
			animation: mouth_mov 1s linear infinite;
		}

       		@keyframes mouth_mov {
			0% {
				transform: translate(0, 0);
			}
			25% {
				transform: translate(0px, 5px);
			}
			50% {
				transform: translate(0px, 0);
			}
			75% {
				transform: translate(0px, -5px);
			}
			100% {
				transform: translate(0px, 0);
			}

		}



	</style>
</head>
<body>
<!-- 小黄人容器 -->
	<div class="contain">
	   <!-- 身体 -->
		<div class="body">	
		<!-- 眼睛 -->
          <div class="eyes">
          <div class="eyes_l">
          	<div class="black_l">
          		<div class="white_l">	</div>
          	</div>
          </div>
          <div class="eyes_r">
          	<div class="black_r">
          		<div class="white_r">	</div>
          	</div>
          </div>

          </div>
          <!-- 嘴巴 -->
          <div class="mouth">	</div>
          <!-- 衣服 -->
          <div class="clothes">
          <!-- 上部 -->
          	<div class="clothes_t"></div>
          	<!-- 下部 -->
          	<div class="clothes_b"></div>
          	<!-- 口袋 -->
          	<div class="clothes_k">
          		<div class="clothes_k_y">
          			
          		</div>
          	</div>
          	<!-- 肩带 -->
          	<div class="clothes_jl"></div>
          	<div class="clothes_jr"></div>

          </div>
		</div>
		<!-- 头发 -->
		<div class="hair">
			<div class="hair_l"></div>
			<div class="hair_r"></div>

		</div>
		<!-- 手臂 -->
		<div class="hand">
			<div class="hand_l"></div>
			<div class="hand_r"></div>
		</div>
		<!-- 脚部 -->
		<div class="foot">
			<div class="foot_l">
				
			</div>
			<div class="foot_r">
				
			</div>
		</div>
	</div>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
黄人动画是一个非常有趣的CSS动画,可以通过CSS3中的一些特性来实现。以下是一个基本的小黄人动画的CSS代码: ```css /* 设置小黄人动画的容器 */ .minion { position: relative; width: 250px; height: 250px; } /* 设置小黄人的身体 */ .minion .body { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 100px; height: 100px; border-radius: 50%; background-color: yellow; } /* 设置小黄人的眼睛 */ .minion .eye { position: absolute; top: 30%; left: 25%; width: 20px; height: 20px; border-radius: 50%; background-color: white; } /* 设置小黄人眼睛里的黑色部分 */ .minion .eye::before { content: ''; display: block; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 10px; height: 10px; border-radius: 50%; background-color: black; } /* 设置小黄人眼睛的另一只 */ .minion .eye.right { left: auto; right: 25%; } /* 设置小黄人的嘴巴 */ .minion .mouth { position: absolute; top: 60%; left: 50%; transform: translate(-50%, -50%); width: 40px; height: 20px; border-radius: 0px 0px 20px 20px; border-bottom: solid black 3px; } /* 设置小黄人的带子 */ .minion .goggles { position:absolute; top:-10px; left:-10px; width:120px; height:120px; border-radius:50%; border:10px solid #2D2D2D; background-color:white; } /* 设置小黄人的带子上面的金属部分 */ .minion .goggles::before { content:""; display:block; position:absolute; top:-8px; left:-8px; width:10px; height:10px; border-radius:50%; background-color:#B8B8B8; } /* 设置小黄人的带子下面的金属部分 */ .minion .goggles::after { content:""; display:block; position:absolute; bottom:-8px; right:-8px; width:10px; height:10px; border-radius:50%; background-color:#B8B8B8 } /* 定义小黄人动画的关键帧 */ @keyframes rotate { from { transform : rotate(0deg); } to { transform : rotate(360deg); } } /* 设置小黄人动画 */ .minion:hover .goggles, .minion:hover .eye::before { animation-name: rotate; /* 使用刚才定义的关键帧 */ animation-duration:2s; /* 持续时间为2秒 */ animation-timing-function: linear; /* 时间函数为线性 */ animation-iteration-count: infinite; /* 循环无限次 */ } ```

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值