2.8 KiB
2.8 KiB
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