如何在角度 6 中实现内容显示更多和显示更少

编程入门 行业动态 更新时间:2024-10-21 03:46:57
本文介绍了如何在角度 6 中实现内容显示更多和显示更少的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我们有 6 个内容 div.我们还使用字符限制每个 div.我们使用了 bootstrap 4 angular 6 版本.

6 div 一些切换 div 内容打开,一些关闭如何解决这个问题.

解决方案

使用一些自定义 css 很容易实现.试试这个:

模板:

Lorem Ipsum 只是印刷和排版行业的虚拟文本.自 1500 年代以来,Lorem Ipsum 一直是行业标准的虚拟文本,当时一位不知名的印刷商使用了一个类型的厨房,并争先恐后地制作了一本类型样本书.它不仅存活了五个世纪,而且还经历了电子排版的飞跃,基本保持不变.它在 1960 年代随着包含 Lorem Ipsum 段落的 Letraset 表的发布而流行,最近随着桌面出版软件 Aldus PageMaker 的发布,包括 Lorem Ipsum 的版本.

<button (click)="show = !show">{{ show ?'显示更少':'显示更多' }}</button>

CSS:

.container {字体大小:16px;行高:16px;高度:32px;溢出:隐藏;}.展示 {溢出:可见;高度:自动;}

组件:

show = false;

这是一个示例StackBlitz 供您参考.

We have 6 content div. And also we using character limit each div. We used bootstrap 4 angular 6 version.

6 div some toggle div content opened and some closed How to achive this case.

解决方案

It's very easy to implement with some custom css. Give this a try:

Template:

<div class="container" [class.show]="show">
    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, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
<button (click)="show = !show">{{ show ? 'Show less': 'Show More' }}</button>

CSS:

.container {
  font-size: 16px;
  line-height: 16px;
  height: 32px;
  overflow: hidden;
}

.show {
  overflow: visible;
  height: auto;
}

Component:

show = false;

Here's a Sample StackBlitz for your ref.

这篇关于如何在角度 6 中实现内容显示更多和显示更少的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-22 17:03:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1027004.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:更少   角度   更多   内容   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!