Home >Web Front-end >CSS Tutorial >How to Hide Text Overflow with a Custom Indicator in CSS?
Hiding Text Overflow with an Indicator
To condense text that exceeds two lines and indicate the hidden content, a custom solution can be implemented until the future implementation of the line-clamp property.
Custom Solution
CSS
.main-text { line-height: 1.2em; max-height: calc(2 * 1.2em); overflow: hidden; display: inline-block; position: relative; } .main-text:after { content: "123 T."; display:inline-block; width:40px; position:relative; z-index:999; box-shadow: 40px 0 0 #fff, 80px 0 0 #fff, 120px 0 0 #fff, 160px 0 0 #fff; color: #8e8f8f; font-size: 10px; background: #fff; margin-left:2px; } .main-text span { position: absolute; top: 1.2em; right: 0; padding: 0 3px; background: #fff; } .main-text span:before { content: "..."; } .main-text span:after { content: "123 T."; color: #8e8f8f; font-size: 10px; }
HTML
<div class="main-text"> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam metus mi, dapibus sit amet posuere eu, porttitor condimentum nulla. Donec convallis lorem justo, eget malesuada lorem tempor vitae. Aliquam sollicitudin lacus ipsum, at tincidunt ante condimentum vitae. <span></span> </div>
This solution hides overflow text and shows the specified indicator after two lines.
The above is the detailed content of How to Hide Text Overflow with a Custom Indicator in CSS?. For more information, please follow other related articles on the PHP Chinese website!