css3按钮制作
CSS3 按钮制作方法
基础按钮样式
使用 border-radius 和 padding 创建圆角按钮:
.btn {
display: inline-block;
padding: 10px 20px;
border-radius: 5px;
background-color: #3498db;
color: white;
text-decoration: none;
text-align: center;
}
悬停效果
添加 :hover 伪类实现交互效果:
.btn:hover {
background-color: #2980b9;
box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}
渐变背景
使用 linear-gradient 创建渐变按钮:
.gradient-btn {
background: linear-gradient(to right, #ff7e5f, #feb47b);
border: none;
}
阴影效果
通过 box-shadow 添加立体感:
.shadow-btn {
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}
动画效果
使用 transition 实现平滑过渡:
.animate-btn {
transition: all 0.3s ease;
}
3D按钮
结合多重阴影创建3D效果:
.btn-3d {
box-shadow: 0 5px 0 #c0392b, 0 5px 15px rgba(0,0,0,0.2);
position: relative;
top: 0;
}
.btn-3d:active {
top: 5px;
box-shadow: 0 0 0 #c0392b, 0 0 10px rgba(0,0,0,0.2);
}
禁用状态
使用 :disabled 伪类设置禁用样式:
.btn:disabled {
opacity: 0.6;
cursor: not-allowed;
}





