CSS3快速上手之23:按钮样式说明2

本文介绍了一种使用CSS来定制按钮样式的详细方法,包括不同颜色的边框样式、阴影效果、禁用状态以及按钮宽度的变化等,适用于网页设计中各种场景的需求。

1.代码:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>网页title</title> 
<style>
/*---范例1:按钮边框颜色样式---*/
button {
    background-color: #4CAF50; /* Green */
    border: none;
    color: white;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    margin: 4px 2px;
    cursor: pointer;
}

.button1 {
    background-color: white; 
    color: black; 
    border: 2px solid #4CAF50;
}

.button2 {
    background-color: white; 
    color: black; 
    border: 2px solid #008CBA;
}

.button3 {
    background-color: white; 
    color: black; 
    border: 2px solid #f44336;
}

.button4 {
    background-color: white;
    color: black;
    border: 2px solid #e7e7e7;
}

.button5 {
    background-color: white;
    color: black;
    border: 2px solid #555555;
}

		/*---鼠标悬停按钮样式---*/
.button1:hover {background-color: #4CAF50; color: white;}
.button2:hover {background-color: #008CBA; color: white;}
.button3:hover {background-color: #f44336; color: white;}
.button4:hover {background-color: #e7e7e7; color: white;}
.button5:hover {background-color: #555555; color: white;}



/*---范例2:按钮阴影样式---*/
.button6 {
    background-color: #4CAF50; /* Green */
    border: none;
    color: white;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    margin: 4px 2px;
    cursor: pointer;
    -webkit-transition-duration: 0.4s; /* Safari */
    transition-duration: 0.4s;
}

.button7 {
    box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);
}

.button8:hover {
    box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24),0 17px 50px 0 rgba(0,0,0,0.19);
}


/*---范例3:禁用按钮--*/
.button9 {
    background-color: #4CAF50; /* Green */
    border: none;
    color: white;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    margin: 4px 2px;
    cursor: pointer;
}

.disabled {
    opacity: 0.6;
    cursor: not-allowed;
}


/*---范例4:按钮宽度--*/
.button10 {
    background-color: #4CAF50; /* Green */
    border: none;
    color: white;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    margin: 4px 2px;
    cursor: pointer;
}

.button11 {width: 250px;}
.button12 {width: 50%;}
.button13 {
    padding-left: 0;
    padding-right: 0;
    width: 100%;
}

</style>
</head>
<body>

<p>范例1:按钮边框颜色+鼠标悬停按钮样式</p>
<button class="button button1">Green</button>
<button class="button button2">Blue</button>
<button class="button button3">Red</button>
<button class="button button4">Gray</button>
<button class="button button5">Black</button>

<p>范例2:按钮阴影样式</p>
<button class="button6 button7">阴影按钮</button>
<button class="button6 button8">鼠标悬停后出现阴影</button>

<p>范例3:禁用按钮样式</p>
<button class="button9">正常按钮</button>
<button class="button9 disabled">禁用按钮</button>

<p>范例4:按钮宽度</p>
<button class="button10 button11">250px</button><br>
<button class="button10 button12">50%</button><br>
<button class="button10 button13">100%</button>

</body>
</html>

2.结果:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值