点击查看更多猫图.
猫咪最喜欢的三件东西:
- 猫薄荷
- 激光笔
- 千层饼
猫咪最讨厌的三件东西:
- 跳蚤
- 打雷
- 同类
class
具有可重用性,可应用于各种 HTML 元素。
一个 CSSclass
声明示例,如下所示:
```html
```
可以看到,我们在<style>
样式声明区域里,创建了一个名为blue-text
的class
选择器。
你可以将 CSSclass
选择器应用到一个HTML元素里,如下所示:
<h2 class="blue-text">CatPhotoApp</h2>
注意:在style
样式区域声明里,class
需以.
开头。而在 HTML 元素里,class
属性的前面不能添加.
。
style
样式声明里,把h2
元素选择器改为.red-text
class 选择器,同时将颜色blue
变为red
。
在h2
元素里,添加一个class
属性,且值为'red-text'
。
h2
元素应该为红色。'
testString: assert($("h2").css("color") === "rgb(255, 0, 0)");
- text: 'h2
元素应含有red-text
class 选择器。'
testString: assert($("h2").hasClass("red-text"));
- text: 'style
样式声明区域里应该包含一个red-text
class 选择器,并且它的颜色应为红色。'
testString: assert(code.match(/\.red-text\s*\{\s*color\s*:\s*red;\s*\}/g));
- text: '不要在h2
元素里使用行内样式:style="color: red"
。'
testString: assert($("h2").attr("style") === undefined);
```
点击查看更多猫图.
猫咪最喜欢的三件东西:
猫咪最讨厌的三件东西: