简体   繁体   中英

Insert image using html

I have an image located in here D:\clone4\java-security-service\src\main\resources\images and I want to add it to my html page, but it doesn't seem to work. I tried many ways like:

<img style="max-width: 170px;" src="./images/piechart.jpg" alt="pie-chart"> 

but I get nothing. My Html file is located inside a java project. I'm open to suggestions.

Try using the full path of your file.

So:

<img src="file://D:/clone4/java-security-service/src/main/resources/images/piechart.jpg">

Use Absolute path, not the Relative one. So give the whole path since both locations of HTML file and image are from different folders. Give src attribute: D:\clone4\...\images But Try using forward slashes instead of backslashes and prepend with file:// , So the link would be like

C:/clone4/.../images/piechart.jpg

Open the image in your web browser. Then copy the path and add it to attribute src of img src location looks like this file:///D:/clone4/.../images/piechart.jpg

src="./images/piechart.jpg"

Try moving the jpg into the same folder where html file located. Then remove the path and put is as just

src="piechart.jpg"

How about you create a new folder.Lets call the folder Project. This Project folder would include your HTML files, CSS, Javascript and it would also contain your images. So there would be 4 other folders in your Project Folder. Put your various code in their respective folders, same applies with the images.

Then if you want to access the images from the Image folder,

 <img src=.../Images/picture.jpg>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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