Home > Article > Web Front-end > How Do I Access Files from a Higher Directory in HTML?
Accessing Files from a Higher Directory in HTML
When organizing website assets, it's common to separate files like style sheets and images into different directories for easier management. However, when you need to reference these files from within the HTML, you may encounter issues if the paths are not specified correctly.
Problem:
Consider a scenario where style sheets are stored in "{root}/styles" and images are stored in "{root}/images." How can you reference images from within the style sheets, ensuring the correct path is used?
Solution:
To resolve this issue, use the parent directory indicator ".." in the path:
background-image: url('../images/bg.png');
This modification instructs the browser to move one level up in the directory structure and then locate the "images" directory. By using ".." (two periods), you are accessing the parent directory of the current directory ("styles"). This allows you to refer to files in a higher-level directory, even when the actual HTML file is located in a different subdirectory.
The above is the detailed content of How Do I Access Files from a Higher Directory in HTML?. For more information, please follow other related articles on the PHP Chinese website!