【问题标题】:How to make a custom checkbox and radio button in pure css?如何在纯 CSS 中制作自定义复选框和单选按钮?
【发布时间】:2012-04-16 01:29:24
【问题描述】:

我正在尝试在纯 css 中制作一个自定义复选框和单选按钮,并兼容跨浏览器。

我正在寻找如下图所示的结果:-

我只想用 ie7 做这个纯 css

【问题讨论】:

  • 据我所知,仅使用 CSS 是不可能的。但我可能是错的!

标签: html css checkbox radio-button


【解决方案1】:

我已经制作了基于 css 的复选框和单选按钮,它在结果附近吗?

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

【讨论】:

【解决方案2】:

试试这个:

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;
}

或者 - 跟随这个 URL:http://fronteed.com/iCheck/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-06
    • 2022-11-10
    • 1970-01-01
    相关资源
    最近更新 更多