What is the best way to arrange these badges in a row?

I'm struggling to horizontally align these badges next to each other, as inline-block isn't working and they keep stacking vertically instead of side by side.

How can I achieve the alignment shown in the image below?

This is the desired appearance:

.tgr_card span {
    display: block;
    width: 150px;
    overflow: hidden;
    text-overflow: ellipsis; 
    white-space: nowrap;
}
<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>test</title>
        <link href="https://cdn.jsdelivr.net/npm/bootstrap@dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap/font/bootstrap-icons.css">
    </head>
    <body>

        <div class="card tgr_card" style="width: 30rem;">
            <div class="card-body">
                <h5 class="card-title d-flex justify-content-between align-items-center">
                    Name
                    <div class="text-end">
                        <button type="button" class="btn-close" aria-label="Close"></button>
                    </div>
                </h5>
                <h6 class="card-subtitle mb-2 text-muted">#x</h6>

                <br>

                <ul class="list-group list-group-flush tgr_card_ul">
                    <li class="list-group-item d-flex justify-content-between align-items-center">
                        Name
                        <span class="badge bg-primary rounded-2">test</span>
                    </li>
                    <li class="list-group-item d-flex justify-content-between align-items-center">
                        Min Max
                        <div class="row">
                            <div class="col">
                                <span class="badge bg-primary rounded-2">1</span>
                            </div>
                            <div class="col">
                                <span class="badge bg-primary rounded-2">None</span>
                            </div>
                        </div>
                        <!-- <div>
                            <span class="badge bg-primary rounded-2">1</span>
                            <span class="badge bg-primary rounded-2">None</span>
                        </div> -->
                        <!-- <span class="badge bg-primary rounded-2">1 | None</span> -->
                    </li>
                    <li class="list-group-item d-flex justify-content-between align-items-center">
                        Name
                        <span class="badge bg-primary rounded-2">test</span>
                    </li>
                </ul>
            </div>
            <div class="card-footer text-muted text-center">
                <a href="#" class="btn btn-primary" style="width: 100%;">footer</a>
            </div>
        </div>

        <script src="https://cdn.jsdelivr.net/npm/bootstrap@dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
    </body>
</html>

Using Bootstrap v5.3.0 alpha-1

Edit: The badges are aligned horizontally in the snippet, but what I mean is that I want them to be side by side and have the same width as the full-width badge above/below (refer to the attached image) - so both badges should be 50% width and consistent with the ones above and below.

Answer №1

.tgr_card span {
    display: block;
    width: 150px;
    overflow: hidden;
    text-overflow: ellipsis; 
    white-space: nowrap;
}
.half{
    width: 150px;
}
.half span{
width: 49%;
}
<!doctype html>
<!-- <html lang="en" data-bs-theme="dark"> -->
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>test</title>
        <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0e6c61617a7d7a7c6f7e4e3b203d203e236f627e666f3f">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f3919c9c878087819283de9a909c9d80b3c2ddc2c3ddc0">[email protected]</a>/font/bootstrap-icons.css">
    </head>
    <body>

        <div class="card tgr_card" style="width: 30rem;">
            <div class="card-body">
                <h5 class="card-title d-flex justify-content-between align-items-center">
                    Name
                    <div class="text-end">
                        <button type="button" class="btn-close" aria-label="Close"></button>
                    </div>
                </h5>
                <h6 class="card-subtitle mb-2 text-muted">#x</h6>

                <br>

                <ul class="list-group list-group-flush tgr_card_ul">
                    <li class="list-group-item d-flex justify-content-between align-items-center">
                        Name
                        <span class="badge bg-primary rounded-2">test</span>
                    </li>
                    <li class="list-group-item d-flex justify-content-between align-items-center">
                        Min Max  
                     <div class="half d-flex justify-content-between align-items-center ">
                      <span class="badge bg-primary rounded-2">1</span>
                      <span class="badge bg-primary rounded-2">None</span>
                        </div>
                        <!-- <div>
                            <span class="badge bg-primary rounded-2">1</span>
                            <span class="badge bg-primary rounded-2">None</span>
                        </div> -->
                        <!-- <span class="badge bg-primary rounded-2">1 | None</span> -->
                    </li>
                    <li class="list-group-item d-flex justify-content-between align-items-center">
                        Name
                        <span class="badge bg-primary rounded-2">test</span>
                    </li>
                </ul>
            </div>
            <div class="card-footer text-muted text-center">
                <a href="#" class="btn btn-primary" style="width: 100%;">footer</a>
            </div>
        </div>

        <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c0a2afafb4b3b4b2a1b080f5eef3eef0eda1acb0a8a1f1">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
    </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

"Struggling with the height of Bootstrap row not filling the entire space

I've tried everything but nothing seems to be working. Whether it's a simple height: 100% or experimenting with flex-grow: 1, none of it is doing the trick. I'm having issues with this site I'm currently working on: https://i.sstatic.n ...

Ways to sum up the values within a JSON object

Currently, I am using an AJAX call to fetch JSON data from an API. My goal now is to add up all the visits. This is what I have implemented so far. Any suggestions on how I can achieve that? $(document).ready(function() { var X = []; var Y = []; var d ...

I aim to break down a function into several functions using jQuery and AJAX for better organization and efficiency

I am working with a JavaScript file that includes an Ajax function to fetch data from a JSON file on a server. The goal is to interpret this data into a table, but I would like to break down the process into separate functions for generating links, dates, ...

Alternative content can be pasted into the webpage

After finding out a peculiar phenomenon related to copy and paste, I decided to share it. If you head over to the Diablo 3 website () and scroll down to the bottom of the page, you will notice: ©2012 Blizzard Entertainment, Inc. All rights reserved A ...

What is the best way to target an anchor element that includes a particular word using jquery or css?

I attempted $('a[title="*"]').find('contains("PDF")').css({'background-color':'red'}); Unfortunately, this code is not working as expected. To clarify, I am searching for a specific word in the title. ...

Comparing Embedded and Linked JS/CSS

In my experience, I understand the advantages of using linked CSS over embedded and inline styles for better maintainability and modularity. However, I have come across information suggesting that in certain mobile web development applications, it may be m ...

What is the correct method for asynchronously loading CSS files in web development?

On a mission to enhance my website's performance, I set out to achieve the perfect score on PageSpeed Insights. Everything was going smoothly until I encountered an issue with CSS delivery. I initially achieved a flawless result by utilizing the prel ...

Trouble with CSS3 Menu Layout and Gradient Display Issues

My task is to replicate this menu: I'm having trouble creating the gradient. Completed Why can't I see it in my code? http://jsfiddle.net/Vtr6d/ Here's what I currently have: CSS: .mainOptions{ float:left; margin:0 20px 0 20px; ...

Tips for handling the !important declaration when creating a customized bootstrap theme

Exploring the Color Dilemma After creating a simple website in Bootstrap 4.1 with a distinct shade of purple, I encountered an issue with specificity when it came to customizing button states. To address this, I introduced a CSS class called .btn-purple ...

Ways to consistently pause background image in CSS?

I have successfully created a slider using the Slider Revolution Wordpress plugin and am currently customizing it with CSS. I have added a small open space within the slider to display logos of the technologies that I am utilizing. Around this space, I hav ...

Display JavaScript and CSS code within an Angular application

I am working on an Angular 1.x application (using ES5) where I need to display formatted CSS and JS code for the user to copy and paste into their own HTML file. The code should include proper indentations, line-breaks, etc. Here is a sample of the code: ...

Designing a layout for a chat application that is structured from the bottom up

I'm currently in the process of designing a web application for a chat platform. I have access to an API that provides a list of messages: chatsite.com/api/thread/1/messages/ [ { "id": 2, "sender": { "id": 2, ...

The footer navigation in CSS shifts position when it is hovered over

My attempt to add a <nav> at the footer was unsuccessful. The navigation bar in this fiddle is completely wrong as the entire nav moves when hovered, even though I did not include any animations. I want the items in the <nav> to stay fixed. ...

Troubles with NextJS and TailwindCSS Styling

I encountered a strange issue when I used the component separately. Here's how the code looked like: <> <Head> <title>Staycation | Home</title> <meta name="viewport" content="initial- ...

Arrange the text in a div element in a horizontal direction

While developing a friends list script for a website, I encountered an interesting UI issue in the chat section. When a lengthy chat message is added to the chat content div with the CSS attribute overflow: scroll, it causes the div to stretch out horizont ...

What are the techniques for implementing an if statement in CSS or resolving it through JavaScript?

Demo available at the bottom of the page Within my code, there is a div called #myDiv that defaults to an opacity of 0. Upon hovering over #myDiv, the opacity changes to 1. See the CSS snippet below: #myDiv { opacity: 0; } #myDiv:hover { opacity: 1 ...

Why does my contact form display PHP code unexpectedly?

I've been following a YouTube tutorial to create a responsive single-page website using Bootstrap. The tutorial covered the front-end, but now I'm stuck on integrating a contact form. I added some PHP code I found online, but there seems to be an ...

What is the best way to adjust the size of the close button in react-bootstrap for a unique design?

<CancelButton className="exitBtn"/> .exitBtn{ height:40px; width:35px; } I'm trying to adjust the dimensions of the cancel button, but for some reason it's not working. Can someone provide guidance on how to successfully ...

Ways to initiate a CSS transition without hovering over it

Currently, I have a sidebar that is hidden and only shows up when the mouse hovers over it. I'm wondering how I can make the CSS transition trigger before the mouse hover, similar to what happens in this sidebar link: . Any advice on how to achieve th ...

Issues arising with VueJS array props when integrating Bootstrap

I am attempting to display two divs next to each other while iterating through props (which are essentially an array) in VueJS. When I have just a single element, everything functions properly. However, as soon as I include the v-for directive, the element ...