CSS Multiline Text With Ellipsis

CSS Multiline Text With Ellipsis
Code Snippet:CSS multiline text with ellipsis
Author: an-ska
Published: January 10, 2024
Last Updated: January 22, 2024
Downloads: 376
License: MIT
Edit Code online: View on CodePen
Read More

This code creates a stylish CSS Multiline Text With an Ellipsis effect. The core functionality lies in the “text” class within the “box” div. It truncates lengthy text and adds an ellipsis (…) to maintain a clean design. Helpful for displaying long paragraphs in a limited space.

You can integrate this code into your project to generate blog post summaries or product short descriptions with an ellipsis effect. Moreover, you can customize the text with additional CSS according to your needs.

How to Create CSS Multiline Text With Ellipsis

1. Start with the HTML structure. Define a container <div> with a class of “box” and a <p> element inside it with a class of “text” that holds your text content.

<div class="box">
	<p class="text">Biscuit fruitcake halvah fruitcake fruitcake. Icing cake gingerbread cake. Bear claw sugar plum liquorice candy canes cake. Gingerbread gummi bears tart toffee. Jelly bear claw fruitcake danish macaroon icing donut. Brownie ice cream cookie carrot cake sweet. Cookie jelly-o cookie gummi bears bonbon sweet jelly beans. Dessert cake caramels icing cookie. Biscuit fruitcake halvah fruitcake fruitcake. Icing cake gingerbread cake. Bear claw sugar plum liquorice candy canes cake. Gingerbread gummi bears tart toffee. Jelly bear claw fruitcake danish macaroon icing donut. Brownie ice cream cookie carrot cake sweet. Cookie jelly-o cookie gummi bears bonbon sweet jelly beans. Dessert cake caramels icing cookie. Bear claw sugar plum liquorice candy canes cake. Gingerbread gummi bears tart toffee. Jelly bear claw fruitcake danish macaroon icing donut. Brownie ice cream cookie carrot cake sweet. Cookie jelly-o cookie gummi bears bonbon sweet jelly beans. Dessert cake caramels icing cookie</p>
</div>
<p class="text-info">Tested on Chrome, Firefox Safari, Opera, IE11 & IE10<p>

2. Apply the necessary CSS styles to achieve the multiline text with ellipsis effect. Add the following CSS styles to your existing stylesheet or create a new CSS file and link it to your HTML document using <link> tag. Modify the width of the “.box” class to fit your layout.

* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

.box {
  width: 500px;
  margin: 60px auto;
  border: 5px solid #273043;
  padding: 15px;
  border-radius: 5px;
  background-color: #FFF;
}

.text {
  color: #830A48;
  display: block;
  display: -webkit-box;
  font-size: 16px;
  line-height: 1.5;
  -webkit-line-clamp: 8;
  min-height: 192px;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

.text-info {
  color: #FFF;
  text-align: center;
}

Customize the font size, color, line height, and other text properties in the “.text” class to match your design.

That’s all! hopefully, you have successfully created multiline text with ellipsis on your website. If you have any questions or suggestions, feel free to comment below.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About CodeHim

Free Web Design Code & Scripts - CodeHim is one of the BEST developer websites that provide web designers and developers with a simple way to preview and download a variety of free code & scripts. All codes published on CodeHim are open source, distributed under OSD-compliant license which grants all the rights to use, study, change and share the software in modified and unmodified form. Before publishing, we test and review each code snippet to avoid errors, but we cannot warrant the full correctness of all content. All trademarks, trade names, logos, and icons are the property of their respective owners... find out more...

Please Rel0ad/PressF5 this page if you can't click the download/preview link

X