在HTML页面中包含外部CSS/JS文件 [英] Include external css/js file into html page
问题描述
我正在尝试手动链接我的CSS和Javascript文件到HTML脚本,但是我从来没有真正使用来自其他文件夹/目录中的文件来完成此操作.这是我到目前为止的内容:
I'm trying to link manually my CSS and Javascript files to my HTML scripts, but I've never really done it with files from a different folder/directory. This is what I have so far:
<link rel="stylesheet" type="text/css" href="/Desktop/Script/CSS/tempeststyle.css"/>
<link rel=script" type="text/javascript" href="/Desktop/Script/Javascript/tempestscript.js"/>
我从一些资料中获悉,您不必从头开始在C:/Users
或任何情况下(对于不同的系统),但是我不确定这些链接是否可以以它们的方式接受是(即,它们从"/Desktop"开始).这些文件位于桌面上同一文件夹内的单独文件夹中.那么,如何最好的方式包含它们?谢谢.
I've read from a few sources that you don't have to start all the way at C:/Users
or whatever the case may be for different systems, but I'm not sure if these links are acceptable the way they are (i.e., them starting at "/Desktop"). The files are in separate folders within the same folder on the desktop. So how to include them the best way? Thanks.
推荐答案
如果要从本地路径添加脚本,可以使用相对路径:
If you want to add scripts from local path you can use a relative path:
<link rel="stylesheet" type="text/css" href="../CSS/tempeststyle.css"/>
或Web根文件夹中的相对路径:
or relative path from your web root folder:
<link rel="stylesheet" type="text/css" href="/styles/CSS/tempeststyle.css"/>
或文件系统绝对路径:
<link rel="stylesheet" type="text/css" href="file:///C:/Path/To/Scripts/styles/CSS/tempeststyle.css"/>
如果您使用来自Web服务器的绝对路径,那就更好了:
It is rather better if you use an absolute path from your web server:
<link rel="stylesheet" type="text/css" href="http://www.example.com/styles/CSS/tempeststyle.css"/>
这篇关于在HTML页面中包含外部CSS/JS文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!