我应该如何链接来自主域的子域的CSS文件? [英] How should I link a CSS file for the subdomain from the main domain?

查看:133
本文介绍了我应该如何链接来自主域的子域的CSS文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可能在这里错误地使用了子域,而不是使用子目录,但我想从我的主域(joeisaacson.com)将相同的CSS导入到我的子域(hire.joeisaacson.com)中。

I may be using subdomains incorrectly here instead of using sub directories, but I want to import the same CSS into my subdomain (hire.joeisaacson.com) from my main domain (joeisaacson.com)

当前文件结构在

The current file structure is below

public_html (where joeisaacson.com points to)
-index.html
-css
--style.css
-hire (where hire.joeisaacson.com points to)
--index.html

我想从hire文件夹访问style.css,而不是创建副本并且必须更新两者。

I want to access style.css from the "hire" folder instead of creating a duplicate and having to updated both.

使用hire文件夹中的../css/style.css不起作用,因为它在hire.joeisaacson.com而不是joeisaacson.com内搜索

using ../css/style.css from the "hire" folder doesn't work, because it searches within hire.joeisaacson.com and not joeisaacson.com

推荐答案

如果您有相同源代码将用于不同嵌套级别的情况(如/index.htm和/ hire / index .htm或您可能需要考虑的其他网域

When you have a case that the same source code will be used at different nesting levels (like /index.htm and /hire/index.htm or different domains you might want to consider the HTML BASE tag.

<base href="http://joeisaacson.com">
<link rel="stylesheet" href="/css/style.css" type="text/css">

这将从取得CSS http://joeisaacson.com/css /style.css ,只要您意识到它会为所有外部资源(图像,css,js等)执行此操作即可。

This will fetch the CSS from http://joeisaacson.com/css/style.css regardless of where the HTML page is served as long as you realise it will do this for all external resources (images, css, js, etc).

只要确保 BASE 标签位于 HEAD 内部并位于任何链接内容之前。您也不要在HTML中关闭这个标签(所以不要< / base> < base /> 预计)

Just be sure BASE tag is inside HEAD and comes before any linked content. You also do not close this tag in HTML (so no </base> or <base /> is expected)

这篇关于我应该如何链接来自主域的子域的CSS文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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