案例1- 跳动的心

一颗正在跳动的心

案例思路演示

再通过添加动画效果以达到完成心形构建目的

环境构建

html 复制代码
<!DOCTYPE html>
<html lang="zh">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>跳动的心</title>

    <style>
      /* 初始化页面 */
      html,body{
      width: 100%;
      height: 100%;
      }

      body{
      background-color: pink;
      /* 设置父级元素元素变成了一个弹性容器,直接子元素变成弹性子元素 */
      display: flex;
      /* 定义主轴为水平方向 */
      flex-direction: row;
      /* 子项居中对齐在容器的主轴 */
      justify-content: center;
      /* 子项在容器中垂直居中 */
      align-items: center;
      }
      .heart{
      width: 200px;
      height: 200px;
      background-color: red;
      position: relative;
      }
      .heart .b{
      content:"";
      width: 200px;
      height: 100px;
      background-color: yellow;
      position: absolute;
      left: 0;
      top: -100px;

      }
      .heart .a{
      content:"";
      width: 100px;
      height: 200px;
      background-color: yellow;
      position: absolute;
      left: -100px;
      top: 0;
      }


    </style>

  </head>

  <body>
    <div class="heart">
      <div class="a"></div>
      <div class="b"></div>
    </div>
  </body>
</html>

a 和 b 圆角化

html 复制代码
border-radius: 100px 0 0 100px;

border-radius: 100px 100px 0 0 ;

父容器 旋转45度

html 复制代码
transform: rotate(45deg);

动画效果

html 复制代码
/* 让心跳动起来 */
@keyframes heartbit{
  0%{
    transform: rotate(45deg) scale(0.6);
  }
  100%{
    transform: rotate(45deg) scale(1.4);
  }
}

父容器 实现动画效果
animation: heartbit 1s alternate infinite;

添加阴影效果

html 复制代码
box-shadow: 0 0 30px red;

完成后代码

html 复制代码
<!DOCTYPE html>
<html lang="zh">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>跳动的心</title>
	
	<style>
		/* 初始化页面 */
			html,body{
				width: 100%;
				height: 100%;
			}
		
			body{
				background-color: pink;
				/* 设置父级元素元素变成了一个弹性容器,直接子元素变成弹性子元素 */
				display: flex;
				/* 定义主轴为水平方向 */
				flex-direction: row;
				/* 子项在容器中垂直居中 */
				align-items: center;
				/* 子项居中对齐在容器的主轴 */
				justify-content: center;
			}
			.heart{
				width: 200px;
				height: 200px;
				background-color: red;
				position: relative;
				transform: rotate(45deg);
				animation: heartbit 1s alternate infinite;
				box-shadow: 0 0 30px red;
				
			}
			.heart .b{
				width: 200px;
				height: 100px;
				background-color: red;
				position: absolute;
				left: 0;
				top: -99px;
				border-radius: 100px 100px 0 0;
				box-shadow: 0 0 30px red;
				
			}
			.heart .a{
				width: 100px;
				height: 200px;
				background-color: red;
				position: absolute;
				left: -99px;
				top: 0;
				border-radius: 100px 0 0 100px;
				box-shadow: 0 0 30px red;
			}
			
			/* 让心跳动起来 */
			@keyframes heartbit{
				0%{
					transform: rotate(45deg) scale(0.6);
				}
				100%{
					transform: rotate(45deg) scale(1.4);
				}
			}
		
		
	</style>
	
</head>

<body>
	<div class="heart">
		<div class="a"></div>
		<div class="b"></div>
	</div>
</body>
</html>
相关推荐
2301_796512526 分钟前
【精通篇】打造React Native鸿蒙跨平台开发高级复合组件库开发系列:Lazyload 懒加载(懒加载的图片)
前端·javascript·react native·react.js·ecmascript·harmonyos
敲敲了个代码12 分钟前
从N倍人力到1次修改:Vite Plugin Modular 如何拯救多产品前端维护困境
前端·javascript·面试·职场和发展·typescript·vite
摘星编程15 分钟前
OpenHarmony环境下React Native:Timeline时间轴组件
javascript·react native·react.js
摘星编程17 分钟前
在OpenHarmony上用React Native:Timeline水平时间轴
javascript·react native·react.js
干前端37 分钟前
Vue3 组件库工程化实战:BEM 命名规范与 useNamespace 深度解析
前端·css
bigdata-rookie1 小时前
Starrocks 数据模型
java·前端·javascript
RFCEO1 小时前
前端编程 课程十四、:CSS核心基础2:选择器优先级 + 伪类选择器(解决冲突+交互效果)
前端·css·交互·css选择器优先级判断规则详解·css important使用·css链接伪类lvha顺序·实现悬浮交互效果
web打印社区1 小时前
前端实现浏览器预览打印:从原生方案到专业工具
前端·javascript·vue.js·electron
yuezhilangniao1 小时前
# 告别乱码:用FastAPI特性与Next.js打造类型安全的API通信
javascript·安全·fastapi
徐同保1 小时前
vue.config.ts配置代理解决跨域,配置开发环境开启source-map
前端·javascript·vue.js