这是我参与8月更文挑战的第2天,活动详情查看: 8月更文挑战”juejin.cn/post/698796…
隐藏或者none都可以
1.原生写
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<style type="text/css">
div {
position: relative;
line-height: 30px;
}
input[type="radio"] {
width: 20px;
height: 20px;
opacity: 0;
}
label {
position: absolute;
left: 5px;
top: 8px;
width: 20px;
height: 20px;
/* border-radius: 50%; */
border-radius: 4px;
border: 1px solid #999;
}
/* 这只check 之后的样式 */
input:checked+label {
background-color: #0090FF;
border: 1px solid #0090FF;
}
input:checked+label::after {
position: absolute;
content: "";
width: 5px;
height: 10px;
top: 3px;
left: 6px;
border: 2px solid #fff;
border-top: none;
border-left: none;
transform: rotate(45deg)
}
</style>
<body>
<form>
<div>
<input id="nan" type="radio" name="sex" checked>
<label for="nan"></label>
<span style="margin-left: 10px">男</span>
</div>
<div>
<input id="nv" type="radio" name="sex">
<label for="nv"></label>
<span style="margin-left: 10px">女</span>
</div>
</form>
</body>
</html>
2.vue项目中使用
我用的是scss
::v-deep {
.el-radio__inner {
display: inline-block;
position: relative;
border: 1px solid #dcdfe6;
border-radius: 2px;
box-sizing: border-box;
width: 14px;
height: 14px;
background-color: #fff;
z-index: 1;
//小圆点消失
// transition: border-color 0.25s cubic-bezier(0.71, -0.46, 0.29, 1.46),
// background-color 0.25s cubic-bezier(0.71, -0.46, 0.29, 1.46);
}
.el-radio__input.is-checked + .el-radio__label {
color: #0090FF !important;
}
.el-radio__input.is-checked .el-radio__inner::after {
content: "";
position: absolute;
width: 8px;
height: 4px;
border: 1px solid white;
border-top: transparent;
border-right: transparent;
text-align: center;
display: block;
top: 2px;
left: 1.5px;
vertical-align: middle;
transform: rotate(-45deg);
border-radius: 0px;
background: none;
}
}