如何按角度按伪类应用?

发布于 2025-02-05 01:46:21 字数 463 浏览 4 评论 0原文

我有以下CSS

#auction-history div:after {
    content: "";
    width: 100%;
    height: 8px;
    position: absolute;
    bottom: -8px;
    background: #bad3e0;
    left: 0;
}

此CSS始终应用于我的DIV。

我需要基于布尔值的HTML中将此假类带有条件。

因此,当我

isLoading = true or false

需要绑定时,加载属性,如果它是真的 - 我不想在我的div上添加thius pseudeo class,如果是错误的,我需要应用

我知道我可以在Angular上应用类带有ngclass的条件,但我不知道该如何使用伪类进行此操作。

I have the following css

#auction-history div:after {
    content: "";
    width: 100%;
    height: 8px;
    position: absolute;
    bottom: -8px;
    background: #bad3e0;
    left: 0;
}

this css will be applied always on my div.

I need to have this pseudoclass on condition in my Html based on boolean.

So when i have

isLoading = true or false

i need to bind to this is loading property and if it is true - I don't want to appky thius pseudeo class on my div if it is false I need to apply

I know that I can apply classes in Angular on condition with ngClass but I don't know how can i do this with pseudo classes.

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

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

发布评论

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

评论(2

盗梦空间 2025-02-12 01:46:22

您可以使用::之后来创建一个其他类来处理此操作。

示例:

html

<p [class.show--after]="isLoading  == true">My name is Adrita</p>

css

.show--after::after {
   content: ' - After content';
 }

stackbiltz demo

You can create a additional class with ::after to handle this.

Example:

HTML

<p [class.show--after]="isLoading  == true">My name is Adrita</p>

CSS

.show--after::after {
   content: ' - After content';
 }

StackBiltz Demo

策马西风 2025-02-12 01:46:22

只需“重新考虑”您的CSS,例如您可以使用“

#auction-history:not(.loading) div:after {
    content: "";
    ...
}

您的.html

<div #auction-history [class.loading]="yourVariable">...</div>

或简单的类

#auction-history.not-loading div:after {
    content: "";
    ...
}
 <div #auction-history [class.not-loading]="yourVariable">...</div>

注:您可以使用[ngclass][ngstyle][style.property] =“变量”[class.classname] =“ variable”

Just "re-think" your css, e.g. you can use "not"

#auction-history:not(.loading) div:after {
    content: "";
    ...
}

Your .html

<div #auction-history [class.loading]="yourVariable">...</div>

or a simple class

#auction-history.not-loading div:after {
    content: "";
    ...
}
 <div #auction-history [class.not-loading]="yourVariable">...</div>

NOTE: You can use [ngClass]or [ngStyle] or [style.property]="variable" or [class.classname]="variable"

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