看一些大佬的博客总能有各种收获啊,下面是一个很实用的小技巧,只是通过 css 就实现了美化 原生的 radio 框框
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<div class="radio-beauty-container">
<label>
<span class="radio-name">前端工程师</span>
<input type="radio" name="radioName" id="radioName1" hidden/>
<label for="radioName1" class="radio-beauty"></label>
</label>
<label>
<span class="radio-name">后端工程师</span>
<input type="radio" name="radioName" id="radioName2" hidden/>
<label for="radioName2" class="radio-beauty"></label>
</label>
<label>
<span class="radio-name">全栈工程师</span>
<input type="radio" name="radioName" id="radioName3" hidden/>
<label for="radioName3" class="radio-beauty"></label>
</label>
</div>
</body>
</html>
.radio-beauty-container {
font-size: 0;
}
.radio-beauty-container .radio-beauty:hover,
.radio-beauty-container input[type="radio"]:checked + .radio-beauty {
padding: 3px;
background-color: black;
background-clip: content-box;
}
.radio-beauty-container .radio-name {
vertical-align: middle;
font-size: 16px;
}
.radio-beauty-container .radio-beauty {
width: 18px;
height: 18px;
box-sizing: border-box;
display: inline-block;
border: 1px solid #000;
vertical-align: middle;
margin: 0 15px 0 3px;
border-radius: 50%;
}
.radio-beauty-container .radio-beauty:hover {
box-shadow: 0 0 7px green;
}