Determining the HTML root in a folder in the root folder of a site

I want to have a new folder containing a set of new html files. All images inside it are in the format src="image.png" , and image.png is in the root folder. But when you put the HTML file in a new folder, it cannot find the image. You must have it in the format src="../root folder/folder/image.png" for it to work. That would mean a lot of insertion. I tried putting image.png inside the folder, but without changes.

+6
source share
2 answers

Use the <base> element . It allows you to specify a URL for all relative URLs on the page.

for instance

 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>This is an example for the <base> element</title> <base href="http://www.example.com/news/index.html"> </head> <body> <p>Visit the <a href="archives.html">archives</a>.</p> </body> </html> 

The link in this example will be a link to " http://www.example.com/news/archives.html .

For you, the base URL can be as simple as <base href="http://www.yoursite.com/"> . This would make images defined as src="image.png" , as "http://www.yoursite.com/image.png"

See also https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base

+14
source

You need to set the base tag. If you add a tag to your <head> page as follows:

<base href="http://yoursite.tld/folder/">

it should display images and sources in relation to this base path.

+3
source

Source: https://habr.com/ru/post/948346/


All Articles