简体   繁体   English

我在将 CSS 文件链接到 HTML 文件时遇到问题

[英]I am having trouble linking my CSS file to my HTML file

So...as the tile says, I am having a bit of trouble linking my CSS file to my HTML file.所以......正如瓷砖所说,我在将我的 CSS 文件链接到我的 HTML 文件时遇到了一些麻烦。 I link it, but it wont do anything.我链接它,但它不会做任何事情。 Nohing that I do in my file will change or work.我在我的文件中所做的任何事情都不会改变或起作用。

Here is my HTML code:这是我的 HTML 代码:

<!DOCTYPE html>
<html lang=en_US>
    <head>
        <meta charset="UTF-8">
        <meta name="author" content="©Isaac Guillen 2020">
        <meta name="keywords" content="Christian, Discord, Christianity, server">
        <meta http-equiv="refresh" content="30">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="Christian discord server for christians who are looking to spread the word or people who are looking to expand their knowledge on Christianity">
        <link rel="stylesheet" href="./CSS/style.css">
        <title>Scripture Alone Official</title>
    </head>
    <body>
        <div class="Title">
            <h1 class="title-1">Welcome!</h1>
        </div>
        <section id="link-buttons">
            <div class="button">
                <a class="link-1" href="#">Home</a>
                <a class="link-2" href="#">About</a>
                <a class="link-3" href="#">contact</a>
                <a class="link-4" href="#">Join!</a>
            </div>
        </section>
    </body>
</html>

And just in case...this is my CSS file:以防万一……这是我的 CSS 文件:

* {
    margin: 0;
    padding: 0;
}

body {
    background-color: black;
}

What am I doing wrong?我究竟做错了什么?

CSS can be added to HTML documents in 3 ways: CSS 可以通过 3 种方式添加到 HTML 文档中:

Inline - by using the style attribute inside HTML elements Internal - by using a element in the section External - by using a element to link to an external CSS file Inline - 通过在 HTML 元素内部使用 style 属性 Internal - 通过使用部分中的元素 External - 通过使用元素链接到外部 CSS 文件

To link CSS to an HTML file, we use the tag that you put in the HTML's section.要将 CSS 链接到 HTML 文件,我们使用您放置在 HTML 部分中的标记。 The link will look like this:该链接将如下所示:

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

Here's a breakdown of the attributes contained within the link:以下是链接中包含的属性的细分:

rel — defines the relationship between the file that hosts this command and the file defined in the href attribute. The standard value for this attribute is stylesheet.
type — defines the content of the linked file. In this tutorial, we set this attribute’s value to text/css. However, you can skip it altogether if you’re using HTML5.
href — specifies the location of the CSS file you want to link to the HTML. If the CSS file is in the same directory as the HTML file, you only need to enter the file name. Otherwise, you need to include the folder name in which you store the CSS file (example: CSS/stylesheet.css).
media — specifies the type of media the CSS rules are optimized for. In this tutorial, we use the screen value to imply its use for computer screens. If you want to apply the CSS rules to printed pages, you can set the value to print.

Once you've included the above link in your HTML file, save the changes and enter your website's URL in the browser.在 HTML 文件中包含上述链接后,保存更改并在浏览器中输入您网站的 URL。 Styles written in the CSS file should change the look of your website.编写在 CSS 文件中的样式应该会改变您网站的外观。

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

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