首页 > 解决方案 > HTML wont link with CSS. they are both in the same folder

问题描述

This is the HTML:

<!DOCTYPE html>
    <head>
        <title> navigation practice</title>
        <link rel="stylesheets" type="text/css" href="style.css"/>
    </head>
    <body>
        <ul>
            <li><a href="#"> HOME</a></li>
            <li><a href="#"> ABOUT</a>
                <ul>
                    <li><a>camp sites</a></li>
                    <li><a>our team</a></li>
                    <li><a>wildlife</a></li>
                    <li><a>resources</a></li>
                </ul>
            </li>
            <li><a href="#"> CONTACT</a>
                <ul>
                    <li><a>email</a></li>
                    <li><a>phone</a></li>
                </ul>
            </li>
            <li><a href="#">things to do</a>
                <ul>
                    <li><a>shops</a></li>
                    <li><a>activities</a></li>
                    <li><a>trails</a></li>
                </ul>
            </li>
            <li><a href="#"> MORE</a></li>
        </ul>
    </body>
</html>

The CSS just has:

body {
  background: blue
}

both the HTML and CSS are in the same file. I’ve checked spelling on the link, syntax and any errors in the CSS. I’ve also tried opening the file in a different browser. I have this problem every time I start a new project. I’m using Notepad++.

标签: htmlcss

解决方案


问题出在您的样式表标签上,您在单词末尾添加了一个不必要的“S”,它应该是:

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

不是stylesheets

而且您忘记在声明和字符集声明之后打开html标签。<!doctype html>这是它应该是这样的:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title> navigation practice</title>
        <link rel="stylesheet" type="text/css" href="style.css"/>
    </head>
    <body>
        <!--YOUR CODE HERE-->
    </body>
</html>

尝试在此处验证您的代码:https ://www.freeformatter.com/html-validator.html 。它会显示它有什么问题。


推荐阅读