自己手寫一套按鈕

預覽效果:

      

 

 

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
}

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章