演示

原理
- 使用元素包裹按钮;
- 按钮设置为玻璃质感,设置光标悬停动画;
- 使用元素的before和after两个元素作为背景灯光,设置光标悬停动画;
代码
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<title>玻璃背光按钮title>
<style>
* {
padding: 0;
margin: 0;
user-select: none;
box-sizing: border-box;
}
html,
body {
height: 100vh;
}
style>
<style>
body {
display: flex;
background-color: #333947;
align-items: center;
justify-content: center;
}
.btn {
width: 200px;
height: 50px;
margin: 20px;
}
.btn>button {
width: 100%;
height: 100%;
font-size: 20px;
color: white;
box-shadow: 0 15px 15px rgba(0, 0, 0, 0.25);
background: rgba(255, 255, 255, 0.05);
border-radius: 25px;
border: none;
border-top: 1px solid rgba(255, 255, 255, 0.1);
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.btn>button:focus {
outline: none;
}
style>
<style>
.btn>button {
position: relative;
overflow: hidden;
transition: 0.3s;
}
.btn>button:hover {
letter-spacing: 3px;
}
.btn>button::before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 50%;
height: 100%;
background: linear-gradient(to right, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.15));
transform: skewX(45deg);
transition: 0.3s;
}
.btn>button:hover:before {
transform: translateX(200%);
}
style>
<style>
.btn>button {
backdrop-filter: blur(10px);
}
.btn {
position: relative;
}
.btn::before,
.btn::after {
content: "";
position: absolute;
left: 50%;
transform: translateX(-50%);
width: 40px;
height: 10px;
border-radius: 5px;
transition: 0.3s;
z-index: -1;
}
.btn:nth-child(1)::before,
.btn:nth-child(1)::after {
background: #ffa502;
}
.btn:nth-child(2)::before,
.btn:nth-child(2)::after {
background: #1e90ff;
}
.btn::before {
top: -5px;
}
.btn::after {
bottom: -5px;
}
.btn:hover::before,
.btn:hover::after {
height: 50%;
width: 90%;
border-radius: 25px;
transition-delay: 0.3s;
}
.btn:hover::before {
top: 0px;
border-radius: 25px 25px 0 0;
}
.btn:hover::after {
bottom: 0px;
border-radius: 0 0 25px 25px;
}
style>
head>
<body>
<div class="btn"><button>BUTTONbutton>div>
<div class="btn"><button>BUTTONbutton>div>
body>
html>

- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156