Angular< p>由 *ngfor赢得冠军

发布于 2025-01-26 22:32:47 字数 371 浏览 5 评论 0原文

我进行了此聊天,我正在尝试将样式应用于“ chat-c​​ontainer”

这些消息以Angular的*NGFOR显示:仅

<p *ngFor="let m of messageArray" [ngClass]="this.currentUser.user._id==m.src?'self pr-3':'otherUser pl-3'">
   {{m.msg}}
</p>

应用的类仅具有float:左或 float:right 取决于发送的用户每个消息。但是,它们总是在左边显示。

关于如何使消息浮动到相应的一侧的任何建议吗?

I have this chat in which I'm trying to apply styles to the "chat-container".

The messages are displayed with Angular's *ngFor as follows:

<p *ngFor="let m of messageArray" [ngClass]="this.currentUser.user._id==m.src?'self pr-3':'otherUser pl-3'">
   {{m.msg}}
</p>

The classes applied only have float:left or float:right depending on the user that sent each message. However, they're always being displayed in the left.

Any suggestions on how to make the messages float to their corresponding side?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

很糊涂小朋友 2025-02-02 22:32:47

使用 flexbox

<p *ngFor="let m of messageArray" [ngClass]="this.currentUser.user._id==m.src?'self pr-3':'otherUser pl-3'" class='message'>
   {{m.msg}}
</p>

在CSS上:

.message {
 display: flex;
 flex-flow: row nowrap;
 width: 100%;
}

.self {
 align-items: flex-end;
}

.otherUser {
 align-items: flex-start;
}

使用 width /em>在父级上覆盖可用空间。(您可以使用PX或%设置宽度)

use flexbox

<p *ngFor="let m of messageArray" [ngClass]="this.currentUser.user._id==m.src?'self pr-3':'otherUser pl-3'" class='message'>
   {{m.msg}}
</p>

on CSS:

.message {
 display: flex;
 flex-flow: row nowrap;
 width: 100%;
}

.self {
 align-items: flex-end;
}

.otherUser {
 align-items: flex-start;
}

use width on parent div to cover the available space.(you can set the width with px or % is up to you)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文