2018-10-10 22:03:03 +00:00
|
|
|
---
|
|
|
|
id: bad87fee1348bd9aede08835
|
2020-12-16 07:37:30 +00:00
|
|
|
title: 元素嵌套
|
2018-10-10 22:03:03 +00:00
|
|
|
challengeType: 0
|
2019-12-26 12:05:59 +00:00
|
|
|
videoUrl: 'https://scrimba.com/p/pVMPUv/cNW4kC3'
|
|
|
|
forumTopicId: 18246
|
2021-01-13 02:31:00 +00:00
|
|
|
dashedName: nest-many-elements-within-a-single-div-element
|
2018-10-10 22:03:03 +00:00
|
|
|
---
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
# --description--
|
|
|
|
|
2021-02-06 04:42:36 +00:00
|
|
|
`div` 元素也叫内容划分元素,是一个包裹其他元素的通用容器。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
2019-12-26 12:05:59 +00:00
|
|
|
它也是 HTML 中出现频率最高的元素。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
和其他普通元素一样,你可以用 `<div>` 来标记一个 `div` 元素的开始,用 `</div>` 来标记一个 `div` 元素的结束。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
|
|
|
# --instructions--
|
|
|
|
|
2021-02-06 04:42:36 +00:00
|
|
|
将你的列表“猫喜欢的三件事”和“猫最讨厌的三件事”放入同一个 `div` 元素中。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
2021-02-06 04:42:36 +00:00
|
|
|
提示:你可以在第一个 `<p>` 之前插入 `div` 开始标记,在 `</ol>` 之后插入 `div` 结束标签。 这样,所有的列表都会位于 `div` 之内。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
|
|
|
# --hints--
|
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
所有的 `p` 元素都应嵌套在 `div` 元素中。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert($('div').children('p').length > 1);
|
2018-10-10 22:03:03 +00:00
|
|
|
```
|
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
所有的 `ul` 元素都应嵌套在 `div` 元素中。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert($('div').children('ul').length > 0);
|
2018-10-10 22:03:03 +00:00
|
|
|
```
|
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
所有的 `ol` 元素都应嵌套在 `div` 元素中。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
```js
|
|
|
|
assert($('div').children('ol').length > 0);
|
|
|
|
```
|
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
`div` 元素应有结束标签。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
```js
|
|
|
|
assert(
|
|
|
|
code.match(/<\/div>/g) &&
|
|
|
|
code.match(/<\/div>/g).length === code.match(/<div>/g).length
|
|
|
|
);
|
|
|
|
```
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2021-01-13 02:31:00 +00:00
|
|
|
# --seed--
|
|
|
|
|
|
|
|
## --seed-contents--
|
|
|
|
|
|
|
|
```html
|
|
|
|
<h2>CatPhotoApp</h2>
|
|
|
|
<main>
|
|
|
|
<p>Click here to view more <a href="#">cat photos</a>.</p>
|
|
|
|
|
2021-04-27 15:16:44 +00:00
|
|
|
<a href="#"><img src="https://www.bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
|
2021-01-13 02:31:00 +00:00
|
|
|
|
|
|
|
<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>
|
|
|
|
|
2021-04-27 15:16:44 +00:00
|
|
|
<form action="https://www.freecatphotoapp.com/submit-cat-photo">
|
2021-01-13 02:31:00 +00:00
|
|
|
<label for="indoor"><input id="indoor" type="radio" name="indoor-outdoor" value="indoor" checked> Indoor</label>
|
|
|
|
<label for="outdoor"><input id="outdoor" type="radio" name="indoor-outdoor" value="outdoor"> Outdoor</label><br>
|
|
|
|
<label for="loving"><input id="loving" type="checkbox" name="personality" value="loving" checked> Loving</label>
|
|
|
|
<label for="lazy"><input id="lazy" type="checkbox" name="personality" value="lazy"> Lazy</label>
|
|
|
|
<label for="energetic"><input id="energetic" type="checkbox" name="personality" value="energetic"> Energetic</label><br>
|
|
|
|
<input type="text" placeholder="cat photo URL" required>
|
|
|
|
<button type="submit">Submit</button>
|
|
|
|
</form>
|
|
|
|
</main>
|
|
|
|
```
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
# --solutions--
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2021-01-13 02:31:00 +00:00
|
|
|
```html
|
|
|
|
<h2>CatPhotoApp</h2>
|
|
|
|
<main>
|
|
|
|
<p>Click here to view more <a href="#">cat photos</a>.</p>
|
2021-02-06 04:42:36 +00:00
|
|
|
|
2021-04-27 15:16:44 +00:00
|
|
|
<a href="#"><img src="https://www.bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
|
2021-01-13 02:31:00 +00:00
|
|
|
<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>
|
2021-04-27 15:16:44 +00:00
|
|
|
<form action="https://www.freecatphotoapp.com/submit-cat-photo">
|
2021-01-13 02:31:00 +00:00
|
|
|
<label for="indoor"><input id="indoor" type="radio" name="indoor-outdoor" value="indoor" checked> Indoor</label>
|
|
|
|
<label for="outdoor"><input id="outdoor" type="radio" name="indoor-outdoor" value="outdoor"> Outdoor</label><br>
|
|
|
|
<label for="loving"><input id="loving" type="checkbox" name="personality" value="loving" checked> Loving</label>
|
|
|
|
<label for="lazy"><input id="lazy" type="checkbox" name="personality" value="lazy"> Lazy</label>
|
|
|
|
<label for="energetic"><input id="energetic" type="checkbox" name="personality" value="energetic"> Energetic</label><br>
|
|
|
|
<input type="text" placeholder="cat photo URL" required>
|
|
|
|
<button type="submit">Submit</button>
|
|
|
|
</form>
|
|
|
|
</main>
|
|
|
|
```
|