简体   繁体   中英

I'm having a problem loading a css sheet in an ejs file. I specified exactly where the css file is and it is still not working

所以我发布了下面的图片,向您展示我的项目的结构和未正确链接的 style.css 链接。请注意,我还尝试了使用 express 的静态方法,但它不起作用

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CRUD Application</title>

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css" integrity="sha512-KfkfwYDsLkIlwQp6LFnl8zNdLGxu9YAA1QvwINks4PhcElQSvqcyVLLD9aMhXd13uQjoXtEKNosOWaZqXgel0g==" crossorigin="anonymous" referrerpolicy="no-referrer" />
    <link rel="stylesheet" href="/crud_app/asset/css/style.css">
</head>
<body>   
    <!-- Header -->
        <header id="header">
            <nav>
                <div class="container">
                    <div class="text-center">
                        <a href="/" class="nav-brand text-dark">User Management system</a>
                    </div>
                </div>
            </nav>
        </header>
    <!-- /Header -->

This is the code that is used and note that I also tried the static method using express. When that didn't work I tried this method. Any help is appreciated. Thanks

我认为您将不得不使用内联 CSS,尽管这是一种不好的做法。

You should use express then make folder inside the main folder of the project then name it public just like this : /curd/public

then create css folder and move the style sheet folder inside it, it will be like this : /curd/public/css/style.css

then go to the app.js file or your entry point file whatever you name it, then put that code inside it

app.use(express.static("public"))

then go to the ejs file to load the stylesheet file just like this

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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