Add css background image in node.js using express
10,219
The path to your image should be set inside url("...")
.
Based on your project structure, it would be:
body{
background-image: url("a.jpg");
}
Related videos on Youtube
Author by
user5640752
Updated on June 04, 2022Comments
-
user5640752 almost 2 years
I am experimenting with Node.js and am a complete new bee.. Haven't been able to find an answer. My directory structure is
app --> public --> a.jpg & style.css
I provide access to these files in express as follows:
var express = require("express"); var app = express(); var PORT = 3000; app.use(express.static("./app/public"));
The css works, but when i call the background-image property in the style sheet it is unable to find the image and apply it. I have tried the following combinations with no luck:
body{ background-image: "../app/public/a.jpg"; background-image: "./app/public/a.jpg"; background-image: "/app/public/a.jpg"; background-image: "/public/a.jpg"; background-image: "./public/a.jpg"; background-image: "/a.jpg"; background-image: "a.jpg"; }
can someone point me in the right direction.
-
Imnotapotato almost 6 yearsUsually backgrounds need sizes or at least content that will stretch the tag with the background applied to. Do you have any content in the body tag?
-
Dhaval Jardosh almost 6 yearsTry this
./a.jpg
. Will take you topublic
and from there toa.jpg
-
user5640752 almost 6 yearsthanks just tried it but still no go :-/
-
-
user5640752 almost 6 yearswow.. lol i can't believe i missed that.. thank you so much. it works now