Having trouble getting a background image to show up using node.js?

Hi there, I have a quick and simple question. I am attempting to include a div with a background-image in my *.ejs page file.

<style>
    .signPage{
        background-image: url("//back.jpg");
        width: 98%;
        height: 98vh;
        top: 1%;
        right: 1%;
        position: fixed;
        border-radius: 20px;
    }

The image and the ejs file are located in the same directory. Thank you!

Answer №1

In order to utilize a background image in your project, ensure that you set up a static path in your app.js file and place the desired image in the public/images directory.

background-image: url("images/back.jpg");

app.use(express.static(__dirname+'/public'));

Answer №2

When referencing an image in your CSS file, remember to provide the correct path starting from where the CSS file is located.
For example, if your image is stored in a folder called "images" within a folder named "public" and your CSS file is in the "css" folder within "public",

then you should specify the path like this:
-- ../images/image-name.image-extension

To put it simply - Make sure to provide a relative path from CSS to the image.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using a pool.query with async/await in a for-of loop for PostgreSQL

While browsing another online forum thread, I came across a discussion on using async/await with loops. I attempted to implement something similar in my code but am facing difficulties in identifying the error. The array stored in the groups variable is f ...

Encountering a problem during the setup of Vue.js with Onsen UI

Looking to dive into onsenUI vue but running into some issues. When I try to start a new project with monaca using the command: monaca create helloworld and choosing the onsenui-v2-vue-splitter template, I encounter the following error: npm WARN package ...

HTML - Align 3 tables horizontally with text below

I have successfully floated 3 tables next to each other using <table style="float:left;">. However, I am facing an issue where some text is being wrapped to the right side of the right-most table instead of being left-justified at the very ...

Please confirm and verify my comprehension of Express Routes

Before delving into the question at hand, I just wanted to confirm something. When I instantiate Express with const app = express(), is app an instance of the entire Express module? I ask because when I call app.route, is route an Express method or a NodeJ ...

Is there a way to align these blocks in a single row?

Having trouble aligning these buttons horizontally. Any suggestions? I've been tinkering with this for a couple of hours now, so decided to seek help here. The desired effect should resemble the image below, but it's not quite there yet. Thank yo ...

Different Line Thickness in Dropdown Menu

Is there a way to adjust line heights in CSS within a drop down menu? I have attempted to change the font sizes of each element, but the new font size does not seem to take effect once an option is selected. Any suggestions would be greatly appreciated! & ...

Testing Node.js Applications - Generating Mock Layers with the mocha Testing Framework

After developing a web service that interacts with an external API and includes various validations and data manipulations, I am now looking to create unit tests and generate a code coverage report. While there are numerous suggestions online, Mocha seem ...

Step-by-step guide on installing both Angular and Nodejs within a single folder

I'm diving into the world of NodeJs and Angular, and I recently created a simple NodeJS application following instructions from this link. However, I encountered an issue when trying to install Angular alongside NodeJS. After running ng new angular-cr ...

Tips on querying a 3-level nested object in MongoDB

I am having trouble filtering objects by comparing specific fields within the third level of my objects. I am unsure how to properly use the $lte or $gte filter in this case. For instance, I want to filter documents based on the delivery time (delivery_rul ...

Preventing CSRF Errors when activating API endpoints in Node Express JS by ensuring that bypassing the error message with next() function is ineffective

In this middleware block, I have implemented a mechanism to render a 404 page when an invalid CSRF token is detected. /* * Middleware for rendering 404 page on invalid csrf token */ this.app.use((err: any, req: Request, res: ...

Response in JSON format from a solitary request

Trying to use async.parallel to fetch JSON data from two different tables in a single URL Encountering issues while debugging the error Current Scenario: There is a database with two tables Attempting to convert JSON response from both tables usin ...

Discovering the most recent update date of Node packages

I recently noticed that one of the node dependencies my project relies on has been updated since a few days ago. The update caused my test suite to fail, even though I haven't made any changes to my code or package.json in that time. It seems like NPM ...

What is the best way to conceal the li elements that exceed a single line?

I have a unordered list containing product information as list items. My goal is to hide the list items that do not fit on a single line based on the screen size. Therefore, the number of products displayed should adjust depending on how many can fit on a ...

What could be causing a blank page to appear after being redirected? (Using NextJS 13 API Route)

After struggling with this issue for 2 days, I'm throwing in the towel and reaching out to the community for assistance. I've been tasked with setting up a basic login system for a new project using NextJS v13. However, it seems like a lot has c ...

CSS style takes precedence over inline JavaScript transitions occurring from a negative position

I am puzzled by a JavaScript fiddle I created which contains two small boxes inside a larger box. Upon clicking either of the buttons labeled "Run B" or "Run C", the corresponding box undergoes a CSS transition that is controlled by JavaScript. Below is t ...

Express JS redirect does not update the URL and fails to load static files

I'm currently developing an application using Express.js to build the REST interface on Node.js. Additionally, I am using jQuery Mobile for the client-side pages. One issue I am facing is with redirects when users try to access a restricted or inacce ...

Retrieve MQTT messages via AJAX in web polling

Novice in the field. I'm attempting to create a straightforward data flow: MQTT-Data-source ---> MQTT Broker ---> NodeJS-MQTT-Client ---> AJAX-on-web-browser (fetching-every-3-seconds) I aim to retrieve the MQTT message and display it in the AJAX ...

Homebrew on Mac - updating Node version does not automatically update NPM version

Can anyone help me with switching Node and NPM versions on my Mac using Homebrew? Currently, I am running Node/NPM 8.2.1/5.3.0, but I want to switch to 6.11.2/3.10.10 as per the documentation. I tried the following commands: $ brew install node@6 $ brew ...

Is it possible to bind browser keyboard scrolling to a div without explicit instructions?

Here is a question that closely relates to this one: Enable div to scroll by keyboard without clicking I am aware that explicitly focusing on the element will enable the desired behavior. My inquiry is whether there is a way to achieve this implicitly. ...

Issue encountered when attempting to save document using Mongoose's create() method

I am encountering an issue with my code that involves generating a user profile and saving it to the database using Mongoose's create() function. Unfortunately, I am facing difficulties as it seems that the user profile data is not being properly pass ...