发布时间:2025-12-10 12:54:17 浏览次数:1
HTML爱心跳动特效代码
代码如下:<html><head><title>HTML爱心跳动特效</title><style>.heart {width: 100px;height: 100px;position: relative;transform: rotate(45deg);margin: 20px;}.heart:before,.heart:after {content: "";background-color: #ff4060;border-radius: 50% 50% 0 0;position: absolute;}.heart:before {width: 100px;height: 100px;top: -50px;left: 0;}.heart:after {width: 100px;height: 100px;top: 0;left: 50px;}.heart:before {animation: heart-beat 1s ease-in-out infinite;}@keyframes heart-beat {0% {transform: scale(1);}10% {transform: scale(0.9);}20% {transform: scale(1);}40% {transform: scale(0.9);}60% {transform: scale(1);}80% {transform: scale(0.9);}100% {transform: scale(1);}}</style></head><body><p ></p></body></html>由于:before和: after选择器实际上是在一个p中嵌套了两个p,所以设置了一个position:relative属性。然后就可以通过animation属性来实现心形的跳动效果,这里是实现了一个关键帧的动画,通过控制transform的scale属性实现心形的缩放效果,从而实现整个心形的跳动效果。