CSS3 超出文本用省略号显示text-overflow:ellipsis

it2025-02-15  5

单行隐藏 多行隐藏

<!DOCTYPE html> <html> <head> <style> div.test { white-space:nowrap; width:12em; overflow:hidden; border:1px solid #000000; } </style> </head> <body> <p>这个 div 使用 "text-overflow:ellipsis" :</p> <div class="test" style="text-overflow:ellipsis;">This is some long text that will not fit in the box</div> <p>这个 div 使用 "text-overflow:clip":</p> <div class="test" style="text-overflow:clip;">This is some long text that will not fit in the box</div> </body> </html>

效果图

小技巧如何用hover显示隐藏文本


<!DOCTYPE html> <html> <head> <style> div.test { white-space:nowrap; width:12em; overflow:hidden; border:1px solid #000000; } div.test:hover { text-overflow:inherit; overflow:visible; } </style> </head> <body> <p>这个 div 使用 "text-overflow:ellipsis" :</p> <div class="test" style="text-overflow:ellipsis;">This is some long text that will not fit in the box</div> <p>这个 div 使用 "text-overflow:clip":</p> <div class="test" style="text-overflow:clip;">This is some long text that will not fit in the box</div> </body> </html>

效果图

最新回复(0)