如何将这些传统的字形图标更新以与Bootstrap 5的FontAwesome一起使用?

huangapple go评论60阅读模式
英文:

How can I update this legacy glyphicons to work with Bootstrap 5's FontAwesome?

问题

以下是已翻译的内容:

以下的代码在使用 Bootstrap 3 时运行良好,但当我升级到 Bootstrap 5 时,glyphicon 不起作用。

以下是 HTML 代码,它呈现出漂亮的单选按钮。当选中一个选项时,应显示一个漂亮的 glyphicon,但在 Bootstrap 5 中无法正常工作。我该如何更新此代码以使其与 Bootstrap 5 兼容?

这是 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';
}

非常感谢您的帮助。谢谢。

英文:

The following code works well using Bootstrap 3, but when I update to Bootstrap 5, the glyphicon doesn't work.

The following is the HTML, which renders nice radio buttons. When an option is checked, it should show a nice glyphicon, but this doesn't work in Bootstrap 5. How can I update this code to work with 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>

This is the 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';
}

Any help is highly appreciated. Thanks.

答案1

得分: 1

这是使用Bootstrap 5更新的代码:

<!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 href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet">
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
</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">初学者</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">中级</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">高级</div>
      </label>
    </li>
  </ul>
</body>

</html>

请注意,我将"Beginner"翻译为"初学者","Intermediate"翻译为"中级","Advanced"翻译为"高级"。

英文:

Here is the Updated code using bootstrap 5

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

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=&quot;checkbox&quot;] {
display: none;
}
.chec-radio label.radio-inline input[type=&quot;checkbox&quot;]:checked+div {
color: #fff;
background-color: #000;
}
.chec-radio label.radio-inline input[type=&quot;checkbox&quot;]:checked+div:before,
.chec-radio label.radio-inline input[type=&quot;radio&quot;]:checked+div:before {
content: &quot;\f00c&quot;;
margin-right: 5px;
font-family: &quot;Font Awesome 5 Free&quot;;
font-weight: 900;
}
.chec-radio label.radio-inline input[type=&quot;radio&quot;] {
display: none;
}
.chec-radio label.radio-inline input[type=&quot;radio&quot;]:checked+div {
color: #fff;
background-color: #000;
}

<!-- language: lang-html -->

&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
&lt;meta charset=&quot;UTF-8&quot;&gt;
&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
&lt;title&gt;Bootstrap 5 Radio Buttons&lt;/title&gt;
&lt;link href=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot;&gt;
&lt;script src=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js&quot;&gt;&lt;/script&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css&quot;&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;ul class=&quot;chec-radio&quot;&gt;
&lt;li class=&quot;pz&quot;&gt;
&lt;label class=&quot;radio-inline&quot;&gt;
&lt;input type=&quot;radio&quot; checked=&quot;&quot; id=&quot;pro-chx-residential&quot; name=&quot;property_type&quot; class=&quot;pro-chx&quot; value=&quot;constructed&quot;&gt;
&lt;div class=&quot;clab&quot;&gt;Beginner&lt;/div&gt;
&lt;/label&gt;
&lt;/li&gt;
&lt;li class=&quot;pz&quot;&gt;
&lt;label class=&quot;radio-inline&quot;&gt;
&lt;input type=&quot;radio&quot; id=&quot;pro-chx-commercial&quot; name=&quot;property_type&quot; class=&quot;pro-chx&quot; value=&quot;unconstructed&quot; checked&gt;
&lt;div class=&quot;clab&quot;&gt;Intermediate&lt;/div&gt;
&lt;/label&gt;
&lt;/li&gt;
&lt;li class=&quot;pz&quot;&gt;
&lt;label class=&quot;radio-inline&quot;&gt;
&lt;input type=&quot;radio&quot; id=&quot;pro-chx-open&quot; name=&quot;property_type&quot; class=&quot;pro-chx&quot; value=&quot;open_land&quot;&gt;
&lt;div class=&quot;clab&quot;&gt;Advanced&lt;/div&gt;
&lt;/label&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/body&gt;
&lt;/html&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年6月15日 12:04:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76479037.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定