Three dots implemented in the heading of a card

In my Bootstrap 4 project, I am aiming to design a card header with three distinct parts.

  1. The left part will showcase the author.
  2. The middle section will present a preview of the content.
  3. The right part will display the date.

Specifically, I want the middle part to be cut off with an ellipsis if it exceeds the available space. It should extend from the left to the right part with a margin of ml-5 and mr-5. The content should be in a single line.

Below is the snippet of code I have been working on:

<div class="container">
    <div class="row">
        <div class="col-8">
            <div class="card">
                <div class="card-header">
                    <span class="float-left">
                        John Seed
                    </span>
                    
                    <span class="ml-5 mr-5 text-muted" style="text-overflow: ellipsis; white-space: nowrap; overflow: hidden; display: inline-block;">
                        (Content Preview)
                    </span>
                    
                    <span class="float-right">
                        10-Mar-2020
                    </span>
                </div>
                <div class="card-body">
                    This is card content.
                </div>
            </div>
        </div>
    </div>
</div>

Preview:

https://i.sstatic.net/6AuMd.png

Adding a fixed width: 300px to the middle part makes the ellipsis display correctly. However, I prefer a flexible width.

Answer №1

If you want to improve your layout, simply add the d-flex class to the parent container. Discover more about d-flex here

I highly suggest removing the float in this scenario as it is unnecessary. It is always better to avoid using floats whenever you can and utilize flexbox instead. Floats can disrupt your layout and require clearing.

Edit: To ensure that the left and right span elements do not break into a new line, include the .text-nowrap class from Bootstrap Utility.

<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
    <div class="row">
        <div class="col-8">
            <div class="card">
                <div class="card-header d-flex">
                    <span class="text-nowrap">
                        John Seed
                    </span>
                    
                    <span class="ml-5 mr-5 text-muted" style="text-overflow: ellipsis; white-space: nowrap; overflow: hidden; display: inline-block;">
                        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas finibus vitae magna id aliquam. Phasellus luctus ut ligula eu dignissim. Praesent sodales, nisi quis sodales euismod, enim ante suscipit ex, in cursus est metus nec sem. Pellentesque pharetra lobortis sem in tempus. Morbi turpis leo, rhoncus in eleifend id, pellentesque nec metus. Maecenas commodo scelerisque pellentesque. Suspendisse rhoncus at augue at egestas. Ut in erat ut justo tincidunt suscipit ac sit amet urna. Curabitur lacinia diam sit amet velit gravida hendrerit. Duis a orci quis enim iaculis ultrices. Duis finibus lorem et ipsum fringilla, feugiat ullamcorper turpis lacinia. Nunc vulputate in tortor ac lacinia. Pellentesque nec nibh ut est consequat condimentum vel ut velit. Phasellus elementum vel dui vitae lacinia. Nulla et placerat dui, a laoreet lectus.
                    </span>
                    
                    <span class="text-nowrap">
                        10-Mar-2020
                    </span>
                </div>
                <div class="card-body">
                    This is card content.
                </div>
            </div>
        </div>
    </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

Incorrect column alignment in Tailwind CSS

I am working on a straightforward flexbox layout with a two-column grid setup. <div class="flex relative"> <div class="columns-2 gap-4 space-y-4"> <div class="bg-red-500 p-10">1</di ...

Responsiveness of the element along the vertical axis

I have an element that, when clicked, should display additional content. However, when the headline contains a lot of text, the element does not expand vertically as it should. Thank you for your help! Check out how it looks currently This is my HTML co ...

Dealing with AngularJS: Issue arises when attempting to inject $modal into a controller nested within a directive

Our team has implemented a custom directive that wraps around a checkbox and utilizes transclusion to inject content into it. Here is an example of the setup: somecheckbox.js angular.module('namespace.directives') .directive('someCheckbox& ...

Is there a way to adjust the width of the b-form-select component?

My issue lies with the b-form-select element, as it defaults to a width of 100%. I attempted adjusting the width like so, but unfortunately it did not have the intended effect. <b-form-select v-model="xxx" :options="yyy" width: 50% ...

When designing responsive websites in Bootstrap 4, what is the preferred choice between using the class "container" or "container-fluid"?

When creating responsive designs, which is more effective to use - the .container class or the .container-fluid class? ...

AngularJS: Modifying values in one div updates data in all other divs

The webpage appears as shown below: https://i.sstatic.net/IxcnK.png HTML <li class="list-group-item" ng-repeat="eachData in lstRepositoryData"> <div class="ember-view"> <div class="github-connection overflow-hidden shadow-oute ...

Is there a way to modify a button's aspect ratio when it is clicked?

Currently, I am utilizing the MUI v5 AppBar to craft a navigation bar with Tabs. My aim is to have the background of the Tab blend seamlessly with the main page background upon being clicked, as illustrated here: https://i.sstatic.net/e4bDn.png However, a ...

Exploring the Integration of HTML5 with Android

I recently began diving into Android development and want to incorporate HTML5 as a cross-platform technology. However, I'm not familiar with HTML5 or how it interacts with Android. Despite my efforts to research this topic, I still feel lost on where ...

Cordova: Opening App through a Website Link Click

Embarking on my app development journey, I recently dived into creating an Android app with Cordova. However, I found myself stuck at a particular issue: In the sign-up process, users receive an email containing an activation link to click and confirm the ...

WordPress footer widgets appearing misaligned

I have made a child theme for Twenty Thirteen and am in the process of making some updates to it. My development site is essentially a replica of the live site. The only modification I made in the footer section was to change the widget title styles, but I ...

Preventing Double Click Events on jQuery Spinner

I have been working on an option picker, but now there is a new requirement to make the options configurable. While this shouldn't be too difficult, I am facing some issues with the option picker: Currently, when an item is double-clicked, it will ge ...

What is the process for incorporating PHP into a three-dimensional virtual world?

I recently completed a client's website using a combination of PHP and basic HTML/CSS. The site's main feature is the ability for users to upload images and view them in a digital art gallery. Essentially, I positioned the images against a backgr ...

Transferring a Variable from Arduino to JavaScript

Is there a simple way to pass an Arduino variable as a JS variable? Let's say we have an integer Arduino variable called sensorData: int sensorData = analogRead(sensorPin); How can we transfer this value to a JavaScript variable? client.println(&quo ...

Having difficulty retrieving precise HTML information for data scraping purposes

I'm a beginner in python and exploring web scraping for a project on . Currently, I'm using selenium to automate the search for a CUSIP and then extract specific details about it. Although I've successfully automated navigation from EMMA&a ...

What is the best way to display two items from a list while hiding the rest?

I received a list generated from the backend that looks like this: <ul> {% for item in items %} <li>{{item }}</li> {% endfor %} </ul> My goal is to display only the first two items and collapse the rest, possibly with a 's ...

Tips for identifying if the cursor is hovering over the :before or :after section of an element

One of the challenges I am facing involves CSS and defining drop areas for users to interact with, allowing them to either drop a section before or after existing sections. .section:before, .section:after { content: "[insert here]"; height: 64px; ...

What are the steps for rearranging a table column?

I am trying to show a text file in a table and allocate some code to each entry. I can display the text file. I can assign the code for each record (though this part is still under development). However, I have encountered an issue. The columns of the t ...

Menu with full-width navigation and dropdown options

I am trying to create a navigation menu with a black background that spans the full width of the window. To achieve this, I have placed the ul element inside a div with overflow: hidden; set. However, I am facing issues where hovering over submenus causes ...

Tips for preventing the use of website URLs as variables in jQuery ajax() calls:

Having some trouble. For example: $(document).ready(function () { $("#btnSend").click(function () { var noti_p = { url: "Pusher_Controller.ashx", data: "&appname=" + $("#selt1").val() + "&title=" + $("#title"). ...

Tips for sending the output of a Python function to the webpage associated with the clicked action button in Python's Bottle framework

Here is a method I have: @post('/home', method='post') def myFunction(): if(len(request.forms.get('Matrix_dimension').strip()) != 0): length = int(request.forms.get('Matrix_dimension').strip()) tableRow = ...