简体   繁体   English

如何根据div的大小隐藏文本字符

[英]How to hide text character according to size of div

I want to truncate text according to div size我想根据 div 大小截断文本

this is the code snippet:这是代码片段:

 <div style="padding-left:10px; width:200px; border:1px solid #000000"> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries </div>

this is my output:这是我的输出:

在此处输入图片说明

i want my output to be like:我希望我的输出是这样的:

在此处输入图片说明

thank you谢谢你

 div { white-space: nowrap; /* new */ overflow: hidden; /* new */ text-overflow: ellipsis; /* new */ padding-left: 10px; width: 200px; border: 1px solid #000000; }
 <div>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries</div>

More details: Applying an ellipsis to multiline text更多详细信息:将省略号应用于多行文本

Apply following style to your div.将以下样式应用于您的 div。

div{
    padding-left: 10px;
    width: 200px;
    text-overflow: ellipsis;
    overflow: hidden;
    border: 1px solid #000000;
    white-space: nowrap;
}

You will need to give it a height and use text-overflow: ellipsis;你需要给它一个高度并使用text-overflow: ellipsis;

You can use this class.你可以使用这个类。

.no-overflow {
  padding-left:10px; 
  width:200px; 
  border:1px solid #000000;
  height: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: inline-block;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM