简体   繁体   English

Radiobutton造型与CSS

[英]Radiobutton styling with css

I am trying to style my Radio button with CSS. 我正在尝试使用CSS设置我的单选按钮。 When the button is unchecked it should have a black border and and when its checked the circle should be completely black. 当取消选中该按钮时,它应该有一个黑色边框,当它被选中时,圆圈应该是完全黑色的。 Sadly my Code doesn't work. 可悲的是,我的守则不起作用。

My Code: 我的代码:

<div class="radioss">
      <input type="radio" id="mann" name="selector">
      <label for="mann">Mann</label>
</div>
<div class="radios">
      <input type="radio" id="mann" name="selector">
      <label for="mann">Frau</label>
</div>



.radioss{
    float:left;
}

.radios{
   float:left; 
}

/*Radiobutton*/
input[type="radio"] {
    display:none;
}

.mann:not(checked) + label:before{
    content:" ";  
    display: inline-block;
    border: 2px solid black;
    width: 13px;
    height:13px;
    border-radius:7px;
}

.mann:checked + label:before{
 background-color:black;
}

Does somebody have any idea what i am doing wrong? 有人知道我做错了什么吗?

You cannot use same or single ID for more than one elements, It won't work. 您不能对多个元素使用相同或单个ID,它将无法工作。

 .radioss input[type=radio] { display: none; } .radioss input[type=radio]:not(:checked) + label:before { content: ""; border: 2px solid #000; height: 10px; width: 10px; display: inline-block; border-radius:7px; } .radioss input[type=radio]:checked + label:before { content: ""; border: 2px solid #000; height: 10px; width: 10px; background: #000; display: inline-block; border-radius:7px; } 
 <div class="radioss"> <input type="radio" id="mann" name="selector"> <label for="mann">Mann</label> <input type="radio" id="mann1" name="selector"> <label for="mann1">Frau</label> </div> 

Source: Checkbox styling only css 来源: 复选框样式只有CSS

You can check the following link its may help you. 您可以查看以下链接,它可能会对您有所帮助。

.checkbox-form .lg-label:before {
  content: '';
  width: 18px;
  height: 18px;
  background-color: transparent;
  margin-right: 10px;
  margin-top: 5px;
  border-radius: 50%;
  border: 1px solid #afaeae;
}
input[type=checkbox]:checked + .lg-item-radio .checkbox-form .lg-label:before {
   border-color: rgba(27, 205, 128, 0.6);
}

https://codepen.io/sifulislam/pen/dZvXjK https://codepen.io/sifulislam/pen/dZvXjK

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM