小霆教程网-小霆博客bolg小霆教程网-小霆博客bolg

新年了,给网站加个灯笼吧!html+css教程

转眼间2021的新年已经如期而至,昨日在逛博客时,发现有些同行站点已经挂起了灯笼!

笔者觉得很有创意,于是去网上找了下源代码,果然是有的!

参考了源码的原理 自己写了一个出来,挂在博客上还是很漂亮的,如下图:

QQ截图20210209195221.png

​下方提供视频教程

下方提供源代码

html代码

<div class="box">
<div class="light">
    <div class="line"></div>
    <div class="light-a">
        <div class="light-b"></div>
        <div class="light-c">
            <!-- 在此元素内添加需要显示的文字 -->
            新
        </div>
        <div class="ear-a">
            <div class="ear-b"></div>
            <div class="ear-c"></div>
        </div>
    </div>
    
</div>

</div>

css代码

    /* 清楚盒子内外边距 */
* {
    padding: 0;
    margin: 0;
}

.box {
    /* 添加一个固定定位,可以让网页在滚动时灯笼固定不动 */
    position: fixed;
    top: 100px;
    left: 100px;
}

.box .light {
    animation: dong-light 3s infinite linear;
}

.box .light .line {
    position: absolute;
    left: 50%;
    top: -30px;
    transform: translateX(-50%);
    width: 2px;
    height: 20px;
    background-color: red;
}

/* 灯笼主体 */
.box .light .light-a {
    width: 150px;
    height: 120px;
    background-color: red;
    border-radius: 50%;
    /* 给灯笼添加一个投影,让其看起来像东灯光 */
    box-shadow: 5px 5px 70px 5px rgba(255, 0, 0, 1);
}

/* 添加两个伪元素 制作灯笼上下的两个模块 */
.box .light .light-a::before {
    content: '';
    position: absolute;
    left: 50%;
    top: -10px;
    transform: translateX(-50%);
    width: 80px;
    height: 20px;
    border-radius: 50% 50% 0 0;
    /* 添加一个渐变色,颜色已经提前准备好 */
    background: linear-gradient(to right,#dc8f03, #ffa500, #dc8f03, #ffa500, #dc8f03);
    /* 增加元素等级 让元素在上方 */
    z-index: 3;
}

.box .light .light-a::after {
    content: '';
    position: absolute;
    left: 50%;
    bottom: -10px;
    transform: translateX(-50%);
    width: 80px;
    height: 20px;
    border-radius: 0 0 50% 50%;
    /* 添加一个渐变色,颜色已经提前准备好 */
    background: linear-gradient(to right,#dc8f03, #ffa500, #dc8f03, #ffa500, #dc8f03);
    /* 增加元素等级 让元素在上方 */
    z-index: 3;
}

/* 开始制作灯笼内部的线条 */
.box .light .light-b {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: 120px;
    height: 120px;
    border-radius: 50%;
    border: 2px solid #ffa500;
}

.box .light .light-c {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 120px;
    border-radius: 50%;
    border: 2px solid #ffa500;
    /* 文字水平居中 */
    text-align: center;
    /* 文字垂直居中 */
    line-height: 120px;
    /* 字体大小 */
    font-size: 60px;
    /* 字体 */
    font-family: '华文行楷';
    /* 颜色 */
    color: #ffa500;
}

.box .light .ear-a {
    position: absolute;
    bottom: -30px;
    left: 50%;
    transform: translateX(-50%);
    width: 5px;
    height: 20px;
    background-color: #ffa500;
    animation: dong-ear 3s infinite linear;
}

.box .light .ear-b {
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: red;
    z-index: 2;
}

.box .light .ear-c {
    position: absolute;
    bottom: -40px;
    left: 50%;
    transform: translateX(-50%);
    width: 10px;
    height: 40px;
    border-radius: 10px 10px 0 10px;
    background-color: #ffa500;
}

/* 开始绘制动画 */
@keyframes dong-light {
    0% {
        transform: rotate(-10deg);
    }
    50% {
        transform: rotate(10deg);
    }
    100% {
        transform: rotate(-10deg);
    }
}

@keyframes dong-ear {
    0% {
        transform: rotate(10deg);
    }
    50% {
        transform: rotate(-10deg);
    }
    100% {
        transform: rotate(10deg);
    }
}

需要技术支持可以联系笔者QQ:727859088

本原创文章未经允许不得转载 | 当前页面:小霆教程网-小霆博客bolg » 新年了,给网站加个灯笼吧!html+css教程

评论 1

  1. 共享博客

    写的666呀

    共享博客 2021-02-20    回复