iOS喜欢使用复选框的切换按钮在不同的浏览器上看起来不同



我对网页设计有点陌生。尝试创建一个切换iOS喜欢按钮,但问题在于它出现在不同的浏览器上。在不同的浏览器中看起来不同。当我测试它时,它在 Chrome 上正常工作。

有人可以帮助我使其在所有浏览器上看起来都相同吗?对不起英语蹩脚?

jsfiddle 链接 : http://jsfiddle.net/racy2408/Let1y8yr/

下面给出的是我尝试过的 CSS:

body {
  margin: 30px;
  text-align: center;
}
input[type=checkbox],
input[type=radio] {
  display: inline-block;
  width: 50px;
  height: 30px;
  position: relative;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  box-shadow: inset 0px 5px 40px -13px rgba(0, 0, 0, 0.75);
  -webkit-box-shadow: inset 0px 5px 40px -13px rgba(0, 0, 0, 0.75);
  -moz-box-shadow: inset 0px 5px 40px -13px rgba(0, 0, 0, 0.75);
  -o-box-shadow: inset 0px 5px 40px -13px rgba(0, 0, 0, 0.75);
  border-radius: 15px;
  -webkit-border-radius: 15px;
  -moz-border-radius: 15px;
  -o-border-radius: 15px;
  background-color: #fff;
  padding: 1px;
  margin: 0px;
  transition: all 0.3s ease-out;
  -webkit-transition: all 0.3s ease-out;
  -moz-transition: all 0.3s ease-out;
  -o-transition: all 0.3s ease-out;
  transform: scale(1);
  -webkit-transform: scale(1);
  /*Adjust size here*/
  -moz-transform: scale(1);
  -o-transform: scale(1);
}
input[type=checkbox]:checked,
input[type=radio]:checked {
  box-shadow: inset 0px 0px 0px 20px #53d76a, inset 0px 5px 40px -13px rgba(132, 132, 132, 1);
  -webkit-box-shadow: inset 0px 0px 0px 20px #53d76a, inset 0px 5px 40px -13px rgba(132, 132, 132, 1);
  -moz-box-shadow: inset 0px 0px 0px 20px #53d76a, inset 0px 5px 40px -13px rgba(132, 132, 132, 1);
  -o-box-shadow: inset 0px 0px 0px 20px #53d76a, inset 0px 5px 40px -13px rgba(132, 132, 132, 1);
}
input[type=checkbox]:after,
input[type=radio]:after {
  content: " ";
  position: absolute;
  width: 28px;
  height: 28px;
  cursor: pointer;
  border-radius: 15px;
  -webkit-border-radius: 15px;
  -moz-border-radius: 15px;
  -o-border-radius: 15px;
  box-shadow: 0px 2px 2px 1px rgba(0, 0, 0, 0.2);
  -webkit-box-shadow: 0px 2px 2px 1px rgba(0, 0, 0, 0.2);
  -moz-box-shadow: 0px 2px 2px 1px rgba(0, 0, 0, 0.2);
  -o-box-shadow: 0px 2px 2px 1px rgba(0, 0, 0, 0.2);
  background-color: #fff;
  /* background-image: url(../images/toggle.png);
	background-repeat: no-repeat;
	background-size: contain; */
  transition: all 0.2s ease-in 0.2s;
  -webkit-transition: all 0.2s ease-in 0.2s;
  -moz-transition: all 0.2s ease-in 0.2s;
  -o-transition: all 0.2s ease-in 0.2s;
}
input[type="checkbox"]:checked:after,
input[type="radio"]:checked:after {
  left: 23px;
}
input[type=checkbox]:focus,
input[type=checkbox]:active,
input[type=radio]:focus,
input[type=radio]:active {
  outline: 0;
}
<h1>Checkbox :</h1> 
<input type="checkbox" />
<input type="checkbox" checked />
<h1>Radio :</h1>
<input type="radio" name="group" />
<input type="radio" name="group" checked />
<input type="radio" name="group" />

输入不应该

能够添加beforeafter伪元素,因为它们不是容器(例如,<input>不能有子元素(。

这里的评论中有更多信息:https://stackoverflow.com/a/4660434/4338477

不过,您可以添加标签以获得相同的效果(这适用于Firefox和IE9+(:

http://jsfiddle.net/8okjwLxx/2/

<h1>Checkbox :</h1> 
<input id="checkbox1" type="checkbox" />
<label for="checkbox1"></label>
<input id="checkbox2" type="checkbox" checked />
<label for="checkbox2"></label>
<h1>Radio :</h1>
<input id="radio1" type="radio" name="group" />
<label for="radio1"></label>
<input id="radio2" type="radio" name="group" checked />
<label for="radio2"></label>
<input id="radio3" type="radio" name="group" />
<label for="radio3"></label>
body {
    margin: 30px;
    text-align: center;
}
input[type=checkbox],
input[type=radio]{
    display: none;
}
input[type=checkbox] + label,
input[type=radio] + label {
    display: inline-block;
    width: 50px;
    height: 30px;
    position: relative;
    cursor: pointer;
    appearance:         none;
    -webkit-appearance: none;
    -moz-appearance:    none;
    box-shadow:         inset 0px 5px 40px -13px rgba(0, 0, 0, 0.75);
    -webkit-box-shadow: inset 0px 5px 40px -13px rgba(0, 0, 0, 0.75);
    -moz-box-shadow:    inset 0px 5px 40px -13px rgba(0, 0, 0, 0.75);
    -o-box-shadow:      inset 0px 5px 40px -13px rgba(0, 0, 0, 0.75);
    border-radius:         15px;
    -webkit-border-radius: 15px;
    -moz-border-radius:    15px;
    -o-border-radius:      15px;
    background-color: #fff;
    padding: 1px;
    margin: 0px;
    transition:         all 0.3s ease-out;
    -webkit-transition: all 0.3s ease-out;
    -moz-transition:    all 0.3s ease-out;
    -o-transition:      all 0.3s ease-out;  
    transform:         scale(1);
    -webkit-transform: scale(1); /*Adjust size here*/
    -moz-transform:    scale(1);
    -o-transform:      scale(1);
}
input[type=checkbox]:checked + label,
input[type=radio]:checked + label {
    box-shadow:         inset 0px 0px 0px 20px #53d76a, inset 0px 5px 40px -13px rgba(132, 132, 132, 1);
    -webkit-box-shadow: inset 0px 0px 0px 20px #53d76a, inset 0px 5px 40px -13px rgba(132, 132, 132, 1);
    -moz-box-shadow:    inset 0px 0px 0px 20px #53d76a, inset 0px 5px 40px -13px rgba(132, 132, 132, 1);
    -o-box-shadow:      inset 0px 0px 0px 20px #53d76a, inset 0px 5px 40px -13px rgba(132, 132, 132, 1);
}
input[type=checkbox] + label:after,
input[type=radio] + label:after {
    left: 0;
    content: " ";
    position: absolute;
    width: 28px;
    height: 28px;
    cursor: pointer;
    border-radius:         15px;
    -webkit-border-radius: 15px;
    -moz-border-radius:    15px;
    -o-border-radius:      15px;
    box-shadow:         0px 2px 2px 1px rgba(0, 0, 0, 0.2);
    -webkit-box-shadow: 0px 2px 2px 1px rgba(0, 0, 0, 0.2);
    -moz-box-shadow:    0px 2px 2px 1px rgba(0, 0, 0, 0.2);
    -o-box-shadow:      0px 2px 2px 1px rgba(0, 0, 0, 0.2);
    background-color: #fff;
    /* background-image: url(../images/toggle.png);
    background-repeat: no-repeat;
    background-size: contain; */
    transition:         all 0.2s ease-in 0.2s;
    -webkit-transition: all 0.2s ease-in 0.2s;
    -moz-transition:    all 0.2s ease-in 0.2s;
    -o-transition:      all 0.2s ease-in 0.2s;
}
input[type=checkbox]:checked + label:after,
input[type=radio]:checked + label:after {
    left: 23px;
}
input[type=checkbox]:focus,
input[type=checkbox]:active,
input[type=radio]:focus,
input[type=radio]:active {
    outline: 0;
}

相关内容

最新更新