如何使用省略號和自訂計數器('...123 T.”)隱藏第二行之後的文字溢位?
使用省略號和計數器隱藏第二行後的文本溢出
問題:
隱藏部分超過兩行的文字並添加“...123 T”。因為隱藏的溢出指示器需要一個聰明的解決方案。
解:
雖然未來的更新將提供使用 line-clamp屬性的更簡單的方法,但這裡有一個創造性的技巧達到這個目的效果:
CSS:
.container { max-width: 200px; margin: 5px; } .main-text { line-height: 1.2em; /* line height */ max-height: calc(2 * 1.2em); /* limit height to 2 lines */ overflow: hidden; display: inline-block; position: relative; } .main-text:after { content: "123 T."; display: inline-block; width: 40px; position: relative; z-index: 999; /* big box shadow to hide the ellipsis */ 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; /* cover text beneath */ margin-left: 2px; } .main-text span { position: absolute; /* bottom right position */ top: 1.2em; /* 1 line height */ right: 0; padding: 0 3px; background: #fff; /* cover text beneath */ } .main-text span:before { content: "..."; /* ellipsis */ } .main-text span:after { content: "123 T."; color: #8e8f8f; font-size: 10px; }
登入後複製
HTML:
<div class="container"> <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> </div> <div class="container"> <div class="main-text"> Lorem ipsum <span></span> </div> </div> <div class="container"> <div class="main-text"> Lo <span></span> </div> </div> <div class="container"> <div class="main-text"> Lorem ipsum dolor sit ameta, adipiscing elit. Nam metus <span></span> </div> </div> <div class="container"> <div class="main-text"> Lorem ipsum dolor sit ameta, adipiscing elit <span></span> </div> </div>
登入後複製
HTML:
此技術確保「.. .123T。以上是如何使用省略號和自訂計數器('...123 T.”)隱藏第二行之後的文字溢位?的詳細內容。更多資訊請關注PHP中文網其他相關文章!
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章
如何修復KB5055612無法在Windows 10中安裝?
4 週前
By DDD
<🎜>:種植花園 - 完整的突變指南
3 週前
By DDD
<🎜>:泡泡膠模擬器無窮大 - 如何獲取和使用皇家鑰匙
3 週前
By 尊渡假赌尊渡假赌尊渡假赌
北端:融合系統,解釋
4 週前
By 尊渡假赌尊渡假赌尊渡假赌
Mandragora:巫婆樹的耳語 - 如何解鎖抓鉤
3 週前
By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

在本週的平台新聞綜述中,Chrome引入了一個用於加載的新屬性,Web開發人員的可訪問性規範以及BBC Move

有很多分析平台可幫助您跟踪網站上的訪問者和使用數據。也許最著名的是Google Analytics(廣泛使用)
