送你一朵小红花,CSS实现一朵旋转的小红花

13 篇文章 3 订阅
4 篇文章 13 订阅

送你一朵小红花,愿你勇敢的面对生活中的苦难,不要放弃爱与希望,蓝天白云,定会如期而至。

视频:

B站视频链接:https://www.bilibili.com/video/BV1xX4y1M7yM

送你一朵小红花,CSS实现一朵旋转的小红花

HTML

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>送你一朵小红花:公众号AlbertYang</title>
    <link rel="stylesheet" href="style.css">
</head>

<body>
    <!-- 容器 -->
    <div class="box">
        <!-- 花朵 -->
        <div class="flower">
            <!-- 花瓣 -->
            <div class="petal" style="--x:0"></div>
            <div class="petal" style="--x:1"></div>
            <div class="petal" style="--x:2"></div>
            <div class="petal" style="--x:3"></div>
            <div class="petal" style="--x:4"></div>
            <div class="petal" style="--x:5"></div>
            <!-- 花心 -->
            <div class="circle"></div>
        </div>
    </div>
</body>

</html>

CSS

/* 清除浏览器设置的默认边距,
使边框和内边距的值包含在元素的width和height内 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
/* 使用flex布局,让内容垂直和水平居中 */
.box {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}
/* 花朵 */
.flower {
    position: relative;
    width: 80px;
    height: 80px;
    transform-origin:  100% 100%;
    animation: rotate 3s linear infinite;
}
/* 花瓣 */
.petal {
    display: block;
    /* 花瓣的宽高等于花朵的宽高 */
    width: 80px;
    height: 80px;
    background: red;
    border-radius: 0 70px;
    position: absolute;
    /* 让不同的花瓣旋转为花朵 */
    transform-origin: 100% 100%;
    transform: rotate(calc(var(--x) * 60deg));
}
/* 花心 */
.circle {
    width: 100px;
    height: 100px;
    position: absolute;
    background: #fff200;
    border-radius: 50%;
    left: 30px;
    top: 30px;
    box-shadow: 0 0 50px yellow;
    background-image: radial-gradient(at 20% 30%, #fffa65, #f1c40f, #f1dc4b);
}
/* 花朵旋转动画 */
@keyframes rotate {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

今天的学习就到这里了,由于本人能力和知识有限,如果有写的不对的地方,还请各位大佬批评指正。有什么不明白的地方欢迎给我留言,如果想继续学习提高,欢迎关注我,每天进步一点点,就是领先的开始,加油。如果觉得本文对你有帮助的话,欢迎转发,评论,点赞!!!

  • 83
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 19
    评论
评论 19
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Albert Yang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值