十五.CSS 按钮
1.基本按钮样式
默认按钮
CSS 实例
.button {
background-color: #4CAF50; /* Green */
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
}
按钮颜色
我们可以使用 background-color 属性来设置按钮颜色:
CSS 实例
.button1 {
background-color: #4CAF50;} /* Green */
.button2 {
background-color: #008CBA;} /* Blue */
.button3 {
background-color: #f44336;} /* Red */
.button4 {
background-color: #e7e7e7; color: black;} /* Gray */
.button5 {
background-color: #555555;} /* Black */
按钮大小
我们可以使用 font-size 属性来设置按钮大小:
CSS 实例
.button1 {
font-size: 10px;}
.button2 {
font-size: 12px;}
.button3 {
font-size: 16px;}
.button4 {
font-size: 20px;}
.button5 {
font-size: 24px;}
圆角按钮
我们可以使用 border-radius 属性来设置圆角按钮:
CSS 实例
.button1 {
border-radius: 2px;}
.button2 {
border-radius: 4px;}
.button3 {
border-radius: 8px;}
.button4 {
border-radius: 12px;}
.button5 {
border-radius: 50%;}
按钮边框颜色
css 我们可以使用 border 属性设置按钮边框颜色:
CSS 实例
.button1 {
background-color: white;
color: black;
border: 2px solid #4CAF50; /* Green */
}
…
鼠标悬停按钮
我们可以使用 :hover 选择器来修改鼠标悬停在按钮上的样式。
提示: 我们可以使用 transition-duration 属性来设置 “hover” 效果的速度:
CSS 实例
.button {
-webkit-transition-duration: 0.4s; /* Safari */
transition-duration: 0.4s;
}
.button:hover {
background-color: #4CAF50