你可以将CSS样式表链接到另一个文件夹中的另一个样式表

时间:2015-03-10 22:10:45

标签: html css

我的项目层次结构如下:

main/
    style1.css
    stylesheet/
        style2.css

我想在style2.css中添加样式表style1.css,但@import不起作用。

2 个答案:

答案 0 :(得分:0)

只需在页眉中包含两个样式表即可。您可以导入多少样式表没有限制,但如果重新定义样式,则最接近内容的定义将优先。

答案 1 :(得分:0)

假设以下文件夹结构:

enter image description here



index.html 中,您可以链接main/styles.css

<link rel="stylesheet" href="main/styles.css">


styles.css (位于文件夹main)中,导入stylesheet/stylesToImport.css

@import url('stylesheet/stylesToImport.css');

请注意,as stated by the specification,以下两种语法是等效的:

@import url('stylesheet/stylesToImport.css');
@import 'stylesheet/stylesToImport.css';