What is the most effective way to compress a paragraph and fill in the remainder with '...'?

Here is some content wrapped in a paragraph, see below:

<div style="width:30px">
  <p>12345678901234567890abcdefghijklmnopqrstuvwxyzIlovePaulinaVega</p>
</div>

We are aware that this content will be displayed on multiple lines due to the width of its parent element. However, I am specifically interested in showing only the first two rows and replacing the rest with '...'. Can anyone guide me on how to achieve this? Please advise.

Answer №1

p {
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}
<div style="width:100px">
  <p>12345678901234567890abcdefghijklmnopqrstuvwxyzIlovePaulinaVega</p>
</div>

Follow this CSS styling:

p{
  text-overflow:ellipsis; 
  white-space:nowrap;
  overflow:hidden;
 }

Answer №2

Give this a shot

Check it out on JsFiddle:

http://jsfiddle.net/2zggrdur/1/

CSS Tricks:

p {
    line-height: 1.5em;
    height: 3em;
    text-overflow:ellipsis; 
    overflow: hidden;
}
  1. Set the height property to determine the number of visible lines or rows in your paragraph.
  2. Using text-overflow: ellipsis along with overflow: hidden will hide excess content and show 3 dots.
  3. Make sure the parent width aligns with the paragraph width.

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

Loading JSON data into HTML elements using jQuery

I am currently grappling with coding a section where I integrate data from a JSON file into my HTML using jQuery. As a newbie to jQuery, I find myself at a standstill. https://jsfiddle.net/to53xxbd/ Here is the snippet of HTML: <ul id="list"> ...

What is the best solution for correcting the error 'Unexpected token < in JSON at position 0'?

I'm facing difficulties in loading JSON files while trying to share a website I designed using GitHub pages. The website is for a game server belonging to a friend, and it utilizes HTML 5, JavaScript, and JSON. While running the website from localhost ...

Service update causing $scope in Ionic Angular Cordova to remain stagnant

As a newcomer to Angular, I've been working on a project to create an app that can answer questions, select images, and send data to the server. I'm facing some challenges with updating the scope properly when a user selects an image. It seems l ...

Attempting to include a new choice on a drop-down menu and ensure its visibility within the drop-down menu

On my journey into the world of web development, I am facing a challenge with adding an option to a dropdown list. Despite pressing the add button to insert "Pasta" as a new option, it is not showing up in the list immediately. However, selecting all optio ...

Having trouble accessing JSON response properties within an Angular.js controller

My Angular.js controller is called 'forecastController'. This is the code for the Angular.js Controller: weatherApp.controller('forecastController', ['$scope','$routeParams','cityService', 'weat ...

Updating the positions of Mesh objects in Three.js asynchronously

I'm currently working on a Three.js application where I am creating a grid to display various objects. These objects are rendered on the grid based on their positions, which are obtained from data fetched from a REST API that I poll every 300 millisec ...

Usage of `ng-disabled` on anchor tag within `li` element

Is there a way to deactivate a specific drop-down menu item that utilizes ui-router and is structured like this? <ul class="dropdown-menu"> <li><a ui-sref="state.random">A random state</a></li> </ul> Attempting th ...

Changing the input value in Nuxt / Vue 2 after it has been overridden

I'm working on a feature where the user's typed keys are converted to the last single upper-cased character (for example, 'a' becomes 'A', 'abc' becomes 'C'). Here is my current code snippet: <template& ...

Tips for ignoring preflight response in AngularJS

When I send a http.post request to my service, I start by sending an Option request as required by Cors. However, I've noticed that the OPTIONS (pre-flight) request does not return any response.data, whereas the POST request does. This creates an iss ...

Play framework fails to apply style attributes correctly

When working with play-framework 2.3.x, I am in the process of creating a form and would like to show/hide it based on a model attribute. Typically, setting the style attribute manually using style = "display: none" and style = "display: block" works fine. ...

Sending Files via PHP Email Attachment

I've been working on creating a customized contact form that allows users to attach a photo using PHP mail. The goal is to send the photo to the specified recipient indicated in the PHP mail code. <input type="file" id="file" name="file"> Belo ...

Assorted Three.js particles

As a beginner in the world of three.js, I'm currently tackling the challenge of incorporating 1000 particles, each unique in size and color. The current roadblock I'm facing is that all particles end up the same color and size when using a Partic ...

axios interceptor - delay the request until the cookie API call is completed, and proceed only after that

Struggling to make axios wait for an additional call in the interceptor to finish. Using NuxtJS as a frontend SPA with Laravel 8 API. After trying various approaches for about 4 days, none seem to be effective. TARGET Require axios REQUEST interceptor t ...

Limit the usage of map() to solely operate on a collection of headers stored within an array generated from a specified range

I need to limit the map functionality to only include columns within the specified range that are also present in the headers list, which is a subset of the values in v[0]. This ensures that only values from columns listed in the headers array will be mo ...

Troubleshooting the EACCESS error in Node.js on OpenShift

I'm having trouble getting the application to start properly, as I keep receiving an EACCESS error: Error: listen EACCES Below is the code snippet causing the issue: var server_port = process.env.OPENSHIFT_NODEJS_PORT || 8080 var server_ip_address ...

Combining various MySQL query results into a single array key element in PHP

I currently have a MySQL database that houses various 'heating profiles', each profile has its own table and there is a separate table to manage the names of these profiles. To ensure my jQuery Mobile / Cordova HTML 5 page dynamically loads base ...

How do I set up a navigation bar item to align to either side based on the selected language?

I need to adjust the positioning of the last list item component within a specific div. The webpage is available in both Arabic and English, with the direction changing based on the selected language. Here is a snippet of CSS code that I'm using: #na ...

Clicking the button in jQuery results in no action

Currently, I am delving into the world of jQuery and have encountered a roadblock with a particular issue. Below is the code snippet in question: $(function(){ var gotProducts=new Array(); var productsWithDelete=new Array(); $('.addProducts ...

What techniques can be applied to utilize JSON data in order to dynamically create menu components using the map method?

My current challenge involves dynamically generating a set of menu items using data retrieved from a JSON file. I've attempted to achieve this by mapping the values with props, but it seems like I'm overlooking something. Below is the code snipp ...

Issues with JavaScript Prototype in MongoDB Cursor OperationsThe problem of the prototype

I have been working on merging two projects: Real-time apps using MongoDB and https://github.com/meanjs/mean Progress has been smooth so far, but I recently encountered an issue that is puzzling me. The error message I am facing is "cursor has no metho ...