预览效果:
1、定义所有button的默认样式
.btn{
user-select: none;
padding: 0 10px;
border-radius: 4px;
border: 1px solid transparent;
display: inline-block;
height: 38px;
line-height: 38px;
white-space: nowrap;
text-decoration: none;
}
.btn, .btn:active, .btn:focus {
outline: 0;
}
2、定义按钮的大小
/*大型按钮*/
.btn-lg{
height: 44px;
line-height: 44px;
padding: 0 25px;
font-size: 16px;
}
/*小型按钮*/
.btn-sm{
height: 30px;
line-height: 30px;
font-size: 12px;
}
/*迷你按钮*/
.btn-xs{
height: 22px;
line-height: 22px;
padding: 0 5px;
font-size: 12px;
}
3、自定义一个默认按钮
.btn-default{
cursor: pointer;
background: #fff;
border: 1px solid #dcdfe6;
color: #606266;
}
.btn-default:hover, .btn-default:focus{
border-color: #c6e2ff;
color: #409eff;
background-color: #ecf5ff;
}
.btn-default:active{
border-color: #3a8ee6;
color: #3a8ee6;
}
4、完整源码
HTML
<button type="button" class="btn btn-disabled btn-lg ml10">禁用按钮</button>
<button type="button" class="btn btn-disabled ml10">禁用按钮</button>
<button type="button" class="btn btn-disabled btn-sm ml10">禁用按钮</button>
<button type="button" class="btn btn-disabled btn-xs ml10">禁用按钮</button>
<br/>
<br/>
<button type="button" class="btn btn-primary btn-lg ml10">主要按钮</button>
<button type="button" class="btn btn-primary ml10">主要按钮</button>
<button type="button" class="btn btn-primary btn-sm ml10">主要按钮</button>
<button type="button" class="btn btn-primary btn-xs ml10">主要按钮</button>
<br/>
<br/>
<button type="button" class="btn btn-default btn-lg ml10">默认按钮</button>
<button type="button" class="btn btn-default ml10">默认按钮</button>
<button type="button" class="btn btn-default btn-sm ml10">默认按钮</button>
<button type="button" class="btn btn-default btn-xs ml10">默认按钮</button>
<br/>
<br/>
<button type="button" class="btn btn-success btn-lg ml10">成功按钮</button>
<button type="button" class="btn btn-success ml10">成功按钮</button>
<button type="button" class="btn btn-success btn-sm ml10">成功按钮</button>
<button type="button" class="btn btn-success btn-xs ml10">成功按钮</button>
<br/>
<br/>
<button type="button" class="btn btn-warning btn-lg ml10">警告按钮</button>
<button type="button" class="btn btn-warning ml10">警告按钮</button>
<button type="button" class="btn btn-warning btn-sm ml10">警告按钮</button>
<button type="button" class="btn btn-warning btn-xs ml10">警告按钮</button>
<br/>
<br/>
<button type="button" class="btn btn-danger btn-lg ml10">危险按钮</button>
<button type="button" class="btn btn-danger ml10">危险按钮</button>
<button type="button" class="btn btn-danger btn-sm ml10">危险按钮</button>
<button type="button" class="btn btn-danger btn-xs ml10">危险按钮</button>
<br/>
<br/>
<button type="button" class="btn btn-import ml10">导入按钮</button>
<button type="button" class="btn btn-export ml10">导出按钮</button>
CSS
.ml10{
margin-left: 10px;
}
.ml5{
margin-left: 5px;
}
.ml8{
margin-left: 8px;
}
/*默认按钮*/
.btn{
user-select: none;
padding: 0 10px;
border-radius: 4px;
border: 1px solid transparent;
display: inline-block;
height: 38px;
line-height: 38px;
white-space: nowrap;
text-decoration: none;
}
.btn, .btn:active, .btn:focus {
outline: 0;
}
/*大型按钮*/
.btn-lg{
height: 44px;
line-height: 44px;
padding: 0 25px;
font-size: 16px;
}
/*小型按钮*/
.btn-sm{
height: 30px;
line-height: 30px;
font-size: 12px;
}
/*迷你按钮*/
.btn-xs{
height: 22px;
line-height: 22px;
padding: 0 5px;
font-size: 12px;
}
/*禁用按钮*/
.btn-disabled, .btn-disabled:hover, .btn-disabled:active {
border-color: #e6e6e6;
background-color: #eee;
background-image: none;
cursor: not-allowed;
color: #999;
}
/*主要按钮*/
.btn-primary{
color: #fff;
background-color: #409eff;
border-color: #409eff;
}
.btn-primary:hover, .btn-primary:focus {
cursor: pointer;
background: #66b1ff;
border-color: #66b1ff;
color: #fff;
}
.btn-primary:active, .btn-primary.active {
color: #fff;
background-color: #3a8ee6;
border-color: #3a8ee6;
}
/*默认按钮*/
.btn-default{
cursor: pointer;
background: #fff;
border: 1px solid #dcdfe6;
color: #606266;
}
.btn-default:hover, .btn-default:focus{
border-color: #c6e2ff;
color: #409eff;
background-color: #ecf5ff;
}
.btn-default:active{
border-color: #3a8ee6;
color: #3a8ee6;
}
/*成功按钮*/
.btn-success{
background-color: #1FBB7D;
color: #fff;
}
.btn-success:hover, .btn-success:focus{
cursor: pointer;
background-color: #59cd9f;
border-color: #59cd9f;
color: #fff;
}
.btn-success:active{
background-color: #199463;
border-color: #1FBB7D;
}
/*警告按钮*/
.btn-warning{
color: #e6a23c;
background-color: #fdf6ec;
border-color: #ffeba9;
}
.btn-warning:hover, .btn-warning:focus{
cursor: pointer;
background-color: #fdf6ec;
border-color: #faad14;
}
.btn-warning:active{
background-color: #fEE692;
border-color: #fEE692;
}
/*危险按钮*/
.btn-danger{
cursor: pointer;
background-color: #f56c6c;
border-color: #f56c6c;
color: #fff;
}
.btn-danger:hover, .btn-danger:focus{
color: #fff;
background-color: #ff7875;
border-color: #ff7875;
}
.btn-danger:active{
background-color: #d9363e;
border-color: #d9363e;
}
/*导出和导入按钮*/
.btn-export, .btn-import{
cursor: pointer;
border-color: #9095a1;
background-color: #fff;
}
.btn-export{
color: #f7674e;
}
.btn-import{
color: #395bcc;
}
.btn-export:hover, .btn-import:hover, .btn-export:focus, .btn-import:focus{
border-color: #677088;
background-color: #eeeeee;
}
.btn-dashed{
color: #515a6e;
background-color: #fff;
border-color: #dcdee2;
border-style: dashed
}
.btn-dashed:hover, .btn-dashed:focus{
color: #57a3f3;
background-color: #fff;
border-color: #57a3f3
}
.btn-dashed:active{
color: #2b85e4;
background-color: #fff;
border-color: #2b85e4
}