web前端全系列 教程
1839个小节阅读:2243.7k
目录
鸿蒙应用开发
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
可以用类属性绑定从DOM元素的 class
属性中添加和删除 CSS 类。
绑定类型 | 语法 | 输入类型 | 范例输入值 | 最终输出 |
---|---|---|---|---|
单一类绑定 | [class.sale]="onSale" | boolean | undefined | null | true , false | true=>class='sale'; false=>不显示class属性 |
多重类绑定 | [class]="classExpression" | string | "my-class-1 my-class-2 my-class-3" | class='my-class-1 my-class-2 my-class-3' |
Record<string, boolean |undefined |null> | {foo: true, bar: false} | class='foo' | ||
Array <string > | ['foo', 'bar'] | class="bar foo" |
可以绑定元素的style
属性来动态设置样式。
绑定类型 | 语法 | 输入属性 | 范例输入值 | 最终输出 |
---|---|---|---|---|
单一样式绑定 | [style.width]="width" | string | undefined | null | "100px" | style="width: 100px;" |
带单位的单一样式绑定 | [style.width.px]="width" | number | undefined | null | 100 | style="width: 100px;" |
多重样式绑定 | [style]="styleExpression" | string | "width: 100px; height: 100px" | style="height: 100px; width: 100px;" |
Record<string, string |undefined |null> | {width: '100px', height: '100px'} | style="height: 100px; width: 100px;" |
实时效果反馈
1.下列写法错误的是:
A <div [class]="['foo','bar']"></div>
B <div [class.sale]="true"></div>
C <div [style]="{width:'100px',height:'100px'}"></div>
D <div [style]="width:'100px';height:'100px'"></div>
答案
1=>D