Show ellipses when text exceeds limits, while still supporting multiple lines

I'm currently working on a component that should display three dots when the text inside the box exceeds the height of the box. I've managed to hide the excess text below the box, but I am struggling to make the three dots appear. Instead, the text is simply cut off.

Below is a snippet of my code:

 <div className={styles.box} key={index}>
            <img src={boxDataItem.boxPictureLink} alt='photo'></img>
            <button
              className={styles.boxTitleButton}
              onClick={(event) => this.handleClick(boxDataItem.boxTitleLink, event)}>{boxDataItem.boxTitle}</button>
          </div>

Css:

.placeholder {
  display: flex;
  justify-content: flex-start;

  .box {
    border-top: 8px solid red;
    border-left: 1px solid grey;
    border-bottom: 1px solid grey;
    border-right: 1px solid grey;
    padding: 10px;
    width: 150px;
    height: 115px;
    display: flex;
    justify-content: center;
    align-items: center;
    outline: none;
    margin-left: 10px;
    flex-direction: column;
  }
  
  .boxTitleButton {
    color: gray;
    background-color: white;
    font-size: 18px;
    font-weight: normal;
    font-family: 'ApexSerif-Book';
    letter-spacing: 2;
    border: 0;
    padding: 5px;
    margin: 0;
    width: 100%;
    height: 125px !important;
    max-height: 125px !important;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    word-wrap: break-word;
    white-space: pre-wrap;
  }

  .boxTitleButton:hover {
    cursor: pointer;
  }

If anyone has any suggestions on how to achieve the desired result, I would greatly appreciate it!

Answer №1

Check out this example:

HTML

<div class="example" >
     
       This is my content. This is my content. This is my content. This is my content. This is my content. This is my content. This is my content. This is my content. This is my content. This is my content. This is my content. This is my content. This is my content. This is my content. This is my content. This is my content.
          </div>

CSS

.example {
  display:block;
  white-space: nowrap; 
  width: 300px; 
  overflow: hidden;
  text-overflow: ellipsis; 
  border: 1px solid #000000;
  height:300px;
  min-height:300px;
}

Apply this to your code and see the results!

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

Prevent Copying and Pasting within the Text Editor

@if (Model.CanMaintainNcrLineManagement) { <tr> <td>@Html.TextAreaFor(model => model.Description, new { id = "txArNcrLineDescriptionValue", @style = "height:520px" })</td> </tr> } else { <tr class="read-only-editor"> &l ...

CSS Selector for table cell containing a checked input in the cell before it

Is it possible to select a table cell based on the state of a previous cell using CSS? I have a feeling that this may not be achievable with CSS alone. Can someone confirm my suspicion? Let's consider this example: <table> <tr> ...

An error arises in Typescript when the reducer state does not update upon clicking. The error message indicates that the properties 'state' and 'dispatch' are not recognized on the type 'UserContextType | null'

Having recently delved into typescript with react, I've encountered some issues. Despite trying various solutions, the state doesn't seem to work properly and I keep getting a typescript error stating: Property 'state and dispatch' does ...

Graphic selectors: a new take on radio buttons

I've been attempting to make this work, but it's not functioning correctly. Below is the CSS code: .input_hidden { position: absolute; left: -9999px; } .selected { background-color: #000000; } #carte label { display: inline-bl ...

Is it possible to iterate over a non-reactive array in a Vue template without having to store it in a data property or computed property?

Presented below is a static array data: const colors = ["Red", "Blue", "Green"]; To display these values in my markup, I can use the following method in React: import React from "react"; // Static array of colors const colors = ["Red", "Blue", "Green"] ...

Mobile devices experiencing issues with HTML select options

I have designed a webpage that displays a side menu on the left and images on the right for desktop users, while mobile users see a select option at the top instead of the side menu. The functionality of the page involves sorting the images on the right ba ...

What is the best way to insert text between the logo and menu items using bootstrap?

I've attempted several methods without much success. Here is a snippet of the code: <nav class="navbar navbar-default navbar-fixed-top"> <div class="container-fluid"> <div class="navbar-header"> <button type="button" ...

Filtering dates in a React MUI datatable using a range selector

I recently started using mui datatables and I'm curious if it's possible to implement a date range filter (from date to date) with mui-datatables. I welcome any suggestions or advice on this matter. ...

Having trouble loading a React component

I've been working on breaking down modules from a monolithic React project to store them separately in my npm registry. However, I'm encountering issues with exporting and importing them correctly. Previously, I was using the following code: con ...

Assess the equation twice using angular measurement

I am attempting to assess an expression that is originating from one component and being passed into another component. Here is the code snippet: Parent.component.ts parentData: any= { name: 'xyz', url: '/test?testid={{element["Te ...

Is there a way for me to automate sending this login request every minute?

I am looking to automate a request to my users/login API every minute. I initially tried setting up setinterval (login , 6*6000) directly in the endpoint, but encountered issues with async await functionality. When I moved it to the index.html, the login f ...

I find myself grappling with the styling issue in MUI select

<FormControl> <Select labelId="unique-label" id="unique-id" value={1} className={styles.uniqueCustomSelectRoot} IconComponent={() => <MyUniqueIcon />} sx={{ " ...

Executing a personalized function within a Server Component with the Next JS App Router while the application is running

In my server component Home, I call the function getMyAge: // app/page.tsx import { getMyAge } from './utils/datetime'; export default function Home() { return ( <Page> <Paragraph>I'm {getMyAge()} years old</Parag ...

What is the best way to prioritize .py-md-6 over .p-3 in Bootstrap 4?

I have set the padding for the class .py-md-6 as follows: .py-md-6 { padding-top: 6rem !important; padding-bottom: 6rem !important; } Despite this, there seems to be a conflict with the .p-3 class in my HAML element: #id.p-3.py-md-6 It appears th ...

Issues with react-router-dom's <Routes> and <BrowserRouter> components

Encountering an issue with <Routes> while using react-router-dom. The code in my index.tsx file is as follows: import React from 'react'; import ReactDOM from 'react-dom'; import './index.css'; import App from './Ap ...

MUI Chips serving as selectible tags with checkbox-like functionality

I have retrieved data from a JSON file containing information about different types of chips: [ { "id": "4", "name": "Caucasian" }, { "id": "5", "name": "Asian" }, ...

What is the best way to prompt Leaflet to refresh the map display?

I'm facing a challenge while integrating Leaflet with React, where Leaflet seems to want control over the DOM rendering as well based on my research. Currently, I have countries being properly colored according to specific color codes derived from ba ...

HOC that can be used with many different components

My Higher-Order Component is currently designed to accept a single component, but I want to modify it to handle multiple components dynamically. Here's the current implementation: let VerticalSlider = (Component) => { return (props) => ( ...

Additional spacing in a single column row in Outlook versions 2007 and above

I'm currently working on a fluid hybrid email design, and I've encountered an issue with a single column layout that seems to be expanding beyond the specified 600px container in Outlook 2007+. Strangely, when I test the email in Litmus, everythi ...

What are some strategies for enhancing the performance of a React application that contains numerous text input fields (implemented using Hooks) within a form?

The Issue at Hand Encountering a challenge with a React form that communicates data via a REST API. The rendering and input processing are noticeably sluggish when dealing with around 80 text fields. Currently, I am utilizing functional components with h ...