0

I have many html files, all named index.html but being in different subdirectories. These files are created by a software. After these files being created, I want to add a Stylesheet to all of them!

If i use SEARCH:"<head>" and REPLACE:"<head><link rel='stylesheet' href='/style.css'>" it wouldnt work because the files would need relative paths.

Any idea how I could achieve my goal? While Iframes are oldschool they do not use the CSS of the main page i assume.

Other ideas?

4

2 回答 2

3

您可以使用 CSS 文件的绝对路径。那么它们在不同的路径中并不重要:

<link href="/styles/site.css" ...

现在每个文件都将查找styles根目录中的 -folder,以及该文件site.css夹中的文件

于 2013-05-15T07:48:07.720 回答
0

只需使用您提到的绝对路径即可。

并且不要直接在

file://D:/path/to/your/file/index.html

因为根路径 '/' 表示 D:/

您应该设置一个 http 服务器来托管您的页面并通过访问来打开它们

http://localhost/url/to/your/file/index.html

根路径 '/' 表示

http://localhost/

或者将它们上传到服务器。这样,您的 css 的绝对路径将正常工作。

忘记相对路径。

于 2013-05-15T07:59:01.360 回答