2018-10-10 22:03:03 +00:00
|
|
|
---
|
|
|
|
id: 587d781b367417b2b2512abe
|
2020-12-16 07:37:30 +00:00
|
|
|
title: 给卡片元素添加 box-shadow
|
2018-10-10 22:03:03 +00:00
|
|
|
challengeType: 0
|
2020-02-11 07:46:34 +00:00
|
|
|
videoUrl: 'https://scrimba.com/c/cvVZdUd'
|
|
|
|
forumTopicId: 301031
|
2021-01-13 02:31:00 +00:00
|
|
|
dashedName: add-a-box-shadow-to-a-card-like-element
|
2018-10-10 22:03:03 +00:00
|
|
|
---
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
# --description--
|
|
|
|
|
|
|
|
`box-shadow` 属性用来给元素添加阴影,该属性值是由逗号分隔的一个或多个阴影列表。
|
|
|
|
|
|
|
|
`box-shadow` 属性的阴影依次由下面这些值描述:
|
|
|
|
|
2020-02-11 07:46:34 +00:00
|
|
|
<ul>
|
|
|
|
<li><code>offset-x</code> 阴影的水平偏移量;</li>
|
|
|
|
<li><code>offset-y</code> 阴影的垂直偏移量;</li>
|
|
|
|
<li><code>blur-radius</code> 模糊半径;</li>
|
|
|
|
<li><code>spread-radius</code> 阴影扩展半径;</li>
|
2021-02-06 04:42:36 +00:00
|
|
|
<li><code>color</code></li>
|
2020-02-11 07:46:34 +00:00
|
|
|
</ul>
|
2020-12-16 07:37:30 +00:00
|
|
|
|
|
|
|
其中 `blur-radius` 和 `spread-radius` 是可选的。
|
|
|
|
|
|
|
|
可以通过逗号分隔每个 `box-shadow` 元素的属性来添加多个 box-shadow。
|
|
|
|
|
2020-02-11 07:46:34 +00:00
|
|
|
如下为添加了模糊效果的例子,它使用了透明度较高的黑色作为阴影:
|
|
|
|
|
|
|
|
```css
|
|
|
|
box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23);
|
|
|
|
```
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
# --instructions--
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2021-02-06 04:42:36 +00:00
|
|
|
元素现在有一个 `thumbnail` id。 在这个选择器中,使用上面的示例 CSS 值在卡片上加一个 `box-shadow`。
|
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
|
|
|
应该给 id 为 `thumbnail` 的元素添加 `box-shadow` 属性。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
```js
|
|
|
|
assert(code.match(/#thumbnail\s*?{\s*?box-shadow/g));
|
2018-10-10 22:03:03 +00:00
|
|
|
```
|
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
`box-shadow` 属性值应该是题目说明中指定的 CSS 值。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
```js
|
|
|
|
assert(
|
|
|
|
code.match(
|
|
|
|
/box-shadow:\s*?0\s+?10px\s+?20px\s+?rgba\(\s*?0\s*?,\s*?0\s*?,\s*?0\s*?,\s*?0?\.19\)\s*?,\s*?0\s+?6px\s+?6px\s+?rgba\(\s*?0\s*?,\s*?0\s*?,\s*?0\s*?,\s*?0?\.23\)/gi
|
|
|
|
)
|
|
|
|
);
|
2018-10-10 22:03:03 +00:00
|
|
|
```
|
2020-02-11 07:46:34 +00:00
|
|
|
|
2021-01-13 02:31:00 +00:00
|
|
|
# --seed--
|
|
|
|
|
|
|
|
## --seed-contents--
|
|
|
|
|
|
|
|
```html
|
|
|
|
<style>
|
|
|
|
h4 {
|
|
|
|
text-align: center;
|
|
|
|
background-color: rgba(45, 45, 45, 0.1);
|
|
|
|
padding: 10px;
|
|
|
|
font-size: 27px;
|
|
|
|
}
|
|
|
|
p {
|
|
|
|
text-align: justify;
|
|
|
|
}
|
|
|
|
.links {
|
|
|
|
text-align: left;
|
|
|
|
color: black;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.fullCard {
|
|
|
|
width: 245px;
|
|
|
|
border: 1px solid #ccc;
|
|
|
|
border-radius: 5px;
|
|
|
|
margin: 10px 5px;
|
|
|
|
padding: 4px;
|
|
|
|
}
|
|
|
|
.cardContent {
|
|
|
|
padding: 10px;
|
|
|
|
}
|
|
|
|
.cardText {
|
|
|
|
margin-bottom: 30px;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<div class="fullCard" id="thumbnail">
|
|
|
|
<div class="cardContent">
|
|
|
|
<div class="cardText">
|
|
|
|
<h4>Alphabet</h4>
|
|
|
|
<hr>
|
|
|
|
<p><em>Google was founded by Larry Page and Sergey Brin while they were <u>Ph.D. students</u> at <strong>Stanford University</strong>.</em></p>
|
|
|
|
</div>
|
|
|
|
<div class="cardLinks">
|
|
|
|
<a href="https://en.wikipedia.org/wiki/Larry_Page" target="_blank" class="links">Larry Page</a><br><br>
|
|
|
|
<a href="https://en.wikipedia.org/wiki/Sergey_Brin" target="_blank" class="links">Sergey Brin</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
```
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
# --solutions--
|
|
|
|
|
2021-01-13 02:31:00 +00:00
|
|
|
```html
|
|
|
|
<style>
|
|
|
|
h4 {
|
|
|
|
text-align: center;
|
|
|
|
background-color: rgba(45, 45, 45, 0.1);
|
|
|
|
padding: 10px;
|
|
|
|
font-size: 27px;
|
|
|
|
}
|
|
|
|
p {
|
|
|
|
text-align: justify;
|
|
|
|
}
|
|
|
|
.links {
|
|
|
|
text-align: left;
|
|
|
|
color: black;
|
|
|
|
}
|
|
|
|
#thumbnail {
|
|
|
|
box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23);
|
|
|
|
}
|
|
|
|
.fullCard {
|
|
|
|
width: 245px;
|
|
|
|
border: 1px solid #ccc;
|
|
|
|
border-radius: 5px;
|
|
|
|
margin: 10px 5px;
|
|
|
|
padding: 4px;
|
|
|
|
}
|
|
|
|
.cardContent {
|
|
|
|
padding: 10px;
|
|
|
|
}
|
|
|
|
.cardText {
|
|
|
|
margin-bottom: 30px;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<div class="fullCard" id="thumbnail">
|
|
|
|
<div class="cardContent">
|
|
|
|
<div class="cardText">
|
|
|
|
<h4>Alphabet</h4>
|
|
|
|
<hr>
|
|
|
|
<p><em>Google was founded by Larry Page and Sergey Brin while they were <u>Ph.D. students</u> at <strong>Stanford University</strong>.</em></p>
|
|
|
|
</div>
|
|
|
|
<div class="cardLinks">
|
|
|
|
<a href="https://en.wikipedia.org/wiki/Larry_Page" target="_blank" class="links">Larry Page</a><br><br>
|
|
|
|
<a href="https://en.wikipedia.org/wiki/Sergey_Brin" target="_blank" class="links">Sergey Brin</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
```
|