HTML 显示损坏的图像

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18712701/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 13:12:53  来源:igfitidea点击:

HTML showing broken image

htmlimagesrc

提问by compprog254

i have the following html code and when i pull it up in my browsers the image either doesnt show up, or it shows a broken image:

我有以下 html 代码,当我在浏览器中将其拉出时,图像要么不显示,要么显示损坏的图像:

<!DOCTYPE html>
<html>
    <head>
    <title>Lets Play Battleship</title>
    <link rel="stylesheet" href="style.css">
    </head>

    <body>
        <h1>
            Battleship
            <p><img src="battleship-game-board.jpg" width = "120" height = "90"/></p>
        </h1>


        <p><a href="http://www.freeonlinegames.com/game/battleships"> Click Here to Play Battleship</a></p>

    </body>
</html>

回答by Ashwani

To make image work either you use:

要使图像工作,您可以使用:

Absolute path:

绝对路径:

<img src="http://www.domain.com/MyImages/battleship-game-board.jpg"/>

or

或者

Relative path:

相对路径:

<img src="../MyImages/battleship-game-board.jpg"/>

if image exist in same folder the html file exist then you can use:

如果图像存在于同一文件夹中,则 html 文件存在,那么您可以使用:

<img src="battleship-game-board.jpg" width = "120" height = "90"/>

More details here

更多细节在这里

Note: image must exist in given path in all cases.

注意:在所有情况下,图像都必须存在于给定路径中。

回答by Parag Kuhikar

This is due to the following reason.

这是由于以下原因。

1>The battleship-game-board.jpg is not in the same directory of same file.

1> Battleship-game-board.jpg 不在同一文件的同一目录下。

2>battleship-game-board.jpg do not contain valid permission. If you are using linux then you have to specify 755 permission on battleship-game-board.jpg image.

2>battleship-game-board.jpg 不包含有效权限。如果您使用的是 linux,那么您必须在 Battleship-game-board.jpg 图像上指定 755 权限。

You could use

你可以用

    chmod 755 battleship-game-board.jpg

回答by Ring

<img src="battleship-game-board.jpg" width = "120" height = "90"/>. 

What in the src="" should be a path, but not a title of image. It means you should input the path of battleship-game-board.jpg, but not the image name.

src="" 中的内容应该是路径,而不是图像的标题。这意味着您应该输入 Battleship-game-board.jpg 的路径,而不是图像名称。