外部样式表,指定绝对或相对路径 [英] external style sheets, specifying absolute or relative paths

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

问题描述

用于包含外部样式表的链接标记的href部分对我很困惑,特别是因为大多数人不使用完整的URL。



例如,

 < link rel =stylesheethref =mystyles.csstype =text / cssmedia =屏幕> 

如果我想把我的样式表放在wwwroot的子目录下,参考它通过:



a)href =/ someDir / mystyles.css



< ./someDir/mystyles.css



c)href =someDir / mystyles.css



解决方案

这是基本的相对URL语法。



假设这出现在 http://example.com/foo/bar/index.html

code>


href =/ someDir / mystyles.css


http://example.com/someDir/mystyles.css


href =./ someDir / mystyles.css


http://example.com/foo/bar/someDir/mystyles.css


href =someDir / mystyles.css


http://example.com/foo/bar/someDir/mystyles.css



您没有提及 href =../ someDir / mystyles.css



这将是: http://example.com/foo/someDir/mystyles.css


the href portion of the the link tag for including external stylesheets is confusing to me, especially since most folks don't use an entire URL.

For example, in

  <link rel="stylesheet" href="mystyles.css" type="text/css" media="screen">

if I wanted to put my stylesheet in a subdirectory off wwwroot, what would be the difference in attempting to reference it via:

a) href="/someDir/mystyles.css"

b) href="./someDir/mystyles.css"

c) href="someDir/mystyles.css"

Thanks Much

解决方案

This is basic relative URL syntax. There is nothing CSS specific about this.

Assuming this appears in http://example.com/foo/bar/index.html

href="/someDir/mystyles.css"

http://example.com/someDir/mystyles.css

href="./someDir/mystyles.css"

http://example.com/foo/bar/someDir/mystyles.css

href="someDir/mystyles.css"

http://example.com/foo/bar/someDir/mystyles.css

And you didn't mention href="../someDir/mystyles.css"

Which would be: http://example.com/foo/someDir/mystyles.css

这篇关于外部样式表,指定绝对或相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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