复选框样式在Safari移动设备上不起作用

nie*_*lsv 7 html css safari checkbox css3

我想像下面那样设置复选框的样式:

在此输入图像描述

这是我的CSS:

.checkboxcontact input[type="checkbox"] {
    -webkit-appearance: none;
    background-color: white;
    border: 1px solid #d44803;
    padding: 9px;
    border-radius: 3px;
    display: inline-block;
    position: relative;
    float:left;
}

.checkboxcontact input[type="checkbox"]:checked {
    background-color: #d44803;
    border: 1px solid white;
    color: #fff;
}

.checkboxcontact input[type="checkbox"]:checked:after {
    content: '\2714';
    font-size: 14px;
    position: absolute;
    top: 0;
    left: 3px;
    color: #fff;
    font-family: "FontAwesome";
}
Run Code Online (Sandbox Code Playgroud)

这在桌面和Chrome手机上显示完美.

在此输入图像描述

但问题出在iPhone上的Safari上.它显示如下:

在此输入图像描述

我怎样才能解决这个问题?是否有后备或其他什么?

sco*_*ord 5

正如上面所建议的,伪元素不适用于输入,但是,将复选框包装在标签是个好主意- 它是 w3c 有效的,因此它可以按预期工作,而您没有将for标签用于标签,也不id用于输入复选框。

这是 HTML:

<label class="custom-checkbox">
  <input type="checkbox" value="checkbox1">
  <span>Checkbox</span>
</label>
Run Code Online (Sandbox Code Playgroud)

代码足够通用,所以如果你只需要复选框,没有标签,你只需将跨度留空 - 你必须保留标签 - 或者你可以创建自己的自定义类来应用标签上的伪元素本身。

这是CSS:

.custom-checkbox {
  position: relative;
  display: block;
  margin-top: 10px;
  margin-bottom: 10px;
  line-height: 20px;
}

.custom-checkbox span {
  display: block;
  margin-left: 20px;
  padding-left: 7px;
  line-height: 20px;
  text-align: left;
}

.custom-checkbox span::before {
  content: "";
  display: block;
  position: absolute;
  width: 20px;
  height: 20px;
  top: 0;
  left: 0;
  background: #fdfdfd;
  border: 1px solid #e4e5e7;
  @include vendorize(box-shadow, inset 2px 2px 0px 0px rgba(0, 0, 0, 0.1));
}

.custom-checkbox span::after {
  display: block;
  position: absolute;
  width: 20px;
  height: 20px;
  top: 0;
  left: 0;
  font-size: 18px;
  color: #0087b7;
  line-height: 20px;
  text-align: center;
}

.custom-checkbox input[type="checkbox"] {
  opacity: 0;
  z-index: -1;
  position: absolute;
}

.custom-checkbox input[type="checkbox"]:checked + span::after {
  font-family: "FontAwesome";
  content: "\f00c";
  background:#d44803;
  color:#fff;
}
Run Code Online (Sandbox Code Playgroud)

这是一个工作小提琴:https : //jsfiddle.net/ee1uhb3g/

在所有浏览器上进行验证测试 - FF、Chrome、Safari、IE 等