html - 如何根据条件添加样式

标签 html css angular

我正在尝试根据我的输入复选框将 css 添加到我的 div

<div class="pvreveal"  [style]="ShowHideSection ? 'overflow:scroll;height:483px':''"  >
 <input id="isDelivery" type="checkbox" [(ngModel)]="ShowHideSection " />
</div

如何实现

最佳答案

通过使用[ngClass]。我不太喜欢内联样式

//CSS

.myClass{overflow:scroll;height:483px}

//组件

export class MyComponent {

    public ShowHideSection : boolean = true;
}

//HTML

<div class="pvreveal"  [ngClass]="{'myClass' : ShowHideSection}"  >
 <input id="isDelivery" type="checkbox" [(ngModel)]="ShowHideSection " />
</div>

关于html - 如何根据条件添加样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59673490/

相关文章:

Angular 显示缓存数据并在后台需要数据时更新新数据

html - 表单落在 div 容器之外

html - 为移动应用程序生成 UI

html - 在垂直 <ul> 中居中对齐 <li>

css - 设置 border-right 时删除 border-top gap

angular - 如何将 primeNg 下拉选择值设置为对象的 id 而不是整个对象

html - 在表列上创建覆盖

html - 如何在相对父级的填充顶部垂直对齐一个div

javascript - 可放置的背景颜色为无不工作

css - 如何在面板上添加竖线?