What is the CSS technique for displaying text overflow after displaying only two lines within a div?

Currently working on a webpage design where I am looking to display text overflow using ellipsis within a div. However, my requirement is to display two lines of data in the div before handling the text overflow. I prefer not setting a fixed height for the div. Any suggestions on how to achieve this using CSS?

Answer №1

Thankfully, CSS3 introduced a new text-overflow property that allows text truncation with the option to reveal more on hover (although a click function might be preferred).

element {
    text-overflow: ellipsis; // the exact feature you were looking for
}

Here are some examples and documentation.

text-overflow is not currently included in the latest version of the CSS3 specification. Disappointing, but there are workarounds.

I suggest using javascript or jQuery for alternative solutions.

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

instructions on how to showcase a text message within the fontawesome square icon

Can someone help me with styling my code? I want to display a text message inside a square box with dimensions of 1x. <span class="fa-stack fa-5x" style="margin-left:5%"> <i class="fa fa-square-o fa-stack-2x"></i> </span> ...

What's the reason this doesn't vanish when I hover over it?

Check out this JsFiddle link HTML Code <p>I am a duck</p> CSS Code p:hover { display:none; } Why is the text not disappearing when hovered over? ...

Encountering an unexpected end of input error while making an API call using the fetch()

I'm looking to transition an API call from PHP to Javascript for learning purposes. Unfortunately, I can't make any changes on the API side as it's an external source. When attempting to use fetch() due to cross-origin restrictions, my scrip ...

Using PHP and AJAX for deletion will only work on the initial row

I created a basic PHP blog platform. On the Add Post page, users can input a title and body text for their posts. These posts are displayed on the Posts page, where users also have the option to delete them. However, I encountered an issue where only the ...

Issue with Jquery slideToggle not remaining in the down position

I'm currently working on implementing a sub-navigation menu that slides down when links in a separate div are clicked. Although I've managed to hide the sub-nav properly, I'm facing an issue where it briefly appears and then hides again afte ...

"Troublesome issue with Bootstrap push and pull functionality not functioning correctly

I am currently experiencing issues with Bootstrap push and pull functionality. While the mobile view appears to be working correctly, the web view is shifted to the left. Any assistance on this matter would be greatly appreciated. Below is the code that i ...

Repeated actions using jQuery

Being new to jQuery, I am currently exploring ways to repeat functions without the need to continuously write them over and over again. In the code snippet below, you can see that when a button is clicked, it changes to 'I was clicked' in an h1 t ...

Navigate within an HTML element by utilizing the element's unique ID

I need to create a condition based on the presence of style="display:none;" in the following code snippet. <div class="wrap hide" id="post_query" style="display:none;"> </div> My goal is to identify whether style="display:none;" is included o ...

Try triggering transitions on all elements by hovering over any CSS element

I am currently in the process of developing a website, and for the header section, I have decided to use a table format where each column represents a different section. The top row will feature a picture link, while the bottom row will display the name of ...

Elements that possess identical class attributes yet exhibit dynamic behavior

I'm currently facing challenges with dynamically generated elements. I am working on a page for my website that will show a list of users (data provided by the controller). Each user is represented within a div, containing two h3 tags displaying the u ...

Choosing multiple classes using Xpath

<div class="unique"> <a class="nested" href="Another..."><img src="http://..."/></a> <p> different.... </p> <p><img src="http://....." /></p> </div> I have this interesting HTML struc ...

Leveraging Javascript to generate universal HTML content for various Javascript files

Present Situation: I have a timesheet feature that enables users to input their leave, TOIL, and sick days along with the respective hours. Additionally, there is a table that dynamically adds a new row every time the plus button is clicked using the foll ...

In order to activate the button, make sure all 3 boxes are checked

Can someone provide some guidance on the script below? I'm utilizing it for a pop-up when a user attempts to add a product to the cart. Presently, the button will activate if at least one checkbox is selected (although it's not working on fiddle ...

What is the process for incorporating a custom button for selecting the date and closing the calendar in bootstrap-datepicker?

I successfully coded a simple project, but I'm struggling to figure out how to add a custom button to the bootstrap-datepicker. <!DOCTYPE html> <html> <head> <title>JS</title> <link rel="stylesheet" href="http ...

Troubleshooting Issues with CSS3PIE and border-radius

Trying to implement CSS3PIE for my website to enable border-radius in IE8 (and older versions). The code works perfectly on all other browsers except IE. Below is the CSS I am using: #body_text_design{ border:2px solid black; background-color:#CCC ...

XMLHttpRequest encounters issues with 'Access-Control-Allow-Origin'

I have developed a JavaScript file that tracks and saves the coordinates of mouse clicks on a web page using an AJAX call. In one website (domain2), I have included the following code in the head section: <script src="http://www.domain1.com/scan/track/ ...

What are the steps to design a curved gauge with a linear-gradient background?

Looking to create a fully responsive gauge using only CSS, ranging from 0-100% with a gradient color transition from green to red. After encountering issues with existing examples, I conducted tests and ultimately developed a solution that somewhat meets t ...

What is causing the container to overlap with my sidebar-like <nav>?

Why is the fluid-container overlapping in this way, while others are not? Does this look correct to you, or am I overlooking something? It seems incorrect to me. <nav class="nav flex-column float-left"> {links} </nav> <div class="conta ...

Conceal a div containing certain content using jQuery

Can you use jquery to hide a div with the class "one" if it contains the following content? <div class="one"> <div style="padding:20px;"> <div class="title"></div> <div class="content"></div> < ...

Transform input string containing newline characters into separate paragraphs

I utilize Contentful CMS for content management and fetch the content through their API. When the content is fetched, it comes in as a JSON object. One of the keys within this object pertains to the main text block for the entry I am retrieving. This stri ...