css - 根据条件应用 css
问题描述
我正在尝试根据条件应用 css 类。这是我的代码,但似乎没有正确应用该类。
基本上如果selectedEmployee.isHrEmailAddress
是真的那么我想section
用.section-postal
HTML
<section [ngClass]="{'.section-postal': selectedEmployee.isHrEmailAddress}">
<div class="page-container">
<div id="wrapper">
<form *ngIf="contactDetailsForm" [formGroup]="contactDetailsForm">
<div class="text-left">
<div class="flex flex-row sm:flex-col md:flex-row-reverse lg:flex-col-reverse xl:flex-row">
<div class="check-container text-left" style="width: 450px;">
<div class="flex flex-row sm:flex-col md:flex-row-reverse lg:flex-col-reverse xl:flex-row">
<div class="line">
<p-checkbox name="isHrEmailAddress" formControlName="isHrEmailAddress"
[(ngModel)]="selectedEmployee.isHrEmailAddress" binary="true"
(onChange)="toggle('emailCheckId')">
</p-checkbox>
<span class="ml-2 pt-4" style="font-size: 15px;">I am using my email address on the
member's behalf</span>
</div>
</div>
</div>
</div>
<div class="note" *ngIf="selectedEmployee.isHrEmailAddress">
<span>Please note: You will need to confirm the employee's postal address, so that they can be
contacted in future.</span>
</div>
</div>
</form>
</div>
</div>
</section>
css
section {
height: 500px;
}
.section-postal {
height: 650px;
}
解决方案
您需要从[ngClass]
值中的类名中删除点。
<section [ngClass]="{'section-postal': selectedEmployee.isHrEmailAddress}">
点在CSS 选择器语法中用于表示一个类。HTML 中的类应该没有点。
section { /* denotes the `<section>` tag: type selector syntax */
height: 500px;
}
.section-postal { /* denotes the `section-postal` class: class selector syntax */
height: 650px;
}
推荐阅读
- mysql - MySQL 8 时间戳精度(以纳秒为单位)
- connection-pooling - 检测池化数据源中的连接泄漏
- android - 是否会为新用户运行 Room 迁移?
- jquery - JS如何向我的快递服务器发送http get请求?
- flutter - 如何在上下文之间共享集团
- c# - 选择选项下拉菜单不显示所选选项
- vue.js - vue-konva:从工作不正确的阶段中删除特定节点
- groovy - 在 groovy 页面中使用 findElement
- javascript - 如何将超链接应用到现有 HTML 中的 URL 文本 - 使用 JSFIDDLE 和工作解决方案更新
- jquery - jquery如何在点击关闭后再次开启?