Using Bootstrap 4: How to maximize the width of a span element placed near a label

I need to adjust the width of a span next to its label in my project.

My goal is to show multiple groups {label / data} on the same line. To achieve this, I divided the row into 4 columns and tried to set a specific width for a span. However, no matter what I do, the size does not change...

Here is the code snippet:

<div class="row">   
    <div class="col-xl-4">
        <label class="">Batch ID : </label>
        <span class="border padding_right5 padding_left5 col-xl-3">4444</span>
    </div>    
    <div class="col-xl-4">
         <label class="">Etat : </label>
         **<span class="border border_etat_batch statut_green">En Cours</span>**
    </div>      
    <div class="col-xl-2">
        <label>Ligne : </label>
        <span class="border border_data">1</span>
    </div>  
    <div class="col-xl-2 text-right">
        <label>Cuve : </label>
        <span class="border border_data">B1</span>
    </div>                                                                                                                                                      
</div>  

View Result

Answer №1

In Bootstrap v4, the -xl classes are no longer available. The alternative is to use col-{num} for extra small devices or col-sm-{num} for small devices.

To fill the space of the span tag, you can utilize the flex-fill class from Bootstrap flex utilities. More information on this can be found here.

<div class="col-4 d-flex">
         <label class="">Etat : </label>
         **<span class="border border_etat_batch statut_green flex-fill">En Cours</span>**
    </div> 
.statut_green{
background:green;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">   
    <div class="col-4">
        <label class="">Batch ID : </label>
        <span class="border padding_right5 padding_left5 col-3">4444</span>
    </div>    
    <div class="col-4 d-flex">
         <label class="">Etat : </label>
         **<span class="border border_etat_batch statut_green flex-fill">En Cours</span>**
    </div>      
    <div class="col-2">
        <label>Ligne : </label>
        <span class="border border_data">1</span>
    </div>  
    <div class="col-2 text-right">
        <label>Cuve : </label>
        <span class="border border_data">B1</span>
    </div>                                                                                                                                                      
</div>

Answer №2

Presenting the solution:

.col-filled {
  display: flex;
}

.d-inline {
  flex: 1 1 auto
}

.statut_green {
  background: green;
  flex: 1 1 auto
}
<link href="http://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">   
    <div class="col-xl-4">
        <label class="">Batch ID : </label>
        <span class="border padding_right5 padding_left5 col-xl-3">4444</span>
    </div>    
    <div class="col-filled col-xl-4">
         <label class="">Etat : </label>
         **<span class="border border_etat_batch statut_green">En Cours</span>**
    </div>      
    <div class="col-filled col-xl-2">
        <label class='d-inline'>Ligne : </label>
        <span class="d-inline border border_data">1</span>
    </div>  
    <div class="col-xl-2 text-right">
        <label>Cuve : </label>
        <span class="border border_data">B1</span>
    </div>                                                                                                                                                      
</div>  

Link

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

<ul> hover effect and text </ul>

Looking for a solution to activate hover state on both the box and text when rolling over tiled images with text underneath. Check out this example in the Fiddle: http://jsfiddle.net/techydude/GF8tS/ Any suggestions on how I can achieve this effect? ...

Are Your Padding Styles Missing?

I've noticed that the text under the photos on this page in the main section (a.event) is not displaying the 5px padding top and bottom. Any suggestions for fixing this? Thank you! =) a.event { width:315px; height:auto; border:0; padding: 5px 0; } ...

My HTML grid table is not being properly rendered by the JSON data

I'm currently facing a challenge with rendering my HTML grid table in Angular using JSON data retrieved from a MySQL database. I would greatly appreciate any assistance or guidance on how to solve this issue. View the output of the Angular code here ...

What is the best way to align a box once another one has been placed?

I have integrated both Bootstrap and Masonry plugins into my website design. The issue I am facing is that the Masonry plugin box goes under the top Bootstrap bar. I tried adding a margin-top: 50, but this resulted in a horizontal scroll bar appearing. To ...

The width of the Div element is not following the specified dimensions, and it also has an unspecified margin

Check out my code snippet at: http://jsfiddle.net/8z4aw/ I'm trying to create a table-like layout using div elements, but for some reason the browser is not respecting the specified widths and seems to be adding an unwanted right margin. Where is thi ...

show an HTML webpage within a <div> container using AJAX technology

I am trying to include an HTML page named Introduction.html (located in the same folder as x.html) within div1. However, it does not seem to be loading properly. Below is a snippet of the code from x.html x.html <!DOCTYPE html> <h ...

Using JQuery to reverse the action of hiding an image

Having some trouble with my Javascript and JQuery skills, so bear with me. I've set up a gallery of images where users can drag and drop them into a designated drop zone. Everything works fine when dragging an image from the gallery to the drop zone a ...

Switching the WordPress dropdown menu from a hover function to a click function

Is it possible to modify the WordPress menu dropdown behavior from hover to onclick? I want the menu to appear when an item is clicked, but WordPress currently requires hovering. Below is what I've tried so far, but it has not been successful. Jquery ...

What are some ways to personalize a scrollbar?

I am looking to customize the scrollbar within a div. I attempted to modify it using the code below, but I encountered difficulties when trying to change the scroll buttons and did not achieve my desired outcome. Additionally, this customization did not wo ...

Adding an id to a ul tag using JavaScript

I am trying to dynamically add an ID called "myMenu" using JavaScript to a ul element for a search filter. Unfortunately, I am unable to directly access the ul tag to change it, so I need to do it via JavaScript. As I am new to JavaScript, I am looking t ...

Choosing elements in jQuery

Having some trouble with the subnav on my current website project. I think the issue lies in how I am selecting items in my jquery code. It seems like a small fix that needs to be made, but I'm unsure of the correct approach. http://jsfiddle.net/ZDEr ...

Using jQuery's sortable functionality to rearrange rows in a table can cause conflicts with Angular's orderBy feature

In the past, my angular app used a table with orderBy to sort rows based on a specific column. By clicking on a table header, the orderBy arguments would change and the list would be sorted according to the values in that column. Now, I am experimenting w ...

Upon returning to the previous page, the checkbox remains checked and cannot be unchecked

Here is the code I'm using to append checkbox values with a hash in the URL. However, when navigating back, the checkboxes remain checked. Take a look at the code snippet below: <html> <head> <script src="http://ajax.googleapis.com/aja ...

Allow the div to break out of the overflow: hidden property without disrupting the overall page layout

Currently, I am attempting to separate a child element from its parent that has overflow: hidden applied. The main reason for restricting the dimensions of the parent is for a JavaScript workaround. I have experimented with positioning the child element, ...

The function is not recognized in C# programming language

Whenever I try to trigger functions by clicking buttons, nothing seems to happen and an error message appears in the console. Uncaught ReferenceError: AddressInputSet is not defined at HTMLButtonElement.onclick I'm new to this and could use ...

Side-to-Side Bootstrap Display Panel

I have been attempting to customize a Bootstrap panel to create a horizontal version, but I am struggling to align the panel heading vertically with the content in the panel body. I believe it may be related to clearing the divs. Front-end development is ...

Tips for extracting the chosen value from a dropdown list within a table cell using JavaScript

Here is an example of an HTML element: <td> <select> <option value="Polygon 47">Polygon 47</option> <option value="Polygon 49">Polygon 49</option> </select> </td> I am looking for a ...

Enhancing the appearance of the CSS panel with Font Awesome icons

I need help adding a fontawesome or any other icon to my CSS3 based sliding panel button. The icon should change from open to close when clicked on. Any ideas on how to achieve this would be greatly appreciated! * { margin:0; padding:0; font-famil ...

The collapse feature in bootstrap-vue's navbar does not work properly on mobile devices when trying to uncollapse it by clicking a button within

I have utilized bootstrap-vue to create a navigation bar for my vue.js application. Everything works as expected when the elements are clicked and the navbar uncollapses. However, I decided to replace one of the nav items with a button so that I could hi ...

Change wiki text into HTML using Python for showcasing on a webpage

Despite trying various tools for 6 hours, I have been unable to find one that can properly interpret wikitext like the example below: '<center>Welcome to the world's foremost open content<br><big><big><big>'&ap ...