I’ve made a node.js server and its working to send an image and a css file along with my html website. The image loads fine but I get a popup on Firefox that says style-sheet could not be loaded. For debugging I put the same css path in a Iframe it opens just fine.
Here is my html
<!DOCTYPE html>
<html>
<head>
<title>Repo</title>
<!-- DOESNT WORK!!! -->
<style src="style.css" type="text/css"></style>
</head>
<body style="margin: 0;">
<img src="MazeBackground.png" alt="" srcset="">
<iframe src="style.css" frameborder="0"></iframe>
<!-- WORKS!?!?!?!? -->
</body>
</html>
and here is my node
const express = require("express");
const path = require("path");
const mime = require("mime");
const app = express();
app.get("/", (req, res) => {
app.use(express.static('public'))
res.sendFile(path.join(__dirname, "./public/index.html"));
});
app.listen(3000, () => console.log("server is listening on port 3000."));
I tried setting the mimetype to text/css and sending the css file on its own. I just ended up breaking everything.
2
Answers
You dont need the
<style>
tag, it is for inline CSS. What you need is the<link>
tag.HTML
<link>
tag requireshref
instead ofsrc
.So you have to modify your code accordingly:
W3Schools reference: w3schools reference
you must create your server like this: