freeCodeCamp/curriculum/challenges/chinese-traditional/14-responsive-web-design-22/learn-css-grid-by-building-.../6143869bb45bd85e3b1926aa.md

2.9 KiB

id title challengeType dashedName
6143869bb45bd85e3b1926aa 步驟 4 0 step-4

--description--

在你的 .heading 元素中,創建一個 header 元素,將該元素的 class 設置爲 hero

在那個元素中,創建一個 img 元素,將 src 設置爲 https://cdn.freecodecamp.org/platform/universal/fcc_meta_1920X1080-indigo.png,將 alt 設置爲 freecodecamp logo,並將 class 設置爲 hero-img

img 元素上的 loading 屬性可以設置爲 lazy,以告訴瀏覽器在需要(例如,當用戶將圖像滾動到視圖中時)的時候才獲取圖像資源。 另外一個好處是,延遲加載的元素在加載非延遲元素之前不會加載——這意味着互聯網連接速度較慢的用戶可以查看你的頁面的內容,而無需等待圖像加載。

給你的新 img 元素一個 loading 屬性,設置爲 lazy

--hints--

你應該創建一個 header 元素。

assert.exists(document.querySelector('header'));

你的 header 元素應該在你的 .heading 元素中。

assert(document.querySelector('header')?.parentElement?.className === 'heading');

你的 header 元素應該將 class 設置爲 hero

assert(document.querySelector('header')?.className === 'hero');

你應該創建一個 img 元素。

assert.exists(document.querySelector('img'));

你的 img 元素應該在你的 header 元素中。

assert(document.querySelector('img')?.parentElement?.localName === 'header');

你的 img 元素應該有一個 src,值爲 https://cdn.freecodecamp.org/platform/universal/fcc_meta_1920X1080-indigo.png

assert(document.querySelector('img')?.getAttribute('src') === 'https://cdn.freecodecamp.org/platform/universal/fcc_meta_1920X1080-indigo.png');

你的 img 元素應該有一個 alt,值爲 freecodecamp logo

assert(document.querySelector('img')?.getAttribute('alt') === 'freecodecamp logo');

你的 img 元素應該有一個 loading 屬性,值爲 lazy

assert(document.querySelector('img')?.getAttribute('loading') === 'lazy');

你的 img 元素應該有一個 classhero-img

assert(document.querySelector('img')?.className === 'hero-img');

--seed--

--seed-contents--

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Magazine</title>
    <link
      href="https://fonts.googleapis.com/css?family=Anton%7CBaskervville%7CRaleway&display=swap"
      rel="stylesheet"
    />
    <link
      rel="stylesheet"
      href="https://use.fontawesome.com/releases/v5.8.2/css/all.css"
    />
    <link rel="stylesheet" href="styles.css" />
  </head>
  <body>
--fcc-editable-region--
    <main>
      <section class="heading">

      </section>
    </main>
--fcc-editable-region--
  </body>
</html>