freeCodeCamp/curriculum/challenges/chinese/01-responsive-web-design/basic-html-and-html5/define-the-head-and-body-of...

1.4 KiB
Raw Blame History

id title challengeType videoUrl forumTopicId
587d78aa367417b2b2512aec 定义 HTML 文档的 head 和 body 0 https://scrimba.com/p/pVMPUv/cra9bfP 301096

--description--

html 的结构主要分为两大部分:headbody。网页的描述应放入 head 标签,网页的内容则应放入 body 标签。

比如 linkmetatitlestyle 都应放入 head 标签。

这是网页布局的一个例子:

<!DOCTYPE html>
<html>
  <head>
    <!-- metadata elements -->
  </head>
  <body>
    <!-- page contents -->
  </body>
</html>

--instructions--

请给网页添加 headbodyhead 元素应包含 titlebody 元素应该包含 h1p

--hints--

网页应只有一个 head 元素。

assert($('head').length == 1);

网页应只有一个 body 元素。

assert($('body').length == 1);

head 应为 html 的子元素。

assert($('html').children('head').length == 1);

body 应为 html 的子元素。

assert($('html').children('body').length == 1);

title 应为 head 的子元素。

assert(code.match(/<head>\s*?<title>\s*?.*?\s*?<\/title>\s*?<\/head>/gi));

h1p 都应为 body 的子元素。

assert(
  code.match(
    /<body>\s*?(((<h1>\s*?.*?\s*?<\/h1>\s*?)(<p>(.*\s*)*?<\/p>\s*?))|((<p>\s*?.*?\s*?<\/p>\s*?)(<h1>(.*\s*)*?<\/h1>\s*?)))<\/body>/gi
  )
);

--solutions--