freeCodeCamp/curriculum/challenges/chinese/01-responsive-web-design/basic-html-and-html5/add-images-to-your-website....

2.8 KiB
Raw Blame History

id title challengeType guideUrl videoUrl localeTitle
bad87fee1348bd9aedf08812 Add Images to Your Website 0 https://chinese.freecodecamp.org/guide/certificates/add-images-to-your-website 添加图片到您的网站

Description

您可以使用img元素将图像添加到网站,并使用src属性指向特定图像的URL。这方面的一个例子是 <img src="https://www.your-image-source.com/your-image.jpg">请注意, img元素是自动关闭的。所有img元素都必须具有alt属性。 alt属性中的文本用于屏幕阅读器以提高可访问性,并在图像无法加载时显示。注意:如果图像纯粹是装饰性的,则使用空的alt属性是最佳做法。理想情况下,除非需要,否则alt属性不应包含特殊字符。让我们在上面的img示例中添加一个alt属性: <img src="https://www.your-image-source.com/your-image.jpg" alt="Author standing on a beach with two thumbs up.">

Instructions

让我们尝试将图像添加到我们的网站:在h2元素之前插入img标记。现在设置src属性使其指向此URL https://bit.ly/fcc-relaxing-cat https://bit.ly/fcc-relaxing-cat最后不要忘记为您的图像添加alt文字。

Tests

tests:
  - text: 您的页面应该有一个图像元素。
    testString: 'assert($("img").length > 0, "Your page should have an image element.");'
  - text: 您的图像应具有指向小猫图像的<code>src</code>属性。
    testString: 'assert(new RegExp("\/\/bit.ly\/fcc-relaxing-cat|\/\/s3.amazonaws.com\/freecodecamp\/relaxing-cat.jpg", "gi").test($("img").attr("src")), "Your image should have a <code>src</code> attribute that points to the kitten image.");'
  - text: 您的图片元素<strong>必须</strong>具有<code>alt</code>属性。
    testString: 'assert(code.match(/alt\s*?=\s*?(\"|\").*(\"|\")/), "Your image element <strong>must</strong> have an <code>alt</code> attribute.");'

Challenge Seed

<h2>CatPhotoApp</h2>
<main>


  <p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
  <p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
</main>

Solution

// solution required