检查的伪选择器在IE中不起作用

时间:2018-04-13 15:20:35

标签: html css sass css-selectors

以下代码适用于除IE之外的所有浏览器。我似乎无法弄清楚如何解决它。我觉得它与checked中的before和after选择器有关。我认为webkit外观或moz-appearance会把它排除在外但没有运气

我在这里有一个codepen https://codepen.io/ramageftw/pen/yKWQEe

任何帮助将不胜感激

form__checkbox--marketing {
    -webkit-appearance: none;
    -moz-appearance: none;
    -ms-appearance: none;
    width: 62px;
    height: 32px;
    position: relative;
    border-radius: 50px;
    border: 1px solid #d4d4d4;
    cursor: pointer;
    background-color: #fff;
    transition: background-color ease 0.2s;
    -webkit-transition: 0.2s;
    float: right;
    margin-left: 20px;
}

.form__checkbox--marketing {
    &:before {
        content: "";
        display: block;
        position: absolute;
        width: 30px;
        height: 30px;
        background: #fff;
        left: 0px;
        top: -1px;
        border-radius: 50%;
        border: 1px solid #d4d4d4;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
        transition: 0.2s;
        -webkit-transition: 0.2s;
    }
}

.form__checkbox--marketing {
    &:checked {
        background-color: #6CAF20;
        border-color: #6CAF20;
        &:before {
            left: 30px;
            border-color: #6CAF20;
        }
        &:after {
            content: '';
            width: 17px;
            height: 16px;
            position: absolute;
            top: 7px;
            right: 6px;
            background: url('/assets/source/global/img/valid.png');
        }
    }
}

1 个答案:

答案 0 :(得分:1)

在任何:before元素上使用伪元素:afterinput无效。它不支持全球。此外,输入是一个自动关闭元素,因此无需使用关闭输入标记。

正如MDN文档所说

  

Pseudo classes are only for container elements. You can not use them in elements like <input>, <img> etc.

因此,请尝试将输入包装到label中,并使用span作为伪元素。

.form__checkbox--marketing {
  -webkit-appearance: none;
  -moz-appearance: none;
  -ms-appearance: none;
  width: 62px;
  height: 32px;
  position: relative;
  border-radius: 50px;
  border: 1px solid #d4d4d4;
  cursor: pointer;
  background-color: #fff;
  transition: background-color ease 0.2s;
  -webkit-transition: 0.2s;
  float: left;
  margin-left: 20px;
}

.form__checkbox--marketing:before {
  content: "";
  display: block;
  position: absolute;
  width: 30px;
  height: 30px;
  background: #fff;
  left: 0px;
  top: -1px;
  border-radius: 50%;
  border: 1px solid #d4d4d4;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: 0.2s;
  -webkit-transition: 0.2s;
}

input[type=checkbox]:checked+.form__checkbox--marketing {
  background-color: #6CAF20;
  border-color: #6CAF20;
}

input[type=checkbox]:checked+.form__checkbox--marketing:after {
  content: '';
  width: 17px;
  height: 16px;
  position: absolute;
  top: 7px;
  right: 6px;
  background: url('https://image.ibb.co/m7PoE7/valid.png');
}

input[type=checkbox]:checked+.form__checkbox--marketing:before {
  left: 30px;
  border-color: #6CAF20;
}

input[type=checkbox] {
  display: none;
}
<label>
  <input name="marketing" id="join-form-marketing--modal" class="form__checkbox form__checkbox--modal" type="checkbox" />
  <span class="form__checkbox--marketing"></span>
</label>