繁体   English   中英

CSS 文件未在 HTML 文件中加载。 我正在使用 Netbeans IDE

[英]CSS file is not getting loaded in HTML file. I am using Netbeans IDE

I am new to HTML and CSS and trying to load my CSS file in my HTML code with the help of reading multiple answers on Stack Overflow, but sadly not able to run this code as CSS file is not loading in my HTML code. 请,如果有人可以提供帮助或我的代码中有任何错误。 我的 HTML 代码:

<html>
    <head>
        <link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet"/>
        <title>My favourite character</title>
        
        <link href="style.css" type="text/css" rel="stylesheet"/>
     
    </head>
    <body>
        <h1>Batman</h1>
        <h4>A silent guardian, A watchful protector, A dark knight</h4>
        <p>batman is the best man. He is <b>kind</b>. <br>He helps people like my neigbhours. 
            Batman is the alias of Bruce Wayne, a wealthy American playboy, philanthropist, and industrialist who resides in Gotham City. </p>
        <br><a href="https://en.wikipedia.org/wiki/Batman" target = "_blank"> Click here</a> to know more about batman
       
        <h2>Unordered list</h2>
        <ul type = "square">
            <li>this is line 1</li>
            <li>this is line 2</li>
            <li>this is line 3</li>
            <li>this is line 4</li>
        </ul>
        <h2>Ordered list</h2>
        <ol type = "a">
            <li>this is line 1</li>
            <li>this is line 2</li>
            <li>this is line 3</li>
            <li>this is line 4</li>
        </ol>
    </body>
</html>

我的CSS文件代号为style.css:

body{ max-width:1000px;
    margin: auto;
    font-family:Robot;
    font-size:32px;
    color: yellow;
    background-color: black;
}
h4{
    font : italic small-caps bolder 28px arial, sans-serif;
}

它给出的错误:

显示加载资源失败

1

我的 HTML 和 CSS 文件的文件夹结构:

My first project: Site Root                     
    Site Root: index.html 
               style.css
               test.html

index.html 和 style.css 文件在同一个文件夹(站点根目录)中,或者如果不是,请告诉我,因为我猜站点根目录只是一个文件夹。 我的文件夹结构截图: 2

在此处输入图像描述

这可能是一个不好的参考。 检查您是否有任何拼写错误或您的文件与您的根目录位于同一文件夹中。

这可能是由于您的代码结构。 根据您在代码中的内容,您应该将 css 文件与使用它的 html 文件放在相同的文件夹中。 如果 css 文件位于其他位置,则必须指向文件所在的位置。 例如:如果文件位于名为 css 的文件夹中,则您的参考应该是

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM