如何利用CSS3截取字串

來源:互聯網
上載者:User
截取字串一般是用js或者後台語言來實現,其實使用CSS也是可以實現此效果的。下面通過一段執行個體代碼給大家介紹CSS3截取字串的方法,需要的朋友參考下吧

截取字串一般是用js或者後台語言來實現,其實使用CSS也是可以實現此效果的。

代碼執行個體如下:

<!DOCTYPE html><html><head><meta charset=" utf-8"><meta name="author" content="http://www.jb51.net/" /><title>CSS教程-指令碼之家</title><style type="text/css"> #first{  width:120px;  height:30px;  background-color:#F30;  overflow:hidden;  text-overflow:clip;  white-space:nowrap;}#second{  width:120px;  height:30px;  background-color:#F30;  overflow:hidden;  text-overflow:ellipsis;  white-space:nowrap;  margin-top:10px;}</style> </head><body><p id="first">指令碼之家歡迎您,只有奮鬥才會有美好的未來</p> <p id="second">指令碼之家歡迎您,只有奮鬥才會有美好的未來</p> </body></html>

特別注意的是:不能夠省略white-space:nowrap和overflow:hidden,否則截取字串無效。

以上就是本文的全部內容,希望對大家的學習有所協助,更多相關內容請關注topic.alibabacloud.com!

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.