What is the best way to format a card header in bootstrap 4 so that it displays three elements in a row and truncates the text in the middle element on smaller screens?

I am currently working with a set of cards to create an accordion. Each card consists of a card header and a card body.

Within each card header, there are four elements: an <i> tag for a carat icon, an <h4> tag displaying the title of the card, an <input> tag for user input data, and a final <h4> tag representing a % character.

The goal is to have the first two elements (<i> and the first <h4>) float left, with the text wrapping in line with the remaining space between elements. The <input> and final <h4> should remain fixed at the right end of the line. It's important that all four elements always remain on the same line without stacking, and adapt their display across different devices.

After spending several hours researching and experimenting with various CSS classes like .d-flex, .clearfix, .float-left/right, as well as different container structures, I've encountered difficulties in achieving the desired layout. Issues include aligning the elements properly and ensuring proper text truncation with .text-truncate.

How can I structure the cards to consistently achieve the desired layout?

Here is a snippet of the code for the card header:

<div class="card-header">
    <div class="row">
        <div class="col-sm-4 col-md-6">
            <a class="card-link" data-toggle="collapse" data-target="#collapseFive" aria-expanded="true" aria-controls="collapseFive">
                <div class="row" style="display: block;">
                    <i class="far fa-caret-square-down fa-2x mr-1"></i>
                    <h4 class="text-truncate">Education, Emp., Social Services</h4>
                </div>
            </a>
        </div>
        <div class="col-sm-4 col-md-6">
            <div class="row justify-content-center justify-content-md-end align-items-center">
                <input type="number" name="cat-edTrainEmp" class="form-control-sm mr-1 survey" id="cat-edTrainEmp" max="100" min="0" required><h4>%</h4>
            </div>
        </div>
    </div>
</div>

The expected outcome for the card header should resemble this example: card header structure

Answer №1

To address the formatting issues, I took out the .row and .column classes from the card and added the .d-flex class to the card-header, which resolved the unwanted stacking problem. In addition, I fixed the .text-truncate issue by separating the link reference into individual elements. See the updated code snippet below:

<div class="card-header d-flex">
  <a class="card-link" data-toggle="collapse" data-target="#collapseFour" aria-expanded="true" aria-controls="collapseFour">
    <i class="far fa-caret-square-down fa-2x mr-1"></i>
  </a>
  <a class="card-link text-truncate mr-auto" data-toggle="collapse" data-target="#collapseFour" aria-expanded="true" aria-controls="collapseFour">
    <h4 class="text-truncate">Income Security</h4>
  </a>
  <input type="number" name="cat-incomeSec" class="form-control-sm survey ml-1" id="cat-incomeSec" max="100" min="0" required>
  <h4 class="">%</h4>
</div>

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

How can I retrieve all values from an input number field that is created using *ngFor in Angular?

In my table, I have a list of cart products displayed with a quantity field. Users can increase or decrease the quantity using options provided. Currently, if I place an update button inside a loop, it creates separate buttons for each product. However, I ...

What is the best way to combine 4 small triangle pieces in order to create one large triangle?

Is there a way to create an image background with triangle shapes by combining small triangles together? I am interested in making this collection of triangle image backgrounds. Can someone guide me on how to do it?! .block { width: 0; height: ...

Tips for inserting values into a string array using jQuery or Angular 7

I have a series of checkboxes with values obtained from a loop. Instead of pushing these values into an array, I need to join them together as "parent1", "parent2", "parent3" and display the result in the console. Below is the code snippet for reference: ...

Modifying the font style within an ePub document can affect the page count displayed in a UIWebView

Currently in the development phase of my epubReader app. Utilizing CSS to customize the font style within UIWebView, however encountering a challenge with the fixed font size causing fluctuations in the number of pages when changing the font style. Seeki ...

How can I assign a unique background color to each individual column within a RadioButtonList?

I have an issue with setting 3 repeated columns. I want to assign different background colors to each of them. If you have any ideas on how I can achieve this, please share. Here is the code for my RadioButtonList: <asp:RadioButtonList ID="rblTimeSlot ...

Is it possible to utilize Apache FOP for the conversion of any HTML document to a PDF file?

I attempted to utilize Apache FOP for the purpose of converting HTML to PDF, going through the steps of HTML --> XHTML --> XSL-FO --> PDF. For the conversion from xhtml to XSL-FO, I made use of the xhtml2fo.xsl tool from Antenna House. While this ...

In Laravel Blade, you can dynamically add rows and columns based on a certain condition

I'm working on creating a user interface for cinema seats in Laravel Blade. The database includes seat rows and columns, and the rows will be the same for two consecutive rows. For example, the first row could have an id of 1 with seat_row:1 and seat_ ...

How can I iterate over an array in JavaScript to create posts for an HTML feed using Bootstrap?

I have created a simple Bootstrap website in HTML that resembles a news feed. To populate the feed with various posts, I am using Javascript to work with arrays containing images, headlines, and captions for each post. My initial approach involves looping ...

jQuery - Navbar with both horizontal and vertical orientation

I'm new to JavaScript and jQuery, and I'm looking to create a vertical nav/slider that follows the cursor when hovering over horizontal navbars links to reveal sub-links, essentially creating a dropdown menu effect. While I don't expect any ...

What is the best way to display the identical HTML page for both online and offline applications?

I am facing a challenge with my application, as I need to ensure that it can also be accessed offline. While I can easily create dynamic content on the client side using Javascript and JQuery instead of relying on server-side processing, I am struggling wi ...

Having numerous calls to isNaN within a JavaScript if-else statement

I've created a JavaScript function that generates div elements and styles them based on user input values. However, I'm facing an issue when trying to display a warning message if the input is not a number. Currently, I'm unable to create th ...

How can I use jQuery to display a div alongside the element that is currently being hovered over?

Imagine having multiple divs similar to these: UPDATE: <div class="ProfilePic"> <a href="#"> <img src="lib/css/img/profile_pic1.png" alt="" class="ProfilePicImg"/> </a> <div class="PopupBox" style="display: ...

Place the div at the center within the header

I'm struggling to center the logo in my media query for screens below 479px. Whenever I use margin auto, the image gets pushed to the right by the browser. Here is what I have so far and any assistance would be greatly appreciated. HTML <div clas ...

The Modal Bootstrap source code does not match the information displayed in Chrome

Currently tackling an e-commerce project that is causing some technical hiccups. Using both Bootstrap and Django for this endeavor, I apologize in advance for the lengthy query. The core issue lies within a loop that iterates through my product database a ...

Fixed Sidebar and Dynamic main content with top and bottom sections

Hello, I've been encountering an issue with coding the layout of my website. I want the sidebar to remain fixed regardless of screen size, while also making sure that the content area adjusts fluidly. The header is staying at the top as desired, but I ...

Tips on transitioning from Modal1 to Modal2 in Ionic after a successful submit button press?

My survey app requires users to fill out a form and click the Submit Feedback button. Upon successful submission, a message saying "Feedback submitted successfully" should be displayed in Modal2, which is inside another modal named (Modal1). However, being ...

Ways to access the value of an input field using Javascript

I am currently utilizing the valums-file-uploader plugin for file uploads via ajax. However, I have encountered an issue with its functionality. Below is the script that I am using: <input type="text" id="Gaurav" name="Gaurav" /> <script src="fil ...

How should form elements be named and handled for avoiding duplication?

Suppose my form contains 2 inputs <input name="person_name" value="John" type="text" /> <input name="person_name" value="Jean" type="text" /> After submitting the form, which "person_name" will be received? John or Jean? Also, what if I have ...

What is causing the pull-right class to not function correctly in Bootstrap version 4.1.0?

After upgrading from Bootstrap version 3+ to 4.1.0, I encountered an issue with aligning elements using pull-right and pull-left, as well as float-right and float-left. The problem persists despite my efforts. Here is an image (https://i.sstatic.net/Z6ba3. ...