定制设计复选框按钮

时间:2016-12-08 11:19:35

标签: html css html5 css3 checkbox

我正在尝试自定义设计复选框按钮,因此它们看起来不像典型的复选框按钮。我试图实现以下目标:

enter image description here

(请注意检查交叉标记是图片。)

到目前为止我已经实现了这一目标:

enter image description here

但我似乎无法摆脱勾选出现的小白色复选框。我想在选择时更改复选框按钮的CSS。例如,是,检查边框变为绿色,否则保持灰色。

有可能吗?

修改



.btn-primary {
  background-color: #f6f9fc;
  border: 1px solid Rgba(61, 70, 77, 0.1);
  font-size: 11px;
  color: #3d464d;
  width: 200px;
  height: 200px;
}

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" />

<label class="btn btn-primary">
  <input type="checkbox" value="yes">yes
</label>

<label class="btn btn-primary">
  <input type="checkbox" value="no">no
</label>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:5)

只是玩,只有css,没有图像或js:

&#13;
&#13;
input[type="checkbox"].myClass {
  display: none;
}
input[type="checkbox"].myClass + label {
  box-shadow: inset 0 0 0 1px silver;
  border-radius: 0.25em;
  display: inline-block;
  font-family: sans-serif;
  opacity: 0.5;
  padding: 1em 1em 2em 1em;
  text-align: center;
  width: 10em;
  -webkit-user-select: none;
  user-select: none;
}
input[type="checkbox"].myClass + label:before {
  background-image: linear-gradient(to left, black, black), linear-gradient(to left, black, black);
  background-size: 2px 50%, 25% 2px;
  background-repeat: no-repeat;
  background-position: 0.75em 0.625em, 0.75em 0.625em;
  border-radius: 50%;
  box-shadow: inset 0 0 0 2px black;
  content: "";
  display: block;
  height: 2em;
  margin: 1em auto;
  transform: rotate(-135deg);
  width: 2em;
}
input[type="checkbox"].myClass + label:after {
  content: "Yes";
}
input[type="checkbox"].myClass:checked + label {
  box-shadow: inset 0 0 0 1px red, 0 0 0.25em 0 silver;
  color: red;
  opacity: 1;
}
input[type="checkbox"].myClass:checked + label:before {
  background-image: linear-gradient(to left, red, red), linear-gradient(to left, red, red);
  background-size: 2px 50%, 50% 2px;
  background-repeat: no-repeat;
  background-position: center center, center center;
  box-shadow: inset 0 0 0 2px red;
}
input[type="checkbox"].myClass:checked + label:after {
  content: "No";
}
&#13;
<input class="myClass" id="o1" type="checkbox" /><label for="o1"></label>

<input class="myClass" id="o2" type="checkbox" checked/><label for="o2"></label>
&#13;
&#13;
&#13;