CSS 將超出顯示寬度的內容隱藏起來

來源:互聯網
上載者:User

實現原理:
(1)指定寬度:width:300px;
(2)overflow:hidden; 將超出內容隱藏
(3)text-overflow:ellipsis; IE 專有屬性,當對象內文本溢出時顯示省略標記(…)
(4)white-space:nowrap; 強制在同一行內顯示所有文本,直到文本結束或者遭遇 br 對象

 代碼如下 複製代碼


<style type="text/css">
.textOverFlow
{   
 width:300px;    
overflow:hidden;    
text-overflow:ellipsis;    
white-space:nowrap;    
border:1px solid #ddd;
}

</style>

<div class="textOverFlow"> fdsafdsafdsafdsafdsafdsafdsafdsafsafdsa www.111cn.net </div>

相關文章

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.