如何修改input的radio类型选中样式

清除原生样式:

input[type='radio'] {
          appearance: none; /* 用于覆盖默认的外观 */
          -webkit-appearance: none; /* Safari and Chrome */
          -moz-appearance: none; /* Firefox */
        }

设置默认选择框样式:

.customRadio {
          margin: 0;
          margin-right: 8px;
          display: inline-block;
          width: 20px;
          height: 20px;
          border-radius: 50%; /* 使其呈圆形 */
          border: 2px solid #ccc; /* 默认边框颜色 */
          position: relative;
        }

设置选中球样式:

 /*单选按钮选中后增加的样式*/
        > input[type='radio']:checked:before {
          content: '';
          display: block;
          width: 12px;
          height: 12px;
          background-color: #348930; /* 修改选中状态的颜色 */
          border-radius: 50%; /* 使其呈圆形 */
          position: absolute;
          top: 50%;
          left: 50%;
          transform: translate(-50%, -50%);
        }

 

posted @ 2024-03-16 22:23  SimoonJia  阅读(373)  评论(0编辑  收藏  举报