首页 > 解决方案 > css 文件不能与 html 文件一起使用(即使 css 文件已与 html 文件链接)?

问题描述

我是 css 的新手,并试图编写一个 css 文件以在 html 文件中使用,这是我的想法。

首先,我写了一个这样的html文件

<!DOCTYPE html>
<html>
<!-- phan dau -->
<head>
    <title>
        ok we will make it
    </title>
</head>
<!-- phan than  -->
<body>
<div>
    <h1 id="first-heading">css selector</h1>
    <h1 class="css selector">css selector</h1>
    <h1 class="css selector">css selector</h1>
</div> 
</body>

然后,我写了一个这样的css文件

#first-heading {
    color: red;
}

我的想法是,使用 css 文件,首先使用第一个 css 选择器使其变为红色。但它并没有像我希望的那样是红色的。两个文件在同一个文件夹中。

你能给我一些关于这个问题的想法吗?非常感谢您的宝贵时间。

标签: htmlcss

解决方案


你给你的内部css写如下

<head>
    <style>

      #first-heading {
       color: red;
      }

   </style>
</head>

您是外部 css 正确提供两个文件的链接。但是您调用的外部 css 会提供您的链接

 <link rel="stylesheet" href="./style.css">

谢谢


推荐阅读