HTML+CSS 波浪式模糊文字特效

admin 2024-08-11 125 阅读 0评论

效果演示

实现了一个文字模糊消失的效果,包括一个容器(.container)和一个标题(h2)。标题中的文字由多个span元素组成,通过鼠标悬停实现逐个消失的效果。整个容器背景颜色为黑色,使文字效果更加突出。

Code

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>波浪式模糊文字特效</title>
    <link rel="stylesheet" href="./40-波浪式模糊文字特效.css">
</head>

<body>
    <div class="container">
        <h2>
            <span></span>
            <span></span>
            <span></span>
            <span></span>
            <span>C</span>
            <span>S</span>
            <span>S</span>
        </h2>
    </div>
</body>

</html>
CSS
* {
    margin0;
    padding0;
}

.container {
    height100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    background-color#212121;
}

h2 {
    display: flex;
    font-size160px;
    color#fff;
    text-align: center;
    text-transform: uppercase;
    cursor: pointer
}

h2 span {
    transition1.5s;
}

h2:hover span {
    filterblur(20px);
    opacity0;
    transformscale(2);
}

h2 span:nth-child(1) {
    transition-delay0.1s;
}

h2 span:nth-child(2) {
    transition-delay0.2s;
}

h2 span:nth-child(3) {
    transition-delay0.3s;
}

h2 span:nth-child(4) {
    transition-delay0.4s;
}

h2 span:nth-child(5) {
    transition-delay0.5s;
}

h2 span:nth-child(6) {
    transition-delay0.6s;
}

h2 span:nth-child(7) {
    transition-delay0.7s;
}

h2 span:nth-child(8) {
    transition-delay0.8s;
}

h2 span:nth-child(9) {
    transition-delay0.9s;
}

h2 span:nth-child(10) {
    transition-delay1s;
}

实现思路拆分

* {
    margin0;
    padding0;
}

这段代码是设置所有元素的外边距和内边距为0。

.container {
    height100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    background-color#000;
}

这段代码是设置容器的高度为100vh,使用flex布局,使其水平和垂直居中。同时设置overflow为hidden,使其超出部分隐藏。并且设置背景颜色为黑色。

h2 {
    display: flex;
    font-size160px;
    color#fff;
    text-align: center;
    text-transform: uppercase;
    cursor: pointer
}

这段代码是设置标题的布局方式为flex,并且使其水平和垂直居中。同时设置字体大小为160px,颜色为白色,文本对齐方式为居中,文本转换为大写,鼠标指针为手型。

h2 span {
    transition1.5s;
}

这段代码是设置标题中每个字母的过渡效果为1.5s。

h2:hover span {
    filterblur(20px);
    opacity0;
    transformscale(2);
}

这段代码是设置当鼠标悬停在标题上时,标题中每个字母的模糊程度为20px,透明度为0,缩放为原来的2倍。

h2 span:nth-child(1) {
    transition-delay0.1s;
}

h2 span:nth-child(2) {
    transition-delay0.2s;
}

h2 span:nth-child(3) {
    transition-delay0.3s;
}

h2 span:nth-child(4) {
    transition-delay0.4s;
}

h2 span:nth-child(5) {
    transition-delay0.5s;
}

h2 span:nth-child(6) {
    transition-delay0.6s;
}

h2 span:nth-child(7) {
    transition-delay0.7s;
}

h2 span:nth-child(8) {
    transition-delay0.8s;
}

h2 span:nth-child(9) {
    transition-delay0.9s;
}

h2 span:nth-child(10) {
    transition-delay1s;
}

这段代码是设置标题中每个字母的过渡延迟时间,使其逐个消失。第一个字母的过渡延迟时间为0.1s,第二个字母的过渡延迟时间为0.2s,以此类推。

发表评论

快捷回复: 表情:
Addoil Applause Badlaugh Bomb Coffee Fabulous Facepalm Feces Frown Heyha Insidious KeepFighting NoProb PigHead Shocked Sinistersmile Slap Social Sweat Tolaugh Watermelon Witty Wow Yeah Yellowdog
提交
评论列表 (有 0 条评论, 125人围观)