在使用 CSS3 创建的自定义单选按钮上,在反向模式下不会发生转换



我正在尝试为我的网站使用一个自定义的单选按钮。我实现了同样的目标。我试着给单选按钮赋予过渡效果,它也起作用了。我担心的是,转换只能在选中状态下工作。当我取消选中单选按钮时,转换不会发生(即,反向转换不会发生)。它只是一种方式。检查下方的代码

<section class="radio">
  <input id="set_empty" type="radio" name="err_rec" value="1">
  <label for="set_empty">Set empty value for the column</label>
   <input id="st_empty" type="radio" name="err_rec" value="1">
  <label for="st_empty">Set empty value for the column</label>
</section>
.radio{
    position: relative;
    display: block;
    margin-top: 10px;
    margin-bottom: 10px;
}
.radio input[type="radio"], .check input[type="checkbox"] {
    display: none;
}
.radio label, .check label {
    min-height: 1em;
    padding-left: 20px;
    margin-bottom: 0;
    font-weight: normal;
    cursor: pointer;
    display: inline-block;
    position: relative;
    outline: none;
}
.radio label::before {
    content: "";
    display: inline-block;
    position: absolute;
    width: 12px;
    height: 12px;
    left: 0;
    border: 1px solid #46bedc;
    border-radius: 50%;
    background-color: #fff;
    top: 2px;
}
.radio label::after {
    display: inline-block;
    position: absolute;
    content: " ";
    width: 6px;
    height: 6px;
    left: 4px;
    top: 4px;
    border-radius: 50%;
    -webkit-transform: scale(1.6, 1.6);
    -ms-transform: scale(1.6, 1.6);
    -o-transform: scale(1.6, 1.6);
    transform: scale(1.6, 1.6);
    -webkit-transition: transform .5s cubic-bezier(0.6,1,0,0.78);
    -o-transition: transform .5s cubic-bezier(0.6,1,0,0.78);
    transition: transform .5s ease;
    top: 6px;
}
.radio input[type="radio"]:checked + label::after {
    -webkit-transform: scale(1, 1);
    -ms-transform: scale(1, 1);
    -o-transform: scale(1, 1);
    transform: scale(1, 1);
    outline: none;
    background-color: rgb(70, 190, 220);
}

请参阅此处

您还需要转换background-color以使效果可见。在没有任何过渡的情况下,它会立即从颜色变为透明。因此,transform上的过渡对眼睛来说是不可见的。

.radio {
  position: relative;
  display: block;
  margin-top: 10px;
  margin-bottom: 10px;
}
.radio input[type="radio"],
.check input[type="checkbox"] {
  display: none;
}
.radio label,
.check label {
  min-height: 1em;
  padding-left: 20px;
  margin-bottom: 0;
  font-weight: normal;
  cursor: pointer;
  display: inline-block;
  position: relative;
  outline: none;
}
.radio label::before {
  content: "";
  display: inline-block;
  position: absolute;
  width: 12px;
  height: 12px;
  left: 0;
  border: 1px solid #46bedc;
  border-radius: 50%;
  background-color: #fff;
  top: 2px;
}
.radio label::after {
  display: inline-block;
  position: absolute;
  content: " ";
  width: 6px;
  height: 6px;
  left: 4px;
  top: 4px;
  border-radius: 50%;
  transform: scale(1.6, 1.6);
  transition: transform .5s ease, background-color .5s ease;
  top: 6px;
}
.radio input[type="radio"]:checked + label::after {
  transform: scale(1, 1);
  outline: none;
  background-color: rgb(70, 190, 220);
}
<section class="radio">
  <input id="set_empty" type="radio" name="err_rec" value="1">
  <label for="set_empty">Set empty value for the column</label>
  <input id="st_empty" type="radio" name="err_rec" value="1">
  <label for="st_empty">Set empty value for the column</label>
</section>

相关内容

  • 没有找到相关文章

最新更新