Linking to External Stylesheets with HTTP:// or local path
What are t开发者_JAVA百科he pros and cons of each? Is there a difference?
CSS Stylesheets in HTML.
I assume you're asking which of these you should use:
<link rel="stylesheet" type="text/css" href="/file.css" />
<link rel="stylesheet" type="text/css" href="http://example.com/file.css" />
The difference between the two is that the former is called a relative path and the latter is an absolute path.
If the HTML page in question is http://example.com/page.html
, then there effectively is no difference. However, if the page is https://example.com/page.html
(SSL secured), you'll find that there is now a very important difference. On a secured page, many browsers will not load content which is not also served securely. If you've linked your CSS file with an absolute path, it would not be served securely and therefore your stylesheet might not get loaded.
Unless you have a very specific reason to link your CSS absolutely, you want to use a relative path.
when use http://... (absolute path) you'll need to change it when you move your page to new domain (if you dont generate it dynamically with PHP )
using relative path is the best way imho
using local path is not possible as CSS files are requested by hosts/uests browser, not on server
It's nice to get started with inline and embedded style=""
or putting some style defs in the header, but once a project is more than two pages this just because more work in the end.
精彩评论