2018-10-10 18:03:03 -04:00
|
|
|
|
---
|
|
|
|
|
id: bad87fee1348bd9bedf08813
|
|
|
|
|
title: Add Borders Around Your Elements
|
|
|
|
|
challengeType: 0
|
2019-12-13 13:47:57 +08:00
|
|
|
|
videoUrl: 'https://scrimba.com/c/c2MvnHZ'
|
|
|
|
|
forumTopicId: 16630
|
2020-01-08 12:40:17 +08:00
|
|
|
|
localeTitle: 在元素周围添加边框
|
2018-10-10 18:03:03 -04:00
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## Description
|
2019-12-13 13:47:57 +08:00
|
|
|
|
<section id='description'>
|
|
|
|
|
CSS 边框具有<code>style</code>,<code>color</code>和<code>width</code>属性。
|
2020-01-08 12:40:17 +08:00
|
|
|
|
假如我们想要创建一个 5px 的红色实线边框包围一个 HTML 元素,我们可以这样做:
|
2019-12-13 13:47:57 +08:00
|
|
|
|
|
|
|
|
|
```html
|
|
|
|
|
<style>
|
|
|
|
|
.thin-red-border {
|
|
|
|
|
border-color: red;
|
|
|
|
|
border-width: 5px;
|
|
|
|
|
border-style: solid;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</section>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
## Instructions
|
2019-12-13 13:47:57 +08:00
|
|
|
|
<section id='instructions'>
|
2020-01-08 12:40:17 +08:00
|
|
|
|
创建一个<code>thick-green-border</code> CSS class,该 class 应在 HTML 元素周围添加一个 10px 的绿色实线边框,将它应用在猫咪照片上。
|
|
|
|
|
记得在一个元素上可以同时应用多个<code>class</code>,通过使用空格来分隔。例子如下:
|
2019-12-13 13:47:57 +08:00
|
|
|
|
<code><img class="class1 class2"></code>
|
|
|
|
|
</section>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
## Tests
|
|
|
|
|
<section id='tests'>
|
|
|
|
|
|
|
|
|
|
```yml
|
|
|
|
|
tests:
|
2020-01-08 12:40:17 +08:00
|
|
|
|
- text: '<code>img</code>元素应该含有<code>smaller-image</code> class。'
|
|
|
|
|
testString: assert($("img").hasClass("smaller-image"));
|
|
|
|
|
- text: '<code>img</code>元素应该含有<code>thick-green-border</code> class。'
|
|
|
|
|
testString: assert($("img").hasClass("thick-green-border"));
|
|
|
|
|
- text: '设置图片边框为<code>10px</code>。'
|
|
|
|
|
testString: assert($("img").hasClass("thick-green-border") && parseInt($("img").css("border-top-width"), 10) >= 8 && parseInt($("img").css("border-top-width"), 10) <= 12);
|
|
|
|
|
- text: '设置图片边框为<code>solid</code>实线。'
|
|
|
|
|
testString: assert($("img").css("border-right-style") === "solid");
|
2019-12-13 13:47:57 +08:00
|
|
|
|
- text: '<code>img</code>元素的边框颜色应该为绿色。'
|
2020-01-08 12:40:17 +08:00
|
|
|
|
testString: assert($("img").css("border-left-color") === "rgb(0, 128, 0)");
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
## Challenge Seed
|
|
|
|
|
<section id='challengeSeed'>
|
|
|
|
|
|
|
|
|
|
<div id='html-seed'>
|
|
|
|
|
|
|
|
|
|
```html
|
|
|
|
|
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
|
|
|
|
|
<style>
|
|
|
|
|
.red-text {
|
|
|
|
|
color: red;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
h2 {
|
|
|
|
|
font-family: Lobster, monospace;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p {
|
|
|
|
|
font-size: 16px;
|
|
|
|
|
font-family: monospace;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.smaller-image {
|
|
|
|
|
width: 100px;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
<h2 class="red-text">CatPhotoApp</h2>
|
|
|
|
|
<main>
|
2020-01-08 12:40:17 +08:00
|
|
|
|
<p class="red-text">点击查看更多<a href="#">猫图</a>。</p>
|
2019-12-13 13:47:57 +08:00
|
|
|
|
|
|
|
|
|
<a href="#"><img src="https://bit.ly/fcc-relaxing-cat" alt="一只仰卧着的萌猫" class="smaller-image"></a>
|
|
|
|
|
|
2018-10-10 18:03:03 -04:00
|
|
|
|
<div>
|
2019-12-13 13:47:57 +08:00
|
|
|
|
<p>猫咪最喜欢的三件东西:</p>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
<ul>
|
2019-12-13 13:47:57 +08:00
|
|
|
|
<li>猫薄荷</li>
|
|
|
|
|
<li>激光笔</li>
|
|
|
|
|
<li>千层饼</li>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
</ul>
|
2019-12-13 13:47:57 +08:00
|
|
|
|
<p>猫咪最讨厌的三件东西:</p>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
<ol>
|
2019-12-13 13:47:57 +08:00
|
|
|
|
<li>跳蚤</li>
|
|
|
|
|
<li>打雷</li>
|
|
|
|
|
<li>同类</li>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
</ol>
|
|
|
|
|
</div>
|
2019-12-13 13:47:57 +08:00
|
|
|
|
|
2020-07-15 02:55:06 -07:00
|
|
|
|
<form action="https://freecatphotoapp.com/submit-cat-photo">
|
2019-12-13 13:47:57 +08:00
|
|
|
|
<label><input type="radio" name="indoor-outdoor">室内</label>
|
|
|
|
|
<label><input type="radio" name="indoor-outdoor">室外</label><br>
|
|
|
|
|
<label><input type="checkbox" name="personality">忠诚</label>
|
|
|
|
|
<label><input type="checkbox" name="personality">懒惰</label>
|
|
|
|
|
<label><input type="checkbox" name="personality">积极</label><br>
|
|
|
|
|
<input type="text" placeholder="猫咪图片地址" required>
|
|
|
|
|
<button type="submit">提交</button>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
</form>
|
|
|
|
|
</main>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
## Solution
|
|
|
|
|
<section id='solution'>
|
|
|
|
|
|
2019-12-13 13:47:57 +08:00
|
|
|
|
```html
|
2018-10-10 18:03:03 -04:00
|
|
|
|
// solution required
|
|
|
|
|
```
|
2020-02-18 01:40:55 +09:00
|
|
|
|
|
2018-10-10 18:03:03 -04:00
|
|
|
|
</section>
|
2019-12-13 13:47:57 +08:00
|
|
|
|
|