簡體   English   中英

如何在純CSS中制作自定義復選框和單選按鈕?

[英]How to make a custom checkbox and radio button in pure css?

我正在嘗試使用跨瀏覽器兼容的純css中創建自定義復選框和單選按鈕。

我正在尋找如下圖所示的結果: -

在此輸入圖像描述

我希望這只有ie7的純css

嘗試這個:

DEMO

HTML

<div class="checkbox"> 
  <label class="i-checks">
    <input type="checkbox" value=""> <i></i> Option one
  </label>
</div>
<div class="radio">
  <label class="i-checks">
    <input type="radio" checked="" value="option2" name="a"> <i></i> Option two checked
  </label>
</div>

CSS

.i-checks {
    padding-left: 20px;
    cursor: pointer;
}

.i-checks input {
    opacity: 0;
    position: absolute;
    margin-left: -20px;
}

.i-checks input:checked + i {
    border-color: #23b7e5;
}

.i-checks input:checked + i:before {
    left: 4px;
    top: 4px;
    width: 10px;
    height: 10px;
    background-color: #23b7e5;
}

.i-checks input:checked + span .active {
    display: inherit;
}

.i-checks input[type="radio"] + i, .i-checks input[type="radio"] + i:before {
    border-radius: 50%;
}

.i-checks input[disabled] + i, fieldset[disabled] .i-checks input + i {
    border-color: #dee5e7;
}

.i-checks input[disabled] + i:before, fieldset[disabled] .i-checks input + i:before {
    background-color: #dee5e7;
}

.i-checks > i {
    width: 20px;
    height: 20px;
    line-height: 1;
    border: 1px solid #cfdadd;
    background-color: #fff;
    margin-left: -20px;
    margin-top: -2px;
    display: inline-block;
    vertical-align: middle;
    margin-right: 4px;
    position: relative;
}

.i-checks > i:before {
    content: "";
    position: absolute;
    left: 10px;
    top: 10px;
    width: 0px;
    height: 0px;
    background-color: transparent;
    -webkit-transition: all 0.2s;
    transition: all 0.2s;
}

.i-checks > span {
    margin-left: -20px;
}

.i-checks > span .active {
    display: none;
}

或者 - 點擊此網址: http//fronteed.com/iCheck/

我已經制作了基於CSS的復選框和單選按鈕是否接近結果?

http://jsfiddle.net/Vsvg2/78/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM