You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何实现带外围圆环的圆形单选按钮,选中时显示内部小圆效果

调整方案

你只需要修改CSS中对应.checkmark、hover状态、选中状态、内部小圆的样式规则即可,修改后的完整CSS代码如下:

/* The container */
.container {
  display: block;
  position: relative;
  padding-left: 35px;
  margin-bottom: 12px;
  cursor: pointer;
  font-size: 22px;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* Hide the browser's default radio button */
.container input {
  position: absolute;
  opacity: 0;
  cursor: pointer;
}

/* Create a custom radio button */
.checkmark {
  position: absolute;
  top: 0;
  left: 0;
  height: 28px;
  width: 28px;
  box-sizing: border-box;
  background-color: #fff;
  border: 2px solid #eee;
  border-radius: 50%;
}

/* On mouse-over, 边框切换为主题色 */
.container:hover input ~ .checkmark {
  border-color: #0f8c73;
}

/* When the radio button is checked, 外框显示主题色形成外围圆环 */
.container input:checked ~ .checkmark {
  background-color: #fff;
  border-color: #0f8c73;
}

/* Create the indicator (the dot/circle - hidden when not checked) */
.checkmark:after {
  content: "";
  position: absolute;
  display: none;
}

/* Show the indicator (dot/circle) when checked */
.container input:checked ~ .checkmark:after {
  display: block;
}

/* Style the indicator (dot/circle) 缩小尺寸改为主题色 */
.container .checkmark:after {
    top: 6px;
    left: 6px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #0f8c73;
}

修改后效果说明:

  • 未选中状态:白色背景+灰色细边框
  • hover状态:白色背景+绿色细边框
  • 选中状态:白色背景+绿色外围边框(即你要的外围圆环)+ 居中的小尺寸绿色实心圆点

内容的提问来源于stack exchange,提问作者AJ Jones

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.03 16:57:03