CSS Text ellipsis displays only the beginning of each paragraph

I want to add ellipsis to a text, but it keeps including the first line of all paragraphs. What I actually need is for only the first line of the content to have the ellipsis applied.

Here is an example of the content:

When using websocket to send messages, this code snippet is executed. However, '+ msg +' does not recognize new lines (line breaks) in the message. Each sentence appears on the same line.

Can you help optimize this jQuery code so that '+ msg +' can identify new lines?

This is what I am currently seeing:

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

This is what I really want:

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

Below is my CSS styling:

.content .message {
  font-size: 0.8rem;
  color: #afb9d7;
  text-overflow: ellipsis;
  overflow: hidden; 
  white-space: nowrap; 
}

And here is the corresponding HTML:

<div class="content">
  <div class="name">Shreyansh Jha</div>
  <div class="message" data-msg="When sending messages via websocket, this code is triggered. However, '+ msg +' does not detect new lines (line breaks) in the message. Every sentence ends up on the same line.<br />
    <br />
    To fix this issue with detecting new lines, optimize this jQuery code so that '+ msg +' can identify them properly.">When sending messages via websocket, this code is triggered. However, '+ msg +' does not detect new lines (line breaks) in the message. Every sentence ends up on the same line.<br>
    <br>
    To fix this issue with detecting new lines, optimize this jQuery code so that '+ msg +' can identify them properly.
  </div>
</div>

How can I achieve the desired output in this scenario?

Answer №1

The text ellipsis feature is designed to only apply to the width of a single lengthy paragraph.

Thus, in this scenario, you must eliminate the <br /> tag and substitute it with \n, if feasible. Otherwise, it will be interpreted as a distinct segment within that division/paragraph.

Alternatively, you could set a fixed height for the paragraph and handle it using CSS techniques.

Answer №2

Give This a Shot :

.notification  {
  display: inline-block; 
  width: 250px; 
  overflow: hidden;
  text-overflow: ellipsis; 
  border: 1px solid #333333;
}
<div class="notification">
  When using this notification system, make sure that the '+ message +' variable can properly handle line breaks and new lines in the content.
  Modify the existing JavaScript code to ensure that '+ message +' recognizes new lines within the message text.
</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

Toggle visibility of div content when hovering over a link by leveraging the data attribute, with the div initially visible

I have a collection of links: <p><a href="#" class="floorplan initial" data-id="king"><strong>King</strong></a><br> 4 Bedrooms x 2.5 Bathrooms</p> <p><a href="#" class="floorplan" data-id="wood">< ...

Clicking the React Todo Delete Button instantly clears out all tasks on the list

I am dealing with 2 files: App.js import React, { Component } from 'react'; import './App.css'; import ToDo from './components/ToDo.js'; class App extends Component { constru ...

What is the best way to incorporate a <li> view cap within a div element using JavaScript?

Currently, I am attempting to implement a dynamic <li> view limit within the content of a div. My goal is to display only 3 <li> elements each time the div content is scrolled. Although not confirmed, I believe this example may be helpful: ...

Discover the position within a two-dimensional array

Suppose I have an array that contains objects, and each object has its own id property. In this case, I can find the index by writing: data.findIndex(x=>x.id === newData.id); Now, if data is an array of arrays of objects, how can I efficiently get two ...

What is the process for including a selected-by option in a VIS network graph?

I'm trying to outline the neighboring nodes of the node that has been selected (highlightNearest). https://i.sstatic.net/lynhu.png Unfortunately, I haven't had success achieving this using JavaScript. Link to StackBlitz ...

Unsure if values can be imported from one component to another in Vue.js using props

Currently experimenting with Vue and ran into a minor challenge - wondering if there's a solution to this. I am looking to add a new value to my items array using my Button component so that I can display it using v-for. While consolidating everything ...

Ways to prompt for user input using JavaScript

How can I collect user input using JavaScript for a website that saves the input into a text file? Below is the code I am currently using: <button type="button" onclick="storeEmail()">Enter Email</button> <script> ...

How to generate PDF downloads with PHP using FPDF

I am attempting to create a PDF using FPDF in PHP. Here is my AJAX call: form = $('#caw_auto_form'); validator = form.validate(); data = form.serializeObject(); valid = validator.form(); //alert("here"); ajax('pos/pos_api.php',data,fun ...

Tips for inserting a row component into a table using Angular 7

I am currently using the latest version of Angular (7.2.0). I have created a custom tr component as follows: import { Component, OnInit, Input } from '@angular/core'; @Component({ selector: 'app-table-row', templateUrl: './table- ...

Is there a way to handle specific email format designs with PHP?

When trying to send an email with specific shipping information and tracking numbers, the formatting appears strange. Here is the desired format: Dear xyz , Per your request, this email is to no ...

Processing of DataTables json is not performed within the Laravel framework

After making a request for json data, Datatables seems to be doing nothing with it I have implemented Yajra's Datatables to populate my table and followed all the necessary steps. The controller is correctly set up, the routes are functioning (when I ...

"Mastering the Geocoder Class: Unleashing the Power of AJAX for Latitude and Longitude Retrie

This JSON array includes a collection of addresses [ { "id": 0, "title": "Coop.Sociale Prassi e Ricerca Onlus", "latitude": 0, "longitude": 0, "address": "Viale Eleonora D'Arborea 12, Roma, IT" }, { "id": 0, "title": "San Lorenzo", "lati ...

Pair of elements connecting in Vuejs

What is the best way to efficiently organize data and communication between two Vue.js components? Here's an example scenario: 1) I have a component item(v-for="item in items) a {{item.name}} 2) And then the second component card(v-for="item in it ...

The custom validator in Parsley.js's isValid() function will return null

Currently, I am utilizing a custom validator in parsley.js(2.8.1) to verify if an input code already exists on the server. While everything seems to be working well, I have encountered an issue where parsley().isValid() and parsley().validate() are both re ...

Looking to install nodemon for Node.js on macOS? If you're encountering a "command not found" error, here's

After installing nodemon using the command npm install -g nodemon, I encountered a Permissions issue. To resolve this, I used the sudo npm install -g nodemon command. However, when attempting to run the "nodeman" command, I kept receiving an error that s ...

Javascript keycode used to target the element when a key is pressed

In my current project, I am utilizing a code snippet to attach a KeyDown event handler to any element within the HTML form. for(var i=0;i<ele.length;i++) { ele[i].onkeydown = function() { alert('onkeydown'); } } I am ...

An issue has arisen when trying to fetch and parse data using React and JavaScript

I am currently facing some challenges with fetching data from an API and displaying it using React. I have encountered errors and I am struggling with parsing the JSON response from the API. I believe that converting the response into an array may help res ...

Update google maps markers and infoBubbles dynamically with ajax

I am currently using asp mvc in conjunction with jquery and the google maps api to showcase and update various locations on a map. Main Objective: Utilize markers to mark multiple locations Display brief information about these locations using info ...

Issue with "Access-Control-Allow-Origin" header missing in express and react application

I've decided to work on a Node/Express project to improve my JavaScript skills, but I'm facing an issue with 'Access-Control-Allow-Origin'. For some reason, I can't do a get request from the front end and despite looking at other p ...

The contentType property is functioning correctly for application/xml but is experiencing issues with application/json

Hello, I am reaching out here for the first time with a question. Despite searching on various platforms like Stack Overflow, I have not been able to find a definitive answer regarding what is needed for FullCalendar to properly accept a jQuery data proper ...