CSS 长文本处理----文本一行和多行超出,省略号显示

CSS 文本显示处理

默认:字符太长溢出了容器

<style media="screen">
  #div {
    width: 200px;
    border: 1px solid red;
  }
</style>
<div id="div">
  Most words art short & don't need to break.But Antidisestablishmentarianism is to long.
</div>
效果图

CSS 长文本处理----文本一行和多行超出,省略号显示

字符超出部分换行

<style media="screen">
  #div {
    width: 200px;
    border: 1px solid red;
    overflow-wrap: break-word;
  }
</style>
<div id="div">
  Most words art short & don't need to break.But Antidisestablishmentarianism is to long.
</div>
效果图

CSS 长文本处理----文本一行和多行超出,省略号显示

字符超出位置使用连字符

<style media="screen">
  #div {
    width: 200px;
    border: 1px solid red;
    overflow-wrap: break-word;
    hyphens: auto;
  }
</style>
<div id="div" lang="en">
  Most words art short & don't need to break.But Antidisestablishmentarianism is to long.
</div>
效果图

CSS 长文本处理----文本一行和多行超出,省略号显示

单行文本超出省略

<style media="screen">
  #div {
    width: 200px;
    border: 1px solid red;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
</style>
<div id="div">
  Most words art short & don't need to break.But Antidisestablishmentarianism is to long.
</div>
效果图

CSS 长文本处理----文本一行和多行超出,省略号显示

多行文本超出省略

<style media="screen">
  #div {
    width: 200px;
    border: 1px solid red;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }
</style>
<div id="div">
  Most words art short & don't need to break.But Antidisestablishmentarianism is to long.
</div>
效果图

CSS 长文本处理----文本一行和多行超出,省略号显示

注:日常整理,仅做参考,欢迎评论,虚心接受。

上一篇:【CSS】flex布局实现一行展示三个子元素并两端对齐


下一篇:自适应好用的一个css