Issues with CSS not loading properly on EJS files within subdirectories

This is the structure of my folders (with views located in the root directory):

views/contractor/auth/login.ejs

When I access that file, the CSS styles are not being applied. The connection to the CSS file, which is located in the public directory in the root folder, seems to be broken:

public/assets/css/styles.css

Here's a snippet from my app.js file (located in the root directory):

app.set("view engine", "ejs");
app.use(express.static("public"));
app.use(express.static(__dirname + "/public"));
app.use(express.static(__dirname + "/public/css"));
app.use("/public/css/images", express.static("./public/css/images"));

Interestingly, if I navigate to another file named home.ejs within the views directory, the CSS works perfectly fine.

I suspect that the issue lies with the subdirectory structure not being properly defined in my app.js file using app.use. Could someone kindly shed some light on why this is happening and suggest a solution?

Answer №1

It seems like the issue may be with how your HTML page is referencing the CSS file. Instead of using an absolute link to the server for the CSS, the page should call the CSS from the browser when executing.

Unfortunately, I don't have access to the HTML code to confirm this. One thing you can try is opening the page and pressing F12 to view the loaded files in the HTML page. If your CSS is successfully loaded, it should appear in the hierarchy of file lists. Use the link to the CSS from the root folder and put it in the import of the CSS file. Let me know if this solution works for you! I hope it does.

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

Exploring Next.js nested dynamic routes: utilizing getStaticProps for data fetching and sharing data across routes

I am currently working on developing a next.js application with nested dynamic routes and the need for shared data among these routes. The directory structure I have set up is as follows: -pages -/level1 -/[level1_id].js -index.js -/level2 ...

How to utilize JS variables for filtering an array in EJS?

Is there a way to filter my user array based on the "username" variable in JavaScript? On the server side: var users = data.filter(u => u.id.startsWith('user_')).map(u => u.value); // [{"username": "arin2115", "som ...

Tips for building a dynamic view using Angular

I am working on a project where I need to dynamically generate multiple horizontal lines using data from a JSON file, similar to the example in the image below. Here is my attempt: Component.html <div style="text-align: center"> <div ...

Change the default content of the jQuery menu with a content changer

After sharing some base code for a webpage to dynamically change its content based on menu selections, I wanted to showcase the code. Take a look below: HTML: <!DOCTYPE html> <html> <head> <link rel='stylesheet' type=&apos ...

Interactive Vue tree view featuring draggable nodes

I am currently working on creating a tree component in Vue.js, and I am facing challenges with implementing drag and drop functionality in the Tree component. I am unsure where to begin, as I have looked through similar code on GitHub but I am struggling t ...

Updates to the Tailwind file are not appearing on the page after reopening the file

Every time I reopen the project, the file tailwind properties do not get rebuilt and if I add new properties like text-color, they are also not reflected. Any suggestions on how to solve this issue? I need the project to update and take in new properties ...

Separation between dropdown menu subcategories

I have searched through various discussions but haven't found a solution that addresses my specific issue, especially at a beginner level. I would really appreciate some guidance. The problem I'm facing involves my drop-down menu displaying gaps ...

Guide to utilizing JavaScript for a basic gaming experience

Looking to incorporate multiple divs that will vanish upon being clicked, while also increasing the score by 1 through javascript. Any suggestions on how to accomplish this? ...

Tips for maintaining a website within a 960px width while stretching the background on the x-axis

I have enclosed the entire website within a div with the ID container. The CSS styling for the container is as follows: #container { width: 960px; background: #FFFFFF; margin: 0 auto; border: 1px solid #000000; text-align: left; } How ...

Removing the gridlines in a Linechart using Apexcharts

I am experiencing issues with the grid and Nodata options on my Apexchart line chart. noData: { text: none , align: 'center', verticalAlign: 'middle', offsetX: 0, offsetY: 0, style: { color: undefined, fontSize: &apo ...

An AJAX request will only occur if there is an alert triggered on a particular computer

Here's an interesting issue I encountered with my company's CMS newsletter system. It seems that the AJAX call to send an email works flawlessly in all modern browsers and operating systems, except for one client. This particular client is using ...

Angular's minimum date validation is not accurate for dates prior to the year 1901

Any assistance or clarification on this matter would be greatly appreciated. It appears that there may be an issue with my implementation, as otherwise it seems like a significant bug within Angular. Setup Create a form with a minimum date of 0001-01-01 ...

CSS: What causes the gap below my border to appear?

I've noticed an issue in the HTML code snippet below: there seems to be some extra spacing under the border of the 'bucket' div. Despite my attempts, I haven't been able to figure out why this is happening. Can someone provide some ins ...

Increase the lag time for the execution of the on('data') function in Node.js

In my current function, it searches data from a database and performs an action with it. For the purpose of this demonstration, it simply increments a counter. exports.fullThreads = function(){ return new Promise((resolve, reject) => { MongoClien ...

PHP email not going through, stuck on an empty screen

In the process of creating a PHP form mailer, I have encountered multiple obstacles and none of the versions seem to work. My goal is for the information submitted via the form to be automatically sent through email when the 'Submit' button is cl ...

jQuery autoscroll feature for Carousels added

I followed a tutorial to create a jQuery Carousel, but made some modifications. You can find the tutorial here. This is the code I have: (function ($) { $.fn.infiniteCarousel = function () { // Function to repeat a string function repeat(str, num ...

Inspect every div for an id that corresponds to the values stored in an array

I am in the process of developing a series of tabs based on a preexisting set of categories using the JavaScript code below. Now, I am looking to expand this functionality to target specific IDs within the DIV ID corresponding to values from an array in JS ...

creating dynamic navigation tabs with scroll functionality

Utilizing Bootstrap Nav Tabs and Tab panes on my website has been a smooth process. However, I am encountering some difficulty in adding extra links that not only activate the Tab Panes but also scroll to them. The issue seems to be related to a specific l ...

Which Node Module offers a CLI interface for user input?

I've been on the hunt for a node module that offers a CLI prompt interface similar to a REPL for my Node application. What I have in mind is a mix between tools like inquirer or prompt, and commander. While Node does have a built-in REPL module, it ...

When I click on the md-select element, a superfluous "overflow-y: scroll;" gets added to the <body> of my webpage

Typically, I have the following styles on my body: element.style { -webkit-app-region: drag; } However, when I interact with a md-select element (you can observe this behavior on the provided link), additional styles are applied. element.style { -w ...