CSS画心形

思路一:一个正方形盒子逆时针旋转45度,两个圆形定位在正方形顶角两侧

 代码部分:


    <style>
        div {
            position: relative;
            margin: 100px auto;
            width: 100px;
            height: 100px;
            background-color: lightcoral;
        }
        div::before {
            position: absolute;
            top: -50px;
            left: 0px;
            content: '';
            width: 100px;
            height: 100px;
            background-color: lightcoral;
            border-radius: 50%;

        }
        div::after {
            position: absolute;
            top: 0px;
            left: 50px;
            content: '';
            display: block;
            width: 100px;
            height: 100px;
            background-color: lightcoral;
            border-radius: 50%;
        }
        div {
            transform: rotate(-45deg);
        }
    </style>
</head>
<body>
    <div></div>
</body>

思路二: 一个正方形盒子和两个长和正方形一样,宽任意的长方形盒子左右旋转定位到两侧

 

 代码部分:

<style>
        div {
            position: relative;
            width: 150px;
            height: 150px;
            margin: 100px auto;
        }
        div::before,div::after {
            content: '';
            position: absolute;
            width: 105px;
            height: 150px;
            background-color: red;
            border-radius: 50% 50% 0 0;
        }
        div::before {
            left: 0;
            transform: rotate(312deg);
        }
        div::after {
            right: 0;
            transform: rotate(50deg);

        }
    </style>
</head>
<body>
    <div></div>
</body>

进阶:跳动的爱心

<!DOCTYPE html>
<html>

<head>
    <style>
        div{
            position:relative;
            margin-left:100px;
            margin-top:100px;
            width:150px;
            height:150px;
            /* border:1px solid green; */

            animation-name: ttt;
            animation-duration: 1s;
            animation-iteration-count: infinite;
        }

        div::before,div::after{
            content:'';
            position:absolute;
            width:105px;
            height:150px;
            border-radius: 50% 50% 0 0;
            /* border:1px solid black; */
            background-color:red;
        }
        div::before{
            left:0;
            /* background-color:blue; */
            transform: rotate(312deg);
        }
        div::after{
            right:0;
            /* background-color:yellow; */
            transform: rotate(50deg);

        }

        @keyframes ttt{
            0%{
                transform: scale(1);
            }
            30%{
                transform:scale(1.1);
            }
            50%{
                transform:scale(1);
            }
            75%{
                transform:scale(1.1);
            }
            83%{
                transform:scale(1);
            }
            100%{
                transform:scale(1.1);
            }
        }
    </style>
</head>

<body>
    <div></div>
</body>

</html>

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值