想做一个tab切换,但是又不想引入框架,于是自己写了一个简单的demo,先上结果
具体代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>改变默认radio</title>
<style>
#radioBox{
width: 180px;
height: 30px;
user-select: none;
border-radius: 4px;
border: 1px solid #5783fe;
}
#radioBox input {
display: none;
}
#radioBox label {
width: 60px;
height: 30px;
line-height: 30px;
float: left;
color: red;
font-size: 12px;
border-radius: 2px;
display: inline-block;
text-align: center;
}
#radioBox input:checked+label {
color: #fff;
background-color: #5783fe;
}
</style>
</head>
<body>
<div id="radioBox">
<input type="radio" id="radio1" name="sameName" checked>
<label for="radio1">选择1</label>
<input type="radio" id="radio2" name="sameName">
<label for="radio2">选择2</label>
<input type="radio" id="radio3" name="sameName">
<label for="radio3">选择3</label>
</div>
</body>
</html>