Netbeans中的HTML图像未在浏览器中显示

ffscu2ro  于 2022-11-10  发布在  其他
关注(0)|答案(5)|浏览(207)

* {

    margin: 0px;
    padding: 0px;
}
.container{
    background-color:#999999;
    width:100%;
    margin-top: 10px;
}
.wrapper{
    margin-top: 50px;
    width:900px;
    margin:auto;
}
.dark{
    background-color: #FF4500;
    height: 40px;
    margin-top: 40px;
}

# top_div{

    line-height: 40px;
}

# div2{

    height: 220px;
}

上面提到的是我的css文件

<html xmlns="https://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>My static web Page</title>
        <link type="text/css" rel="stylesheet" href="css1.css"/>
    </head> 
    <body>

        <div class="container">
            <div class="wrapper">
                <div>
                    <img src="img.png"  width="400" height="400" ></img>
                </div>
            </div>
        </div>

        <div class="dark">
            <div class="wrapper" id="top_div">
                <h2>The Origin</h2>
            </div>
        </div>

        <div class="container">
            <div class="wrapper" id="top_div">
This is my styled paragraph
            </div>
        </div> 

    </body>
</html>

它只显示图像图标,浏览器上看不到图像。我已经将图像粘贴到项目目录下的一个文件夹中。添加图像的正确方法是什么,请解释。

u5i3ibmn

u5i3ibmn1#

请确保您的路径正确(例如:相对文件./您的文件. png

<div>
     <img src="./img.png"  width="400" height="400" ></img>>
</div>
mmvthczy

mmvthczy2#

<div>
<img src="./foldername/imagename.png" width="400" height="400" />
</div>
odopli94

odopli943#

下面的代码行意味着,您的图像文件img.png驻留在您保存html文件的同一文件夹中。

<img src="img.png"  width="400" height="400" ></img>

如果它保存在其他文件夹中,则可以提供类似于以下内容的相关路径

src="../foldername/img.png"
c8ib6hqw

c8ib6hqw4#

我尝试从%temp%命令中清除临时文件,并且成功了!

txu3uszq

txu3uszq5#

如果您有两个不同的文件夹来存放HTML文件和图像,请按如下所示更新img标记:
<img src="../images/img.png" width="400" height="400" ></img>
其中,“images”是放置图像的文件夹的名称。

相关问题