Expanding the size of a div using the Bootstrap grid system

I need to customize the width of the date column on my inbox page so that it displays inline without breaking the word.

Even when I use white-space: nowrap, the overflow hides it due to the fixed width.

I want the name and date classes to be displayed inline with equal widths like this example:

Username (date at end) 2 years 5 hours 30 min, 25 sec ago

https://i.sstatic.net/cz1wq.png

Below is the code snippet :

$(".message-wrapper").click(function() {
  $(this).toggleClass("swipe-left");
});
.messages-container {
        overflow-x: hidden;
        background: var(--bs-white);
        cursor: pointer;
      }

      .message-wrapper {
        all: unset;
        display: grid;
        grid-template-columns: 60px auto 10ch;
        transition: transform 0.3s;
        position: relative;      
      }
      /* More CSS styles */
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons+Round">
<link href="https://cdn.jsdelivr.net/npm/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
<div class="messages-container mx-3">
  <a class="message-wrapper border-bottom p-3">
    <div class="thumbnail me-3">
      N 
    </div>
    <div class="name h5 m-0">
      No One 
    </div>
    <div class="ago-time small">
      30 min, 25 sec ago
    </div>
    <!-- More HTML content -->
  </a>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

Answer №1

In order to achieve the desired behavior for accommodating a long date, it is necessary to modify the HTML structure as shown below.

<div class="d-flex align-items-center justify-content-between">
    <div class="name h5 m-0">
      No One
    </div>
    <div class="ago-time small">
      2 years 5 hours 30 min, 25 sec ago
    </div>
</div>

The title and date should be wrapped in a flex container with justify-properties between them. You can view an example on jsfiddle.

$(".message-wrapper").click(function() {
  $(this).toggleClass("swipe-left");
});
.messages-container {
        overflow-x: hidden;
        background: var(--bs-white);
        cursor: pointer;
      }

      .message-wrapper {
        all: unset;
        display: grid;
        grid-template-columns: 60px auto 10ch;
        transition: transform 0.3s;
        position: relative;
      }
      .message-wrapper .delete-btn {
        position: absolute;
        top: 0;
        bottom: 0;
        right: -80px;
        width: 80px;
        background: var(--bs-danger);
        display: flex;
        justify-content: center;
        align-items: center;
        color: white;
      }
      .message-wrapper .thumbnail {
        align-self: center;
        grid-row: 1/3;
        aspect-ratio: 1;
        border-radius: 50%;
        background: var(--bs-info);
        color: var(--bs-light);
        display: flex;
        align-items: center;
        justify-content: center;
      }
      .message-wrapper .name, .message-wrapper .message-text {
        overflow: hidden;
        word-break: break-word;
      }
      .message-wrapper .name {
        align-self: center;
        color: var(--bs-dark);
      }
      .message-wrapper .ago-time {
        justify-self: start;
        color: var(--bs-secondary);
      }
      .message-wrapper .message-text {
        grid-column: 2/4;
        color: var(--bs-secondary);
      }
      .message-wrapper.swipe-left {
        transform: translateX(-80px);
      }
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons+Round">
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="30525f5f44434442514070051e011e03">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet">
<div class="messages-container mx-3">
  <a class="message-wrapper border-bottom px-2">
    <div class="thumbnail me-3">
      N
    </div>
    <div class="d-flex align-items-center justify-content-between">
    
    
    <div class="name h5 m-0">
      No One
    </div>
    <div class="ago-time small">
      2 years 5 hours 30 min, 25 sec ago
    </div>
    </div>
    <div class="message-text">
      Es ist ein lang erwiesener Fakt, dass ein Leser vom Text abgelenkt wird, wenn er sich ein Layout ansieht.</div>
    <div class="delete-btn">
      <span class="material-icons-round">delete</span>
    </div>
  </a>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

Answer №2

Implemented inline-block as display for name and date containers, with specific no-wrap on the date.

$(".message-wrapper").click(function() {
  $(this).toggleClass("swipe-left");
});
.messages-container {
        overflow-x: hidden;
        background: var(--bs-white);
        cursor: pointer;
      }

      .message-wrapper {
        all: unset;
        display: grid;
        grid-template-columns: 60px auto 10ch;
        transition: transform 0.3s;
        position: relative;
      }
      .message-wrapper .delete-btn {
        position: absolute;
        top: 0;
        bottom: 0;
        right: -80px;
        width: 80px;
        background: var(--bs-danger);
        display: flex;
        justify-content: center;
        align-items: center;
        color: white;
      }
      .message-wrapper .thumbnail {
        align-self: center;
        grid-row: 1/3;
        aspect-ratio: 1;
        border-radius: 50%;
        background: var(--bs-info);
        color: var(--bs-light);
        display: flex;
        align-items: center;
        justify-content: center;
      }
      .message-wrapper .name, .message-wrapper .message-text {
        overflow: hidden;
        word-break: break-word;
      }
      .message-wrapper .name {
        display: inline-block;
        align-self: center;
        color: var(--bs-dark);
      }
      .message-wrapper .ago-time {
        display: inline-block;
        white-space: nowrap;
        justify-self: start;
        color: var(--bs-secondary);
      }
      .message-wrapper .message-text {
        grid-column: 2/4;
        color: var(--bs-secondary);
      }
      .message-wrapper.swipe-left {
        transform: translateX(-80px);
      }
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons+Round">
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="60020f0f14131412011020554e514e53">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet">
<div class="messages-container mx-3">
  <a class="message-wrapper border-bottom p-3">
    <div class="thumbnail me-3">
      N 
    </div>
    <div class="name h5 m-0">
      No One 
    </div>
    <div class="ago-time small">
      30 min, 25 sec ago
    </div>
    <div class="message-text">
      Es ist ein lang erwiesener Fakt, dass ein Leser vom Text abgelenkt wird, wenn er sich ein Layout ansieht.</div>
    <div class="delete-btn">
      <span class="material-icons-round">delete</span>
    </div>
  </a>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

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

Combine two queries in JavaScript by using arrays

I have a unique challenge where I can only post once every 90 minutes, so here's my double question. First up, I need to create a function that can replace a specific character in a string with a space. //====================== EXAMPLE ============= ...

Executing Rake tasks on the live server fails because of an issue with ExecJS

I currently have a Rails 4 application running on a RHEL 6 server. The production environment utilizes Passenger and Apache2. Recently, I've been attempting to schedule Rake tasks in the production environment using the Whenever Gem and Cron. Howev ...

My JavaScript code is functioning properly in jsfiddle, but when I try to run it on my own website, I encounter

Encountered an error message stating "Uncaught typeError: cannot call method 'hover' of null" following the line $('#nav li a').hover(function(){ in my JavaScript code. Check out the code on my site here: http://pastebin.com/GjZBEu3s Y ...

Modal does not close

I am experiencing an issue with closing a modal. I have checked jQuery and everything seems to be working fine. Currently, I am using version 1.12.4 and have the following script tag in the head of my code: <script src="https://ajax.googleapis.com/aja ...

Toggle switch with active state

I'm currently using Ionic 2 alongside Angular 2 beta 11. Is there a way to turn off the toggle switch? The Ionic documentation suggests using the checked attribute, but I've tried that and also attempted ng-checked with no luck. Any advice on t ...

Embed an external webpage within your own and make full use of its content

Is there a way to embed an entire new URL or page within my website element so that users can interact with it without having to refresh the main page? It's okay if the new content initially loads with a page refresh. Would jQuery.load() work? Or pe ...

Blend multiple images using Angular

Is there a way to combine multiple images in Angular? I came across some HTML5 code that seemed like it could do the trick, but unfortunately, I couldn't make it work. <canvas id="canvas"></canvas> <script type="text/javascript"> ...

Tips for acquiring the initial fully visible item within a scrollable element with horizontal alignment through jQuery

I'm trying to use jQuery to find the first visible element inside a scrollable DIV, but I can't quite get it to work correctly. Can someone please help me identify what's causing the issue? $('div').on('scroll', functio ...

Not all comparisons between two tables are guaranteed to be successful

Looking to compare records within two arrays and apply a style if they are equal. Here is my approach: var json = ["VIP Section","Master Section","Press Section","God Section"]; var sections = ["VIP Section","Master Section"]; if ( sections.length &g ...

What is the best way to align content in the left center of a Paper component and ensure it stays that way on smaller devices?

Recently, I've been developing a component for my Goal Sharing social media platform. Here's what I have accomplished so far: https://i.stack.imgur.com/UDRim.png In an attempt to position the Avatar component along with two typography component ...

Click the button to save the text to your clipboard with a customized

Can anyone suggest a method for duplicating div text using JavaScript while preserving the style attributes (italics, font family, size, etc.)? My goal is to paste the copied text into Word and have it maintain the same appearance as on the webpage. For e ...

Transferring a CSV file to the server from a React application using multi-part form

In order to post a CSV file to an API using React, I have attempted to do so in multipart form. While many tutorials and websites suggest using the fetch() method for sending files to a server, I am encountering some challenges. The issue lies with my RES ...

Adjust: Return scale to default

By applying transform: rotate(-2deg); to a section, I have created an effect where the section rotates slightly. Additionally, when the user hovers over the same section, it increases in size due to transform: scale(1.1);. However, on one specific page of ...

Exploring the wonders of Onsen UI's ng-repeat feature combined

Facing a major issue with my app, and I suspect it's due to the asynchronous call. The HTML section looks like this: <ons-list ng-repeat="item in newsEventi.items"> <ons-list-header class="news_titolo_lista">{{item.categoria}}</ons ...

Issue with PHP and CSS: Navigation bar does not properly indicate the current active tab

When attempting to display a webpage with a tabbed style navbar that changes upon clicking, I am encountering an issue. The desired result is shown in this image: https://i.sstatic.net/xR9zw.png However, after clicking on the links multiple times, the ou ...

Tips for repositioning the window when linking to a different section of a website

As a beginner in HTML and CSS, I am currently working on adding a navigation bar to my one-page website. I want the navigation bar to smoothly guide users to different sections of the page when they click on a link. To achieve this, I am using anchors and ...

Callbacks for AJAX responses that are asynchronous

After using AJAX in a limited and straightforward manner for some time, I find myself currently debugging a web application that heavily relies on JavaScript and JQuery for client-side coding. One issue that has caught my attention is the possibility of mu ...

Image placed as background for registration form

In my Vue project, I am trying to create a login form with an image as the background. However, I am facing an issue where the image is not displaying on the page. Can someone guide me on how to add a picture behind the form? HTML: Below is the HTML code ...

Obtaining Navigation Parameters within Custom React Navigation Title

In the React Navigation StackNavigator, I created a custom title that looks like this: const CustomStackNavigator = StackNavigator({ Home: { screen: HomeScreen } }, { navigationOptions: { headerTitle: <GradientHeader title={this.props.nav ...

What is preventing me from utilizing middleware in my express route?

I have a project in progress where I am developing an API. As part of this process, I need to implement a user system and ensure secure access to the API. Below is the middleware function used for validation: 'use strict' const jwt = require(& ...