我是编码新手,用 html 和 css 构建了一个简单的网站。我试图将本地计算机中的图片添加到该站点。图片文件与我的 html 和 css 文件放在同一个文件夹中。但是,当我的页面加载时,图片没有显示。为什么会这样?这是我的 html 代码。非常感谢您提出可能出错的建议。
<head>
<link rel="stylesheet" type="text/css" href="myStyle.css"/>
<title>My Professional Site</title>
</head>
<body>
<h1>Jon Doe</h1>
<h2>Learning to code.</h2>
<img src = "IMG_0523.jpg" alt="Sorry No Picute Available" style="width:300px;height:300px;">
<p>"Trying to learn to code." </p>
<footer>Contact Info: jd@mail.com 555-5555</footer>
</body>
</html>
最佳答案
目录结构1
根
- 图像
- IMG_0523.jpg
- index.html
使用 images/
访问它
<img src = "images/IMG_0523.jpg" alt="Sorry No Picute Available" style="width:300px;height:300px;">
目录结构2
根
- IMG_0523.jpg
- index.html
然后直接访问
<img src = "IMG_0523.jpg" alt="Sorry No Picute Available" style="width:300px;height:300px;">
目录结构3
根
- 图像
- IMG_0523.jpg
- 页面
- index.html
然后用../images/
访问它
<img src = "../images/IMG_0523.jpg" alt="Sorry No Picute Available" style="width:300px;height:300px;">
改用相对路径
关于html - 无法从我的本地计算机获取图片以显示在我的网站上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37312661/