简体   繁体   English

目录导航到CSS样式表

[英]Directory navigating to CSS Stylesheet

I'm trying to navigate to a stylesheet and I've tried many options but none are working. 我正在尝试导航到样式表,并且尝试了许多选项,但没有一个起作用。

(/stylesheets/main.css)
(../stylesheets/main.css)
(./stylesheets/main.css)

My file tree looks as thus: 我的文件树如下所示:

V1(root)
---- >public
-------- >img
------------ logo.png
-------- >stylesheets
------------ main.css
---- >views
-------- >partials
------------ header.ejs
------------ footer.ejs
-------- landing.ejs

I am including my header.ejs to landing.ejs 我将我的header.ejslanding.ejs header.ejs

Here is the code I'm using: 这是我正在使用的代码:

header.ejs header.ejs

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Event Ticketing</title>
    <link rel="stylesheet" href="/stylesheets/main.css">
</head>

landing.ejs landing.ejs

<% include ./partials/header %>

<h1>Landing Page</h1>

When I try to render the landing view I'm not getting any styles linking through at all. 当我尝试渲染着陆视图时,根本没有任何样式链接。 I think the path is incorrect but have no idea how to link it. 我认为路径不正确,但不知道如何链接。

Make sure you set static path for public directory in main node app. 确保在主节点应用程序中为public目录设置了静态路径。

server.js server.js

// after setting ejs as engine
app.use(express.static(path.join(__dirname, 'public')));
// before routing

A "/" used in href references to your domain's root (www.domain.de/) - if your project was in a sub-folder, you would have to include that folder into your link. href引用域的根目录(www.domain.de/)时使用的“ /”-如果项目位于子文件夹中,则必须将该文件夹包含在链接中。

The path to your stylesheet is "/public/stylesheets/main.css", unless the folder "V1" (root) is an actual subfolder in your domain - in that case, you would have to prepend "/V1" to the link. 样式表的路径为“ /public/stylesheets/main.css”,除非文件夹“ V1”(根)是域中的实际子文件夹-在这种情况下,您必须在链接之前添加“ / V1” 。

You need to go up one more directory so, by the looks of it, your code should be like this: 您需要再建立一个目录,因此从外观上看,您的代码应如下所示:

link rel="stylesheet" type="text/css" href="../../folder/file.css"

(remember the <> at the start and end) (记住开头和结尾的<>)

That should take you up your top level folders, then into stylesheets. 那将带您进入顶层文件夹,然后进入样式表。

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

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