bootstrap從新設計checkbox樣式

文章採集於: https://www.cnblogs.com/GumpYan/p/7845445.html#undefinedhtml

在原文基礎上修改了勾勾的內容,直接採用bootstrap字體庫。修改了橫向佈局的內間距,讓兩項之間有距離好看一點點。沒了。代碼看下面。bootstrap

一、將checkbox原來的樣式改爲新的樣式佈局

checkbox原來的樣式post

checkbox新的樣式字體

  

2.思路:spa

(1)首先,將checkbox的id與label的for關聯起來設計

(2)將原來的checkbox用opacity:0隱藏起來,用新設計的checkbox覆蓋在原來的checkbox的位置code

(3)將新的checkbox與原來的checkbox的checked事件關聯起來orm

 

 (4)將remember me的字體樣式改變一下,同時加上一個樣式:鼠標移動到字體上變成手形htm

 源碼:

html文件

<div class="col-sm-8 ">
    <div class="checkbox-custom checkbox-default">
        <input type="checkbox" id="RememberMe">
            <label for="RememberMe">Remember Me</label>
    </div>
</div>

CSS

.checkbox-custom {
    position: relative;
    padding: 0 15px 0 25px;
    margin-bottom: 7px;
    margin-top: 0;
    display: inline-block;
}
/*
將初始的checkbox的樣式改變
*/
.checkbox-custom input[type="checkbox"] {
    opacity: 0;/*將初始的checkbox隱藏起來*/
    position: absolute;
    cursor: pointer;
    z-index: 2;
    margin: -6px 0 0 0;
    top: 50%;
    left: 3px;
}
/*
設計新的checkbox,位置
*/
.checkbox-custom label:before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    margin-top: -9px;
    width: 19px;
    height: 18px;
    display: inline-block;
    border-radius: 2px;
    border: 1px solid #bbb;
    background: #fff;
}
/*
點擊初始的checkbox,將新的checkbox關聯起來
*/
.checkbox-custom input[type="checkbox"]:checked +label:after {
    position: absolute;
    display: inline-block;
    font-family: 'Glyphicons Halflings';
    content: "\e013";
    top: 42%;
    left: 3px;
    margin-top: -5px;
    font-size: 11px;
    line-height: 1;
    width: 16px;
    height: 16px;
    color: #333;
}
.checkbox-custom label {
    cursor: pointer;
    line-height: 1.2;
    font-weight: normal;/*改變了rememberme的字體*/
    margin-bottom: 0;
    text-align: left;
}
相關文章
相關標籤/搜索