【问题标题】:HTML Checking sibling radio button is checked [duplicate]选中 HTML Checking 同级单选按钮 [重复]
【发布时间】:2020-04-13 21:40:41
【问题描述】:

所以我有这个任务,我需要制作一个自定义单选按钮,如果选中,则会出现成功徽标。

我成功创建了盒子但不是内容我首先虽然它真正的单选按钮不起作用但是在我打开不透明度之后(我使用不透明度来隐藏真实的,以防这不够清晰)真实的单选按钮工作。我试着问我的前辈,他并没有真正回答我的问题

这是html

<label for="Viridian">      
    <span class="checkbox"></span>
     Viridian
    <input type="radio" id="Viridian" name="color" value="Viridian" checked="checked">
</label>

这是css

.checkbox {
    display: block;
    width: 18px;
    height: 18px;
    cursor: pointer;
    margin-right: 2vh;
    border: solid 1px white;
}
    input ~ .checkbox::after {
    content: '';
    vertical-align: middle;
    font-size: 15px;
    text-align: center;
}
 input:checked ~ .checkbox::after {
    content: 'a';
}

【问题讨论】:

  • 内容a仅供模拟

标签: html css radio-button


【解决方案1】:

我想这就是你要找的。​​p>

HTML:

 <p>
    <input type="radio" id="test3" name="radio-group">
    <label for="test3">Orange</label>
 </p>

CSS:

[type="radio"]: checked,
[type="radio"]: not(: checked) {
  position: absolute;
  left: -9999px;
}

[type="radio"]: checked+label,
[type="radio"]: not(: checked)+label {
  position: relative;
  padding - left: 28px;
  cursor: pointer;
  line - height: 20px;
  display: inline - block;
  color: #666;
}

[type="radio"]: checked+label: before,
[type="radio"]: not(: checked)+label: before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  width: 18px;
  height: 18px;
  border: 1px solid #ddd;
  border - radius: 100 %;
  background: #fff;
}

[type="radio"]: checked+label: after,
[type="radio"]: not(: checked)+label: after {
  content: '';
  width: 12px;
  height: 12px;
  background: #F87DA9;
  position: absolute;
  top: 4px;
  left: 4px;
  border - radius: 100 %;
  -webkit - transition: all 0.2s ease;
  transition: all 0.2s ease;
}

[type="radio"]: not(: checked)+label: after {
  opacity: 0;
  -webkit - transform: scale(0);
  transform: scale(0);
}

[type="radio"]: checked+label: after {
  opacity: 1;
  -webkit - transform: scale(1);
  transform: scale(1);
}

【讨论】:

    猜你喜欢
    • 2014-02-24
    • 1970-01-01
    • 1970-01-01
    • 2019-06-03
    • 2012-09-19
    • 1970-01-01
    • 1970-01-01
    • 2016-12-17
    • 1970-01-01
    相关资源
    最近更新 更多