3.3 KiB
3.3 KiB
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
bad87fee1348bd9aecf08806 | Use a CSS Class to Style an Element | 0 | 使用CSS类来设置元素的样式 |
Description
<风格>您可以看到我们在
.blue-text {
颜色:蓝色;
}
</样式>
<style>
标记内创建了一个名为blue-text
的CSS类。您可以将类应用于HTML元素,如下所示: <h2 class="blue-text">CatPhotoApp</h2>
请注意,在CSS style
元素中,类名以句点开头。在HTML元素的class属性中,类名不包含句点。 Instructions
style
元素中,将h2
选择器更改为.red-text
并将颜色的值从blue
更新为red
。为您的h2
元素提供值为'red-text'
的class
属性。 Tests
tests:
- text: 你的<code>h2</code>元素应该是红色的。
testString: 'assert($("h2").css("color") === "rgb(255, 0, 0)", "Your <code>h2</code> element should be red.");'
- text: 你的<code>h2</code>元素应该有<code>red-text</code>类。
testString: 'assert($("h2").hasClass("red-text"), "Your <code>h2</code> element should have the class <code>red-text</code>.");'
- text: 样式表应声明一个<code>red-text</code>类,并将其颜色设置为红色。
testString: 'assert(code.match(/\.red-text\s*\{\s*color\s*:\s*red;\s*\}/g), "Your stylesheet should declare a <code>red-text</code> class and have its color set to red.");'
- text: '不要在<code>h2</code>元素中使用<code>style="color: red"</code>内联样式声明。'
testString: 'assert($("h2").attr("style") === undefined, "Do not use inline style declarations like <code>style="color: red"</code> in your <code>h2</code> element.");'
Challenge Seed
<style>
h2 {
color: blue;
}
</style>
<h2>CatPhotoApp</h2>
<main>
<p>Click here to view more <a href="#">cat photos</a>.</p>
<a href="#"><img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
<div>
<p>Things cats love:</p>
<ul>
<li>cat nip</li>
<li>laser pointers</li>
<li>lasagna</li>
</ul>
<p>Top 3 things cats hate:</p>
<ol>
<li>flea treatment</li>
<li>thunder</li>
<li>other cats</li>
</ol>
</div>
<form action="/submit-cat-photo">
<label><input type="radio" name="indoor-outdoor" checked> Indoor</label>
<label><input type="radio" name="indoor-outdoor"> Outdoor</label><br>
<label><input type="checkbox" name="personality" checked> Loving</label>
<label><input type="checkbox" name="personality"> Lazy</label>
<label><input type="checkbox" name="personality"> Energetic</label><br>
<input type="text" placeholder="cat photo URL" required>
<button type="submit">Submit</button>
</form>
</main>
Solution
// solution required