css 制作按钮
CSS 制作按钮的方法
基础按钮样式
使用 background-color、color、padding 和 border-radius 创建基础按钮样式:
.button {
background-color: #4CAF50;
color: white;
padding: 10px 20px;
border: none;
border-radius: 5px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
cursor: pointer;
}
悬停效果
添加 :hover 伪类实现悬停效果:
.button:hover {
background-color: #45a049;
}
禁用状态
使用 :disabled 或 .disabled 类设置禁用样式:
.button:disabled {
background-color: #cccccc;
cursor: not-allowed;
}
按钮尺寸
通过调整 padding 和 font-size 控制按钮大小:

.button-sm {
padding: 5px 10px;
font-size: 14px;
}
.button-lg {
padding: 15px 30px;
font-size: 18px;
}
按钮组
使用 display: inline-block 或 flexbox 创建水平排列的按钮组:
.button-group {
display: flex;
gap: 10px;
}
图标按钮
结合 Font Awesome 或其他图标库创建带图标的按钮:

.icon-button {
padding-left: 40px;
position: relative;
}
.icon-button::before {
content: "\f007";
font-family: "Font Awesome";
position: absolute;
left: 15px;
top: 50%;
transform: translateY(-50%);
}
动画效果
使用 transition 或 @keyframes 添加点击动画:
.button {
transition: all 0.3s ease;
}
.button:active {
transform: scale(0.95);
}
渐变背景
使用 CSS 渐变创建更丰富的按钮背景:
.gradient-button {
background: linear-gradient(to right, #ff7e5f, #feb47b);
}
边框样式
创建轮廓按钮或自定义边框:
.outline-button {
background-color: transparent;
color: #4CAF50;
border: 2px solid #4CAF50;
}






