What steps do I need to take to integrate the old glyphicons into Bootstrap 5 using FontAwesome?

I've encountered an issue when updating from Bootstrap 3 to Bootstrap 5. The glyphicon no longer works in the following code:

The HTML below displays nice radio buttons, but the glyphicon that should appear when an option is checked doesn't work with Bootstrap 5. How can I modify this code to be compatible 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 CSS styling is used in the code:

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

If anyone has suggestions on how to resolve this issue and make it work with Bootstrap 5, your help would be greatly appreciated. Thank you.

Answer №1

Check out the revised code implementation with 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>Improved Bootstrap 5 Radio Buttons</title>
  <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="61030e0e15121513001121544f534f52">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet">
  <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9dfff2f2e9eee9effceddda8b3afb3ae">[email protected]</a>/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">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>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having trouble creating a full-screen modal with NgbModal by passing content as a component?

I've been using Bootstrap widgets and trying to create a full-screen modal where the header sticks on top, the footer stays at the bottom, and the body scrolls in the middle. Initially, I found a simple HTML solution for this: However, when I want to ...

Update the appearance of a webpage using a custom JavaScript function

My goal is to modify a CSS style whenever a button is clicked. In order to achieve this, I have implemented a JavaScript function that creates a new class for CSS along with several other functionalities. Here's how the JS function currently appears: ...

Creating a background color without using the <canvas id> element can be achieved by utilizing CSS properties such as

As a novice in the world of HTML and CSS, I find myself working on creating my website using HTML. Upon inspecting my site, I notice that the default background color is white. Despite trying to change it by using #canvas { background-color: black; } in ...

What can I do to prevent my website's font from getting distorted due to the recommended display settings?

I've noticed that newer laptops typically have a display font-size recommendation of 150%, which is causing issues with viewing my webpage correctly. The items appear larger and stretched out on their screens. Is there a way to ensure that users can ...

Does anyone know why this code isn't functioning properly on Firefox?

This code performs as intended in Chrome, but unfortunately does not function properly in Firefox. ul { list-style:none; } li { display:inline-block; border:1px solid black; } a { display:block; margin:10px; } a:hover { positio ...

Adjust the color of both the image and text when hovering over either one

I need help creating a hover effect for an image and text pair. My goal is to have the image change when hovered over, along with changing the color of the text next to it. Below is the code I am currently working with: <ul id="recherche"> < ...

A full-width CSS menu featuring dropdowns beneath each entry for easy navigation

Check out the JSFiddle here I've created a full-width CSS menu that spans the entire screen, but I'm struggling to figure out how to make the corresponding subnav items appear below their parent items. Is it even possible to achieve this design ...

Triggering a Bootstrap 5 dropdown through code is only effective within the browser's developer console, rather than standard JavaScript implementation

I attempted to display a Bootstrap5 dropdown by clicking on a link in my web application. Despite trying various methods, such as dispatching events and utilizing the bootstrap Dropdown classes, I was unable to achieve success. Interestingly, both approach ...

Changing the text color of an active button in Bootstrap

Hello everyone, I've been struggling to find a solution to my issue and I could really use some help. The problem I'm facing is changing the text color of the active button in Bootstrap. Specifically, after clicking on a button, I want it to tra ...

mismatch between margin-left and auto not aligning

Having trouble with margin-left: auto not working 1- Looking to create a header with an image and a navbar 2- Want two unordered lists in the navbar 3- Trying to position one list on the left side and the second on the right side When I use margin-left: 8 ...

What is the method for centering an input field with inline CSS?

Is there a way to center align an input text box on a webpage using only inline CSS? I have tried various techniques, including the following code snippet, but nothing seems to work: <input type="text" id="myInput" style= "margi ...

Is it possible to tap into the stylus Abstract Syntax Tree (AST) for

Is there a way to access the abstract syntax tree (AST) of the CSS style generated by stylus without re-parsing it using css-parse? I'm curious if the AST of the generated styles can be accessed publicly. ...

Position the divs on the left and right sides of the central div

I have a total of 7 divs, with one designated for the middle position. The goal is to display the top two pictures and the knife aligned correctly, but the rest are not appearing as desired. Below is the CSS code: .vegetablewrapper { width: 100%; ...

Using React Native's stylesheet to apply multiple values in a CSS statement

Here's a scenario to help clarify my question: Imagine I want to add margin to an element in the following way: const myView = () => <View style={styles.viewStyle}></View> const styles = StyleSheet.create({ viewStyle: { margin: ...

Give your screen a quick swipe with Ionic's pull-to-refresh

Is there a way to bring the footer of an ionic app closer for refresh or loading more content? I am particularly curious about how to implement the 'pull up to refresh' feature using HTML, CSS, or the Ionic content component. ...

Modify the class of an input while typing using Jquery

Recently, I created a form using Bootstrap 4. The validation process is done through a PHP file with an AJAX call and it's functioning correctly, except for one issue. I want the input class to switch from "invalid" to "valid" as soon as the user begi ...

I'm having trouble getting my footer to stay at the bottom of the page

Struggling to get my footer to stay at the bottom on my blog pages, no matter what I try: Every time the social media section appears, the footer slides up... Can't figure out why... Appreciate any assistance! ...

I want to have a video playing in the background of my home page, but when viewers access it on their mobile devices, I would like to display a specific image instead

Is there a specific attribute I can include to make the image display instead of the video on mobile or small devices? ...

Solid white border encasing the full page

While I know there have been similar questions asked before, I believe mine is unique because I haven't found a solution anywhere. Recently, I started a new project in React. I decided to remove App.css and index.css, and created a single component wh ...

What is the significance of the border classes having an overriding color property in Bootstrap?

When adding a border to my navigation menu, I initially thought using the Bootstrap .border class would be the best approach. However, upon examining the code generated by this class, I noticed that it uses an !important declaration on the color property ...