css 按钮制作
基础按钮样式
使用CSS创建基础按钮样式,设置背景色、边框、圆角等属性:
.button {
display: inline-block;
padding: 10px 20px;
background-color: #4CAF50;
color: white;
text-align: center;
text-decoration: none;
border: none;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
}
悬停效果
添加悬停状态提升交互体验:
.button:hover {
background-color: #45a049;
box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}
活动状态
为按钮添加点击时的反馈效果:
.button:active {
transform: translateY(1px);
box-shadow: none;
}
禁用状态
设置禁用按钮的样式:
.button:disabled {
opacity: 0.6;
cursor: not-allowed;
}
渐变按钮
使用CSS渐变创建更现代的按钮:
.gradient-button {
background: linear-gradient(to right, #ff7e5f, #feb47b);
border: none;
color: white;
padding: 12px 24px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
border-radius: 25px;
}
边框按钮
创建带边框的按钮样式:
.outline-button {
background-color: transparent;
color: #4CAF50;
padding: 10px 20px;
border: 2px solid #4CAF50;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
transition: all 0.3s ease;
}
.outline-button:hover {
background-color: #4CAF50;
color: white;
}
图标按钮
在按钮中添加图标:
.icon-button {
background-color: #4CAF50;
border: none;
color: white;
padding: 10px 20px 10px 40px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
border-radius: 5px;
position: relative;
}
.icon-button::before {
content: "→";
position: absolute;
left: 15px;
}
动画按钮
添加点击动画效果:
.animate-button {
background-color: #4CAF50;
border: none;
color: white;
padding: 12px 24px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
border-radius: 5px;
transition: all 0.3s;
}
.animate-button:hover {
transform: scale(1.05);
}





