【问题标题】:src, href and import is not workingsrc、href 和导入不起作用
【发布时间】:2013-04-12 14:51:01
【问题描述】:

一个。 src - 当我使用“img src”时,图像没有在 Firefox 中加载。在 chrome 和 IE 中加载。

b. href - 当我尝试从外部添加 css 文件时它不起作用。

mystyle.css

h1, h2, h3 {
color: #36C;
font-weight: normal;
letter-spacing: .4em;
margin-bottom: 1em;
text-transform: lowercase;
}

css.htm

<head>
<link type="text/css" href="C:\Divakar_Repository\html_learning\mystyle. css">
</head>
<h1>CHEcking the css style</h1>

但它将输出显示为黑色的“检查 css 样式”。 实际上输出应该是蓝色的“检查css样式”。

c。导入 - 它不起作用。

import.htm

<head>
@import "C:\Divakar_Repository\html_learning\mystyle.c ss";
</head>
<h1> CHEking the css file </h1>

但它返回的输出如下。

@import "C:\Divakar_Repository\html_learning\mystyle.c ss"; 检查css文件

任何帮助将不胜感激。

谢谢……

【问题讨论】:

  • "ystyle.c ss";"为什么c和ss之间有空格?
  • 中也有空格。
  • 我刚刚从记事本++中复制了代码。不知道为什么在这里显示这样。在我的文档中找不到空间。

标签: html css web


【解决方案1】:

您必须在使用 CSS 的地方使用 @import,而不仅仅是在 head 元素中,并且格式正确。

你可以在style元素或你的css文件中@import css文件:

@import url(mystye.css);

您的语法更多是 Sass/更少相关,而不是 CSS。

还要注意文件名。

另外,在打开h1 标签之前,您应该先打开body 标签

【讨论】:

    【解决方案2】:

    引用样式表时使用相对路径:

    &lt;link type="text/css" href="mystyle.css"&gt;

    链接是相对于您链接的文档在目录结构中的位置,因此请确保路​​径正确。还要确保奇怪的地方没有空格。

    @import 函数只能在样式表中使用,因此要么在 .css 文件中使用它,要么将其包装在 &lt;style&gt; 标签中:

    <style>
    @import url(mystyle.css);
    </style>
    

    最后一点,在&lt;head&gt; 部分,它需要有一个&lt;title&gt; 元素。你不能跳过这个。

    【讨论】:

      【解决方案3】:

      谢谢大家。

      如果我在样式元素之间有@import,它会起作用。

      在我添加属性 rel="stylesheet" 后,链接元素起作用。

      但我有一些问题。

      反斜杠除了 IE 不能用吗?因为如果我指向具有 c:\ 之类路径的文件,它在 firefox 和 chrome 中不起作用

      【讨论】:

        猜你喜欢
        • 2017-03-08
        • 2016-06-19
        • 2020-09-09
        • 1970-01-01
        • 2015-01-14
        • 2018-07-04
        • 2012-10-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多