HTML+CSS 波浪式模糊文字特效
效果演示
实现了一个文字模糊消失的效果,包括一个容器(.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
* {
margin: 0;
padding: 0;
}
.container {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
background-color: #212121;
}
h2 {
display: flex;
font-size: 160px;
color: #fff;
text-align: center;
text-transform: uppercase;
cursor: pointer
}
h2 span {
transition: 1.5s;
}
h2:hover span {
filter: blur(20px);
opacity: 0;
transform: scale(2);
}
h2 span:nth-child(1) {
transition-delay: 0.1s;
}
h2 span:nth-child(2) {
transition-delay: 0.2s;
}
h2 span:nth-child(3) {
transition-delay: 0.3s;
}
h2 span:nth-child(4) {
transition-delay: 0.4s;
}
h2 span:nth-child(5) {
transition-delay: 0.5s;
}
h2 span:nth-child(6) {
transition-delay: 0.6s;
}
h2 span:nth-child(7) {
transition-delay: 0.7s;
}
h2 span:nth-child(8) {
transition-delay: 0.8s;
}
h2 span:nth-child(9) {
transition-delay: 0.9s;
}
h2 span:nth-child(10) {
transition-delay: 1s;
}
实现思路拆分
* {
margin: 0;
padding: 0;
}
这段代码是设置所有元素的外边距和内边距为0。
.container {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
background-color: #000;
}
这段代码是设置容器的高度为100vh,使用flex布局,使其水平和垂直居中。同时设置overflow为hidden,使其超出部分隐藏。并且设置背景颜色为黑色。
h2 {
display: flex;
font-size: 160px;
color: #fff;
text-align: center;
text-transform: uppercase;
cursor: pointer
}
这段代码是设置标题的布局方式为flex,并且使其水平和垂直居中。同时设置字体大小为160px,颜色为白色,文本对齐方式为居中,文本转换为大写,鼠标指针为手型。
h2 span {
transition: 1.5s;
}
这段代码是设置标题中每个字母的过渡效果为1.5s。
h2:hover span {
filter: blur(20px);
opacity: 0;
transform: scale(2);
}
这段代码是设置当鼠标悬停在标题上时,标题中每个字母的模糊程度为20px,透明度为0,缩放为原来的2倍。
h2 span:nth-child(1) {
transition-delay: 0.1s;
}
h2 span:nth-child(2) {
transition-delay: 0.2s;
}
h2 span:nth-child(3) {
transition-delay: 0.3s;
}
h2 span:nth-child(4) {
transition-delay: 0.4s;
}
h2 span:nth-child(5) {
transition-delay: 0.5s;
}
h2 span:nth-child(6) {
transition-delay: 0.6s;
}
h2 span:nth-child(7) {
transition-delay: 0.7s;
}
h2 span:nth-child(8) {
transition-delay: 0.8s;
}
h2 span:nth-child(9) {
transition-delay: 0.9s;
}
h2 span:nth-child(10) {
transition-delay: 1s;
}
这段代码是设置标题中每个字母的过渡延迟时间,使其逐个消失。第一个字母的过渡延迟时间为0.1s,第二个字母的过渡延迟时间为0.2s,以此类推。
发表评论