使用HTTP://或本地路径链接到外部样式表 [英] Linking to External Stylesheets with HTTP:// or local path

查看:297
本文介绍了使用HTTP://或本地路径链接到外部样式表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

各自的优缺点是什么?有区别吗?

What are the pros and cons of each? Is there a difference?

HTML中的CSS样式表.

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.

如果所讨论的HTML页面是http://example.com/page.html,则实际上没有任何区别.但是,如果页面是https://example.com/page.html(受SSL保护),则您会发现现在有一个非常重要的区别.在受保护的页面上,许多浏览器将不会加载不能安全提供的内容.如果您已经用绝对路径链接了CSS文件,则将无法安全地提供该文件,因此可能不会加载样式表.

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.

除非有绝对特定的理由绝对链接CSS,否则您要使用相对路径.

Unless you have a very specific reason to link your CSS absolutely, you want to use a relative path.

这篇关于使用HTTP://或本地路径链接到外部样式表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆