2018-10-10 22:03:03 +00:00
|
|
|
|
---
|
|
|
|
|
id: bad87fee1348bd9bedf08813
|
2020-12-16 07:37:30 +00:00
|
|
|
|
title: 在元素周围添加边框
|
2018-10-10 22:03:03 +00:00
|
|
|
|
challengeType: 0
|
2019-12-13 05:47:57 +00:00
|
|
|
|
videoUrl: 'https://scrimba.com/c/c2MvnHZ'
|
|
|
|
|
forumTopicId: 16630
|
2018-10-10 22:03:03 +00:00
|
|
|
|
---
|
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
|
# --description--
|
|
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
|
CSS 边框具有 `style`、`color`、`width` 属性。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
|
假如我们要将一个 HTML 元素边框设置为 5px 的红色实线边框,我们可以这样做:
|
2019-12-13 05:47:57 +00:00
|
|
|
|
|
|
|
|
|
```html
|
|
|
|
|
<style>
|
|
|
|
|
.thin-red-border {
|
|
|
|
|
border-color: red;
|
|
|
|
|
border-width: 5px;
|
|
|
|
|
border-style: solid;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
```
|
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
|
# --instructions--
|
2018-10-10 22:03:03 +00:00
|
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
|
创建一个 `thick-green-border` 的 class,该 class 应在 HTML 元素周围添加一个 10px 的绿色实线边框,并将这个 class 应用在猫咪照片上。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
|
记得在一个元素上可以同时应用多个 `class`,使用空格来分隔不同 class 即可,例如:
|
2018-10-10 22:03:03 +00:00
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
|
`<img class="class1 class2">`
|
2018-10-10 22:03:03 +00:00
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
|
# --hints--
|
2018-10-10 22:03:03 +00:00
|
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
|
`img` 元素应包含 `smaller-image` class。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
|
```js
|
|
|
|
|
assert($('img').hasClass('smaller-image'));
|
|
|
|
|
```
|
2018-10-10 22:03:03 +00:00
|
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
|
`img` 元素应包含 `thick-green-border` class。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
|
```js
|
|
|
|
|
assert($('img').hasClass('thick-green-border'));
|
|
|
|
|
```
|
2018-10-10 22:03:03 +00:00
|
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
|
图片边框宽度应设置为 `10px`。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
assert(
|
|
|
|
|
$('img').hasClass('thick-green-border') &&
|
|
|
|
|
parseInt($('img').css('border-top-width'), 10) >= 8 &&
|
|
|
|
|
parseInt($('img').css('border-top-width'), 10) <= 12
|
|
|
|
|
);
|
2018-10-10 22:03:03 +00:00
|
|
|
|
```
|
|
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
|
图片边框样式应为 `solid` 实线。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
|
```js
|
|
|
|
|
assert($('img').css('border-right-style') === 'solid');
|
|
|
|
|
```
|
2018-10-10 22:03:03 +00:00
|
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
|
`img` 元素的边框颜色应为绿色。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
|
```js
|
|
|
|
|
assert($('img').css('border-left-color') === 'rgb(0, 128, 0)');
|
2018-10-10 22:03:03 +00:00
|
|
|
|
```
|
2020-02-17 16:40:55 +00:00
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
|
# --solutions--
|
|
|
|
|
|