我无法链接到HTML中的CSS,但路径正确。我已经尽了一切,即使魔术也无济于事。


HTML路径为romanchenko_test_task/templates/hello.html
CSS路径为romanchenko_test_task/static/first-style.css


hello.html:

<!DOCTYPE HTML>
<html>
    <head>
        <link rel="stylesheet" type="text/css" href="/static/first-style.css">
    </head>
    <body>
        <p> Hello world </p>
    </body>
</html>


first-style.css:

body {
     background: blue;
     color: white;
 }

最佳答案

您的相对链接不正确。

您的两个文件夹路径是:

romanchenko_test_task/templates/hello.html
romanchenko_test_task/static/first-style.css


因此,要退出templates文件夹,您需要使用../上移一级

尝试:

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

10-04 22:11
查看更多