下面的代碼在使用Bootstrap 3時運行良好,但是當我更新到Bootstrap 5時,這個圖標不工作了。
下面是呈現漂亮單選按鈕的HTML。當一個選項被選中時,它應該會顯示一個漂亮的圖標,但是這在Bootstrap 5中不起作用。我該如何更新這段代碼來使用Bootstrap 5?
<ul class="chec-radio">
<li class="pz">
<label class="radio-inline">
<input type="radio" checked="" id="pro-chx-residential" name="property_type" class="pro-chx" value="constructed">
<div class="clab">Beginner</div>
</label>
</li>
<li class="pz">
<label class="radio-inline">
<input type="radio" id="pro-chx-commercial" name="property_type" class="pro-chx" value="unconstructed" checked>
<div class="clab">Intermediate</div>
</label>
</li>
<li class="pz">
<label class="radio-inline">
<input type="radio" id="pro-chx-open" name="property_type" class="pro-chx" value="open_land">
<div class="clab">Advanced</div>
</label>
</li>
</ul>
這是CSS:
ul.chec-radio {
margin: 15px;
}
ul.chec-radio li.pz {
display: inline;
}
.chec-radio label.radio-inline input[type="checkbox"] {
display: none;
}
.chec-radio label.radio-inline input[type="checkbox"]:checked+div {
color: #fff;
background-color: #000;
}
.chec-radio .radio-inline .clab {
cursor: pointer;
background: #e7e7e7;
padding: 7px 20px;
text-align: center;
text-transform: uppercase;
color: #333;
position: relative;
height: 34px;
float: left;
margin: 0;
margin-bottom: 5px;
}
.chec-radio label.radio-inline input[type="checkbox"]:checked+div:before {
content: "\e013";
margin-right: 5px;
font-family: 'Glyphicons Halflings';
}
.chec-radio label.radio-inline input[type="radio"] {
display: none;
}
.chec-radio label.radio-inline input[type="radio"]:checked+div {
color: #fff;
background-color: #000;
}
.chec-radio label.radio-inline input[type="radio"]:checked+div:before {
content: "\e013";
margin-right: 5px;
font-family: 'Glyphicons Halflings';
}
非常感謝任何幫助。謝了。
下面是使用bootstrap 5更新的代碼
ul.chec-radio {
margin: 15px;
padding: 0;
}
ul.chec-radio li.pz {
display: inline-block;
margin-right: 10px;
vertical-align: middle;
}
.chec-radio .radio-inline .clab {
display: flex;
align-items: center;
cursor: pointer;
background: #e7e7e7;
padding: 7px 20px;
text-align: center;
text-transform: uppercase;
color: #333;
position: relative;
height: 34px;
margin: 0;
margin-bottom: 5px;
}
.chec-radio label.radio-inline input[type="checkbox"] {
display: none;
}
.chec-radio label.radio-inline input[type="checkbox"]:checked+div {
color: #fff;
background-color: #000;
}
.chec-radio label.radio-inline input[type="checkbox"]:checked+div:before,
.chec-radio label.radio-inline input[type="radio"]:checked+div:before {
content: "\f00c";
margin-right: 5px;
font-family: "Font Awesome 5 Free";
font-weight: 900;
}
.chec-radio label.radio-inline input[type="radio"] {
display: none;
}
.chec-radio label.radio-inline input[type="radio"]:checked+div {
color: #fff;
background-color: #000;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bootstrap 5 Radio Buttons</title>
<link rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
<link rel="stylesheet" >
</head>
<body>
<ul class="chec-radio">
<li class="pz">
<label class="radio-inline">
<input type="radio" checked="" id="pro-chx-residential" name="property_type" class="pro-chx" value="constructed">
<div class="clab">Beginner</div>
</label>
</li>
<li class="pz">
<label class="radio-inline">
<input type="radio" id="pro-chx-commercial" name="property_type" class="pro-chx" value="unconstructed" checked>
<div class="clab">Intermediate</div>
</label>
</li>
<li class="pz">
<label class="radio-inline">
<input type="radio" id="pro-chx-open" name="property_type" class="pro-chx" value="open_land">
<div class="clab">Advanced</div>
</label>
</li>
</ul>
</body>
</html>
上一篇SVG圓形遮罩光標