【发布时间】:2020-01-08 10:30:03
【问题描述】:
所以我在这里有css链接:
<link rel="stylesheet" type="text/html" href="/public/assets/lib/css/style.css" />
现在,在当前状态下,样式根本不显示。我研究了其他人的说法和尝试:
- 起飞 rel="stylesheet"
- 更改为“文本/html”
- 检查路径
- 放在公用文件夹里问候表达
- 添加
<base href="/"> - 等等..
我还是有问题。
如果我有文本/css,我会收到 mime 错误。
我的文件路径如下:
app.js:
var express = require("express");
var app = express();
var request = require("request");
app.set("view engine", "ejs");
app.use(express.static(__dirname + '/public'));
app.get("/", function(req, res) {
res.render("search");
// res.render("location");
标题:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
*
<link rel="stylesheet" type="text/html" href="/public/assets/lib/css/style.css" />
*
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap"
/>
<link
href="https://fonts.googleapis.com/css?family=Josefin+Sans:600|Open+Sans&display=swap"
rel="stylesheet"
/>
<link
rel="stylesheet"
href="https://fonts.googleapis.com/icon?family=Material+Icons"
/>
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh"
crossorigin="anonymous"
/>
<script
src="https://kit.fontawesome.com/3870ba704e.js"
crossorigin="anonymous"
></script>
<title>tv guide</title>
</head>
<body>
搜索:
<%- include('partials/header') %>
<section class="container-fluid content">
<nav class="navbar navbar-light bg-light">
<a class="navbar-brand" href="#">
<i class="fas fa-tape">filmraid</i>
</a>
</nav>
<h1>Search for a Movie</h1>
<form action="results" method="GET">
<input type="text" placeholder="search term" name="search" />
<!-- <br />
<input type="radio" id="usMovies" name="location" /> US
<input type="radio" id="ukMovies" name="location" /> UK -->
<br />
<input type="submit" />
</form>
</section>
<%- include('partials/footer') %>
我想知道我是否在这里遗漏了其他东西。 感谢您的观看。
【问题讨论】:
-
您在 css 文件上使用
type="text/html"。请改用text/css。 -
@SaurabhSharma 就像上面提到的 text/css 导致 mime 错误
-
将
app.use(express.static(__dirname + '/public'));更改为app.use(express.static(__dirname + 'public'));并将href="/public/assets/lib/css/style.css"更改为href="/assets/lib/css/style.css" -
@SaurabhSharma 样式仍然不适用,不知道为什么。我原来也有这个。