freeCodeCamp/guide/chinese/html/attributes/img-src-attribute/index.md

1.2 KiB

title localeTitle
Img Src Attribute Img Src属性

Img Src属性

<img src>属性指的是要显示的图像的来源。没有src属性, img标签不会显示图像。但是,如果将源设置为图像的位置,则可以显示任何图像。

freeCodeCamp徽标的图片位于https://avatars0.githubusercontent.com/u/9892522?v=4&s=400

您可以使用src属性将其设置为图像。


<html> 
  <head> 
    <title>Img Src Attribute Example</title> 
  </head> 
  <body> 
    <img src="https://avatars0.githubusercontent.com/u/9892522?v=4&s=400"> 
  </body> 
 </html> 

上面的代码显示如下:

freeCodeCamp头像

所有浏览器都支持src属性。

您还可以将本地托管的文件作为图像。

例如,只要'images'文件夹与index.html文件位于同一位置,如果你有一个名为images的文件夹里面有freeCodeCamp.jpeg ,那么<img src="images/freeCodeCamp.jpeg>就可以了。 。

../files/index.html

..files/images/freeCodeCamp.jpeg

更多信息: