纯CSS实现动态炫酷按钮
以下是一个使用纯CSS创建动态炫酷按钮的示例代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>动态炫酷按钮</title>
<style>
.button {
position: relative;
background-color: #4CAF50;
border: none;
font-size: 28px;
color: white;
padding: 20px;
width: 200px;
text-align: center;
text-decoration: none;
display: inline-block;
margin: 4px 2px;
cursor: pointer;
transition: transform 0.2s;
}
.button:active {
transform: scale(0.95);
}
.button::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(255, 255, 255, 0.4);
mix-blend-mode: multiply;
opacity: 0;
transition: opacity 0.5s ease-in-out;
}
.button:hover::before {
opacity: 1;
}
.button::after {
content: '►';
position: absolute;
top: 35%;
right: 30%;
color: white;
font-size: 30px;
transform: translate(-50%, -50%);
opacity: 0;
transition: opacity 0.5s ease-in-out;
}
.button:hover::after {
opacity: 1;
}
</style>
</head>
<body>
<button class="button">点击我</button>
</body>
</html>
这段代码定义了一个带有动画效果的按钮,当鼠标悬停时,按钮本身会缩小,同时按钮上的“►”符号和透明遮罩会显示出来。这个示例展示了CSS的强大功能,可以创建出吸引人的用户界面元素。
评论已关闭