css - 输入[类型= radio ] :before radio sticking out

标签 css

圆形边缘刚好从正方形或圆形中伸出,因此如果我在 before 之前提供白色背景,则 radio 边缘仍然略微可见。

enter image description here

enter image description here

input[type=radio] {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  position: relative;
  cursor: pointer;
}

input[type=radio]:before {
  content: "";
  display: block;
  width: 16px;
  height: 16px;
  border: 2px solid grey;
  border-radius: 50%;
  /* background-color: white; */
  position: absolute;
  top: 0;
  left: 0;
}
> <input type="radio" name="r" checked>

如何使用 css before 完全隐藏单选按钮?

最佳答案

我认为使用 visibility:hidden 可能会有帮助,请检查以下内容:

input[type=radio] {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  position: relative;
  cursor: pointer;
  visibility: hidden;
 
}

input[type=radio]:before {
  content: "";
  display: block;
  width: 16px;
  height: 16px;
  border: 2px solid grey;
  border-radius: 50%;
  /* background-color: white; */
  position: absolute;
  top: 0;
  left: 0;
  visibility: visible;
  
}
input[type=radio]:checked:after {
    content: "";
    display: block;
    width: 10px;
    height: 10px;
    /* border: 2px solid green; */
    border-radius: 50%;
    background-color: green;
    position: absolute;
    top: 5px;
    left: 5px;
    visibility: visible;
}
<input type="radio" name="r" checked>

关于css - 输入[类型= radio ] :before radio sticking out,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55967112/

相关文章:

javascript - 默认水平滚动的表格

css - Bootstrap 模态弹出窗口显示页面内容

html - :First-Child and :nth-child() not working

html - 无法创建具有固定位置的 iframe

CSS 网格导航栏 - 如何正确添加按钮分隔符?

css - 如何在 div 悬停时隐藏视频?

html - 我想在悬停时旋转链接

html - 表单 CSS 问题。 silverstripe 用户自定义表单

html - 表内的绝对元素导致表启用 overflow-y : scroll somehow

css - Flexbox:网格中元素之间的空间