Html 我可以在网站提供的页面中包含来自本地驱动器的 CSS 样式表吗
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5495907/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can I include a CSS StyleSheet from a local drive, in a page served from a web site
提问by Bruce
My goal is to have a page, served by a web site, containing a to a stylesheet, that is available not on the web site, and not on a different web site, but on a local drive.
我的目标是拥有一个由网站提供的页面,其中包含一个样式表,该页面在该网站上不可用,也不在其他网站上可用,但在本地驱动器上可用。
Something like;
就像是;
<!DOCTYPE html>
<html>
<head>
<link href="/styles/something.css" rel="stylesheet" />
<link href="file:///C:/custom.css" rel="stylesheet" />
</head>
My initial research shows that browsers don't seem to support this, but I'm willing to be proved wrong, or discover some sneaky way of doing it. (I tried the above, that doesn't work.)
我最初的研究表明浏览器似乎不支持这一点,但我愿意被证明是错误的,或者发现一些偷偷摸摸的方法。(我试过上面的,那不起作用。)
[I know, I know, you wanna know "why". This is for the site designer - it would allow him to edit the css locally while designing and see the effect on the "semi-live" site. ie the round-trip for edits would be very fast, and I wouldn't need to give him access to the actual site. By extension, for teaching purposes, it would allow multiple people to simultaneously practice their CSS skills locally]
[我知道,我知道,你想知道“为什么”。这是给网站设计师的 - 这将允许他在设计时在本地编辑 css 并查看“半实时”网站上的效果。即,编辑的往返行程会非常快,而且我不需要让他访问实际站点。通过扩展,出于教学目的,它将允许多人同时在本地练习他们的 CSS 技能]
Obviously any edits made to the local file will only be visible on that local computer - that's the whole idea. If you had 10 students each would see the same site with a different css file.
显然,对本地文件所做的任何编辑都只能在该本地计算机上可见 - 这就是整个想法。如果您有 10 名学生,每个学生都会看到同一个站点,但具有不同的 css 文件。
采纳答案by JohnP
Well, if you can setup Apache on your machine, this is easily done.
好吧,如果您可以在您的机器上设置 Apache,这很容易完成。
This is assuming the question is this
这是假设问题是这样的
I want to be able to have a site in a central location (live) and allow users accessing that site to be able to make changes to the site by editing a local file. These changes will onlybe visible to the person making the change and the rest will just see whatever CSS is on their local copy.
我希望能够在中心位置(实时)拥有一个站点,并允许访问该站点的用户能够通过编辑本地文件对站点进行更改。这些更改只会对做出更改的人可见,其余的只会看到他们本地副本上的任何 CSS。
So this means that you have to serve a local file from multiple computers and each person viewing the site may have a different looking copy. If I'm right, read on.
因此,这意味着您必须从多台计算机提供本地文件,并且每个查看该站点的人可能拥有不同外观的副本。如果我是对的,请继续阅读。
Setup a local environment (maybe with WAMP?) on all the machines you want to be able to allow local edits. The important thing is that everyone must have the same hostname defined (either localhost, or something else - don't forget to add it to your hosts
file). Place the CSS file inside your webroot and add a link to your live site pointing to that link.
在您希望能够允许本地编辑的所有机器上设置本地环境(也许使用 WAMP?)。重要的是每个人都必须定义相同的主机名(本地主机或其他名称 - 不要忘记将其添加到您的hosts
文件中)。将 CSS 文件放在您的 webroot 中,并添加一个指向您的实时站点的链接,指向该链接。
<link href="http://www.mysite.com/base.css" rel="stylesheet" />
<link href="http://localhost/custom.css" rel="stylesheet" />
And voila! Local editing.
瞧!本地编辑。
Caveats
注意事项
Everyone needs to have their files placed in the same local URL otherwise it won't work
You need to setup a local environment (very easy)
每个人都需要将他们的文件放在同一个本地 URL 中,否则它将无法工作
您需要设置本地环境(非常简单)
回答by Efra
Just press Shift+F7 on Firefox (or Tools->Web Developer->Style Editor). In the window that opens you can import an entire file or you can also edit the styles loaded.
只需在 Firefox 上按 Shift+F7(或 Tools->Web Developer->Style Editor)。在打开的窗口中,您可以导入整个文件,也可以编辑加载的样式。
回答by fabrik
Obviously, you can't. But why not try it and find out if this didn't work?
显然,你不能。但是为什么不尝试一下,看看这是否行不通呢?
If the purpose of your needs is only for testing, i'll advice you install web developer extensionwhere you can add local CSS to a website - for testing only.
如果您的需求仅用于测试,我建议您安装Web 开发人员扩展,您可以在其中将本地 CSS 添加到网站 - 仅用于测试。
回答by amosrivera
Just for the purpose of answering the question, yes he could serve a CSS file to your website, but he would have to have a server installed on his computer and a public access to his server IP.
只是为了回答这个问题,是的,他可以向您的网站提供 CSS 文件,但他必须在他的计算机上安装一个服务器,并公开访问他的服务器 IP。
Then in the href
of the stylesheet you would write something like <link href="190.181.169.118/styles.css" rel="stylesheet" />
.
然后在href
样式表的 中,您将编写类似<link href="190.181.169.118/styles.css" rel="stylesheet" />
.
Of course this is not the recommended solution, i would advise you to use some sort of browser extension / plug in for that.
当然,这不是推荐的解决方案,我建议您为此使用某种浏览器扩展/插件。
回答by Sangeet Menon
Yes you can!! Just need Firefoxas a browser and you also need add on WEB DEVELOPERinstalled on it...
是的你可以!!只需要Firefox作为浏览器,您还需要添加安装在其上的WEB DEVELOPER...
It allows to disable the inline CSS and add user CSS...
它允许禁用内联 CSS 并添加用户 CSS...
Download the add on WEBDEVELOPER
下载WEBDEVELOPER上的插件
Once installed...after you restart firefox you will get a menu on the firefox window in which click on the CSSmenu which will allow you options to disable and add user CSS
安装后...重新启动 firefox 后,您将在 firefox 窗口中看到一个菜单,在该菜单中单击CSS菜单,您可以选择禁用和添加用户 CSS
You will have to disable the inline CSS to see the CSS applied by the user to full effect
您必须禁用内联 CSS 才能查看用户应用的 CSS 以达到完全效果