简体   繁体   English

为什么我的图像没有显示在html中?

[英]why isn't my image showing up in html?

I'm trying to add an image to my html page. 我正在尝试将图像添加到html页面。 It should be fairly simple. 它应该相当简单。 However, the image refuses to show up. 但是,该图像拒绝显示。

here is the html 这是HTML

        <img src="/images/eiffel.jpg" alt="eiffel">

In safari all i get is a question mark. 在野生动物园,我所得到的只是一个问号。 In chrome it is just an icon with the alt. 在chrome中,它只是带有alt的图标。 That is the directory where the image is and my IDE autocompletes the photo name so I know i'm in the right place. 那是图像所在的目录,我的IDE会自动完成照片名称,因此我知道我来对地方了。 So why isn't it showing up?? 那为什么不显示呢?

如果您的图片文件夹位于网页上方的文件夹中,则在其后添加2个点将起作用。

<img src="../images/eiffel.jpg" alt="eiffel">

What is the url of the page where the image should show? 图片应显示的页面网址是什么? Remember that by using the slash you are calling base url. 请记住,通过使用斜杠来调用基本URL。 Maybe you could use full url or remove the slash at the beginning. 也许您可以使用完整的URL或在开始时删除斜杠。

Also you can try previous answer of adding a "." 您也可以尝试添加“”的先前答案。 before the slash. 在斜线之前。

Hope it helps. 希望能帮助到你。

The leading slash in your src URL makes the path relative to the root of your website, it is an absolute path. src URL中的斜杠使路径相对于网站的根,这是绝对路径。

Without the slash, this path becomes relative to the HTML document's location. 没有斜杠,此路径将对于HTML文档的位置。 If this document is not at the website root (eg: www.example.com/index.html ) then it will not point to the same location as the first example. 如果此文档不在网站根目录下(例如: www.example.com/index.html ),则它将不会指向与第一个示例相同的位置。

For example, if your page URL is www.example.com/mysite/content/index.html then the two variations will be interpreted as follows: 例如,如果您的页面URL是www.example.com/mysite/content/index.html则两种变体将被解释为:

src="images/eiffel.jpg"       -->  www.example.com/mysite/content/images/eiffel.jpg
src="/images/eiffel.jpg"      -->  www.example.com/images/eiffel.jpg

Using dots as mentioned by other answers would produce subtly different results: 使用其他答案提到的点会产生微妙的不同结果:

src="./images/eiffel.jpg"     -->  www.example.com/mysite/content/images/eiffel.jpg
src="../images/eiffel.jpg"    -->  www.example.com/mysite/images/eiffel.jpg
src="../../images/eiffel.jpg" -->  www.example.com/images/eiffel.jpg

Check the below Steps which will help you on image rendering issues. 检查以下步骤,这将有助于您解决图像渲染问题。

  1. Right Click and Choose Inspect Element 右键单击并选择Inspect Element
  2. Click Network Tab Search for your Filename 单击网络选项卡搜索您的文件名
  3. Double click your image file name. 双击您的图像文件名。
  4. It will open in your Safari browser. 它将在您的Safari浏览器中打开。
  5. Verify your image absolute path. 验证图像的绝对路径。

You can follow the same trick for every browser. 您可以为每个浏览器遵循相同的技巧。

Try this because in my code i added the code like this and it worked. 尝试执行此操作,因为在我的代码中我添加了这样的代码并且它起作用了。 My code is img src="C:\\Users\\User\\Desktop\\HTML Programs\\Proj\\bgimg4.jpg" 我的代码是img src =“ C:\\ Users \\ User \\ Desktop \\ HTML Programs \\ Proj \\ bgimg4.jpg”

You can use img src="\images\eiffel.jpg" alt="eiffel" use Markdown in here.
Please keep the above one in angular braces.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM