边框颜色的CSS复选框样式

时间:2017-01-20 05:55:51

标签: css checkbox

我的桌子上有一个复选框。 这是该复选框的css

input[type="checkbox"] {
    width: 20px;
    height: 30px;
    margin: auto;
    display: table-row;
    border: 5px solid red;
    -webkit-transform: rotate(45deg);
    transform: rotate(45deg);
    margin-left: 4px;
    margin-top: 1px;
}

但它显示正常的复选框。 我想更改该复选框的边框颜色。 但它不起作用!

3 个答案:

答案 0 :(得分:8)

您只能在css下方设置复选框边框,然后查看Fiddle Demo

CSS:

.error input[type=checkbox] {
  outline: 2px solid #c00;
}

答案 1 :(得分:1)

我猜HTML不允许在复选框中添加边框样式。请尝试使用outline属性。

答案 2 :(得分:1)

尝试这个自定义的复选框代码:

/* Remove default checkbox */
[type="checkbox"]:not(:checked),
[type="checkbox"]:checked {
  position: absolute;
  left: -9999px;
}
[type="checkbox"]:not(:checked) + label,
[type="checkbox"]:checked + label {  
  position: relative;
  overflow: hidden;
  padding-left: 35px;
  cursor: pointer;
  display: inline-block;
  height: 25px;
  line-height: 25px;

  -webkit-user-select: none; /* webkit (safari, chrome) browsers */
  -moz-user-select: none; /* mozilla browsers */
  -khtml-user-select: none; /* webkit (konqueror) browsers */
  -ms-user-select: none; /* IE10+ */
}

/* checkbox aspect */
[type="checkbox"] + label:before,
[type="checkbox"] + label:after {
  content: '';
  position: absolute;
  left: 0;
  z-index: 1;

  -webkit-transition: .2s;
  transition: .2s;
}
/* Unchecked styles */
[type="checkbox"]:not(:checked) + label:before {
  top: 0px;
  width: 19px; height: 19px;
  border: 1px solid red;
}
[type="checkbox"]:not(:checked) + label:after {
  top: 0px;
  width: 19px; height: 19px;
  border: 1px solid red;
  z-index: 0;
}
/* Checked styles */
[type="checkbox"]:checked + label:before {
  top: 2px;
  width: 6px; height: 12px;
  border-top: 1px solid transparent;
  border-left: 1px solid transparent;
  border-right: 1px solid red;
  border-bottom: 1px solid red;
  -webkit-transform: rotateZ(37deg);
  transform: rotateZ(37deg);

  -webkit-transform-origin: 20% 40%;
  transform-origin: 100% 100%;
}
[type="checkbox"]:checked + label:after {
  top: 0px;
  width: 19px; height: 19px;
  border: 1px solid red;
  z-index: 0;
}
/* disabled checkbox */
[type="checkbox"]:disabled:not(:checked) + label:before,
[type="checkbox"]:disabled:checked + label:before {
  top: 0;
  box-shadow: none;
  background-color: #444;
  width: 19px; height: 19px;
  border: 3px solid #444;
  -webkit-transform: rotateZ(0deg);
  transform: rotateZ(0deg);
}
[type="checkbox"]:disabled + label {
  color: #555;
}
[type="checkbox"]:disabled:not(:checked) + label:hover:before {
  border-color: red;
}
<form action="#">
        <p>
          <input type="checkbox" id="test1" />
          <label for="test1">Red</label>
        </p>
        <p>
          <input type="checkbox" id="test2" checked="checked" />
          <label for="test2">Yellow</label>
        </p>
  </form>