使用 text-truncate() 自動依寬度為 String 加上 ... ?

栏目: CSS · 发布时间: 6年前

内容简介:在macOS Mojave 10.14.5WebStorm 2019.1.3

如何自動依寬度為 String 加上 … ? 一文中,我們自行建立了 text-ellipsis class 完成需求,事實上 Vuetify 已內建 text-truncate helper class,可直接使用。

Version

macOS Mojave 10.14.5

WebStorm 2019.1.3

Node 12.4.0

Vue 2.6.10

Vuetify 1.5.5

Safari 12.1.1

Safari

使用 text-truncate() 自動依寬度為 String 加上 ... ?

我們希望只顯示一行,過長的文字自動加上了 ...

Vue File

App.vue

<template>
  <div class="headline text-truncate">
    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Asperiores dicta eligendi est ex, quod voluptatibus!
    Accusantium aliquam commodi deleniti dolor facere, ipsam itaque, iure, nulla omnis porro quae repudiandae rerum?
  </div>
</template>

<script>
export default {
  name: 'App',
}
</script>

第 2 行

<div class="headline text-truncate">
  Lorem ipsum dolor sit amet, consectetur adipisicing elit. Asperiores dicta eligendi est ex, quod voluptatibus!
  Accusantium aliquam commodi deleniti dolor facere, ipsam itaque, iure, nulla omnis porro quae repudiandae rerum?
</div>

<div> 內文相當長。

<div> 使用了 Vuetify 提供的 headlinetext-truncate 兩個 helper class。

  • headline :相當於 <h5>
  • text-truncate :自動依寬度為 string 加上

CSS

使用 text-truncate() 自動依寬度為 String 加上 ... ?

觀察 .text-truncate 會發現也是由 white-space: nowrapoverflow: hiddentext-overflow: ellipssis 三個 property 所組成,與 如何自動依寬度為 String 加上 … ? 一文所提到原理完全相同。

Conclusion

  • 若 CSS Framework 提境供了 helper class,建議直接使用 helper class,較精簡也便於維護,但別忘了觀察其組成 property,畢竟 CSS 才是根本,要知其然也知其所以然

以上所述就是小编给大家介绍的《使用 text-truncate() 自動依寬度為 String 加上 ... ?》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Remote

Remote

Jason Fried、David Heinemeier Hansson / Crown Business / 2013-10-29 / CAD 26.95

The “work from home” phenomenon is thoroughly explored in this illuminating new book from bestselling 37signals founders Fried and Hansson, who point to the surging trend of employees working from hom......一起来看看 《Remote》 这本书的介绍吧!

SHA 加密
SHA 加密

SHA 加密工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具