Talking about the technique of Web design: The perplexity of getting out of the path

Source: Internet
Author: User
Tags code tag join joins relative root directory
Skills | design | Web Page Design If you are just beginning to contact web design, is this often the problem? Good web pages on their own machine can be normal browsing, and the page uploaded to the server will always appear to see no pictures, CSS stylesheet failure and other errors. This is mostly because you use the wrong path and use an absolute path where the relative path should be used, causing the browser to not open the specified file in the specified location. Let's talk about the difference between the relative path and the absolute path that make the beginner headache. What is an absolute path: as we all know, when we use the computer to find the necessary files must know the location of the file, and the way to represent the location of the file is the path, such as just see the path: c:/website/img/ Photo.jpg We know the photo.jpg file is in an IMG subdirectory under the website directory in C disk. A path similar to the complete description file location is an absolute path. We do not need to know any other information to determine the location of the file according to the absolute path. In a Web site, it is also an absolute path to photo.jpg to determine the location of a file. In addition, in the application of the website, we usually use "/" to represent the root directory,/img/photo.jpg means the photo.jpg file is in the IMG directory on the root directory of the website. But this is risky for beginners, knowing that the root directory is not the root of your site, but the root of the server where your Web site resides, so there will be an error when the site's root directory is not the same as the server root. What is a relative path: Let's first analyze why the picture does not display correctly. For example, there is now a page index.htm that joins a picture photo.jpg in this page. Their absolute path is as follows:

c:/website/index.htm c:/website/img/photo.jpg

If you use an absolute path c:/website/img/photo.jpg, then everything is fine on your own computer, because you can do it in the specified location, c:/website/img/ Photo.jpg found on the photo.jpg file, but when you upload the page to the site is likely to go wrong, because your site may be in the server C, may be in D, or in the AA directory, more likely in the BB directory, in short, there is no reason to have c:/website/ Img/photo.jpg such a path. So, what path do you want to use to locate the Photo.jpg file in the index.htm file? Yes, it should be a relative path, the so-called relative path, as the name suggests is their relative and target position. Photo.jpg that are joined in index.htm in the previous example can use Img/photo.jpg to locate files, so no matter where they are placed, they do not go wrong as long as their relative relationship does not change. In addition we use ".. /"to represent the previous level of the directory,".. /.. /"represents the directory on the ancestor, and so on. (A friend who has studied DOS may be easier to understand) look at a few more examples, and note that all of the examples are index.htm with a picture photo.jpg in the join file. Cases:

c:/website/web/index.htm c:/website/img/photo.jpg

In this case, how should the photo.jpg of the index.htm join be represented? Error writing: Img/photo.jpg This writing is not correct, in this case, for the index.htm file img/photo.jpg represents the absolute path is: c:/website/web/img/photo.jpg, obviously does not meet the requirements. Use the correct wording: /img/photo.jpg the relative path to locate the file example:

c:/website/web/xz/index.htm c:/website/img/images/photo.jpg

In this case, how should the photo.jpg of the index.htm join be represented? Wrong wording:. /img/images/photo.jpg This type of writing is not correct, in this case for the index.htm file. The absolute path represented by/img/images/photo.jpg is: c:/website/web/img/images/photo.jpg. Correct writing: You can use ... /.. /img/images/photo.jpg the relative path to locate the file example:

c:/website/web/xz/index.htm c:/website/web/img/photo.jpg

In this case, how should the photo.jpg of the index.htm join be represented? Wrong wording:. /.. /img/photo.jpg This type of writing is not correct, in this case for the index.htm file. /.. The absolute path represented by/img/photo.jpg is: c:/website/img/photo.jpg. Correct writing: You can use ... /img/photo.jpg the relative path to locate the file summary: Through the above examples can be found, in the absolute path to the relative path, two files absolute path of the same part can be ignored, do not consider. Just think about what they are different. How to modify the path to a style sheet: Open the HTM file using a text editor, view the source code, at the beginning of the source code ... Tags found in the middle . "Href=" After the content is the path of CSS, we can based on the above knowledge of the relative path conversion. Cases:

c:/website/web/xz/index.htm c:/website/css/test.css

In this example, index.htm joins the Test.css file, you can use the. /.. /css/test.css the relative path to locate the file, the complete code tag is: error writing Examples: ... /.. /.. /css/test.css This type of writing is not correct, in this case for the index.htm file. /.. /.. The absolute path represented by/CSS/TEST.CSS is: C:/css/test.css Finally, to avoid a path error when making a Web page, we can use the Dreamweaver site management function to manage the site. As long as you use the menu command site-new site to create new sites and define the site directory, it will automatically turn the absolute path into a relative path, and when you move files in the site, the connection path associated with these files will automatically change, it is very convenient.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.