简单html+css的案例:跳动的心

零、前言

本案例来源于B站尚学堂“【HTML+CSS+JS+Vue】比大学课程还详细的Web前端教程,整整180集,学完即可兼职就业!附学习文档PDF,随时都能学_前端开发_WEB入门”课程案例。

一、绘制心形思路

我们先将心分割为下列三个部分,一个正方形和两个半圆形

为了减少DOM元素,我们可以通过:before:after两个伪元素

接下来就简单了,我们需要将“心”进行旋转45度,将“心”放正

温馨提示

让半圆与正方形进行重合,避免元素中间出现细线~

二、HTML结构

<div class="heart"></div>

三、CSS样式

* {
    margin: 0;
    padding: 0;
}
html,
body {
    height: 100%;
    width: 100%;
}
body {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    background-color: pink;
}
.heart {
    width: 200px;
    height: 200px;
    background: red;
    position: relative;
    transform: rotate(45deg);
}
.heart::before {
    content: '';
    width: 200px;
    height: 100px;
    background: red;
    position: absolute;
    left: 0;
    top: -99px;
    border-radius: 100px 100px 0 0;
}
.heart::after {
    content: '';
    width: 100px;
    height: 200px;
    background: red;
    position: absolute;
    left: -99px;
    top: 0;
    border-radius: 100px 0 0 100px;
}

四、跳动的心_跳动起来

让心跳动起来,可以使用CSS3动画实现,利用缩放实现跳动

我们可以在添加一些阴影效果,让“心”看起来更美观

*{
    margin: 0;
    padding: 0;
}
html,body{
    height: 100%;
    width: 100%;
}
body {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    background-color: pink;
}
.heart {
    width: 200px;
    height: 200px;
    background: red;
    position: relative;
    transform: rotate(45deg);
    animation: heartbit 1s alternate infinite;
    box-shadow: 0 0 30px red;
}
.heart::before {
    content: '';
    width: 200px;
    height: 100px;
    background: red;
    position: absolute;
    left: 0;
    top: -99px;
    border-radius: 100px 100px 0 0;
    box-shadow: 0 0 30px red;
}
.heart::after {
    content: '';
    width: 100px;
    height: 200px;
    background: 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);
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值