<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>纯CSS3边框按钮悬停特效</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: #f5f5f5;
font-family: 'Arial', sans-serif;
flex-direction: column;
padding: 20px;
}
h1 {
margin-bottom: 50px;
color: #333;
text-align: center;
}
.button-container {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 30px;
max-width: 800px;
margin-bottom: 50px;
}
.btn {
position: relative;
padding: 15px 30px;
font-size: 18px;
text-transform: uppercase;
letter-spacing: 2px;
text-decoration: none;
color: #333;
background: transparent;
border: none;
cursor: pointer;
transition: all 0.3s ease;
overflow: hidden;
z-index: 1;
}
/* 特效1: 边框从中间展开 */
.btn-1 {
border: 2px solid transparent;
}
.btn-1:hover {
border-color: #ff4757;
}
.btn-1::before {
content: '';
position: absolute;
top: 0;
left: 50%;
width: 0;
height: 100%;
background: #ff4757;
transition: all 0.3s ease;
z-index: -1;
}
.btn-1:hover::before {
left: 0;
width: 100%;
}
/* 特效2: 四角边框动画 */
.btn-2 {
border: none;
}
.btn-2::before,
.btn-2::after {
content: '';
position: absolute;
width: 0;
height: 2px;
background: #2ed573;
transition: all 0.3s ease;
}
.btn-2::before {
top: 0;
left: 0;
}
.btn-2::after {
bottom: 0;
right: 0;
}
.btn-2:hover::before,
.btn-2:hover::after {
width: 100%;
}
.btn-2 span::before,
.btn-2 span::after {
content: '';
position: absolute;
width: 2px;
height: 0;
background: #2ed573;
transition: all 0.3s ease;
}
.btn-2 span::before {
top: 0;
right: 0;
}
.btn-2 span::after {
bottom: 0;
left: 0;
}
.btn-2:hover span::before,
.btn-2:hover span::after {
height: 100%;
}
/* 特效3: 边框流光效果 */
.btn-3 {
border: 2px solid transparent;
position: relative;
}
.btn-3::before {
content: '';
position: absolute;
top: -2px;
left: -2px;
right: -2px;
bottom: -2px;
z-index: -1;
background: linear-gradient(45deg, #ff0, #f0f, #0ff, #0f0, #00f);
background-size: 400%;
opacity: 0;
transition: 0.5s;
}
.btn-3:hover::before {
opacity: 1;
animation: animate 8s linear infinite;
}
@keyframes animate {
0% {
background-position: 0 0;
}
50% {
background-position: 300% 0;
}
100% {
background-position: 0 0;
}
}
/* 特效4: 3D边框效果 */
.btn-4 {
border: 2px solid #3742fa;
color: #3742fa;
transition: all 0.3s;
}
.btn-4:hover {
box-shadow: 5px 5px 0 #ff6b81, -5px -5px 0 #2ed573;
transform: translate(2px, 2px);
}
/* 特效5: 边框填充效果 */
.btn-5 {
border: 2px solid #ffa502;
position: relative;
overflow: hidden;
}
.btn-5::before {
content: '';
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background: #ffa502;
transition: all 0.3s;
z-index: -1;
}
.btn-5:hover::before {
left: 0;
}
.btn-5:hover {
color: white;
}
/* 特效6: 双边框效果 */
.btn-6 {
border: 2px solid #5352ed;
position: relative;
}
.btn-6::after {
content: '';
position: absolute;
top: 5px;
left: 5px;
right: 5px;
bottom: 5px;
border: 2px solid #ff6348;
opacity: 0;
transition: all 0.3s;
}
.btn-6:hover::after {
opacity: 1;
top: -5px;
left: -5px;
right: -5px;
bottom: -5px;
}
.link {
margin-top: 50px;
}
.link a {
color: #5352ed;
text-decoration: none;
font-weight: bold;
padding: 10px 20px;
border: 2px solid #5352ed;
border-radius: 30px;
transition: all 0.3s;
}
.link a:hover {
background: #5352ed;
color: white;
}
</style>
</head>
<body>
<h1>纯CSS3边框按钮悬停特效</h1>
<div class="button-container">
<button class="btn btn-1">边框展开</button>
<button class="btn btn-2"><span>四角边框</span></button>
<button class="btn btn-3">流光边框</button>
<button class="btn btn-4">3D边框</button>
<button class="btn btn-5">填充边框</button>
<button class="btn btn-6">双边框</button>
</div>
<div class="link">
</div>
</body>
</html>

被折叠的 条评论
为什么被折叠?



