Some of the CSS code in my file is not displaying properly on my ejs file

For some reason, only the CSS styles for my footer are rendering on my ejs file. The rest of my CSS doesn't render at all. I've tried defining the path of my static files to my views directory using the path method:

app.use(express.static(path.join(__dirname, 'public')));
. Additionally, I linked my main.css file to my header.ejs file by adding this line
<link href="/styles/main.css" rel="stylesheet" type="text/css">
; however, it still only renders the footer's CSS style and not the rest.

CODES:

index.js:

import express from "express";
import bodyParser from "body-parser";
import axios from "axios";

// Other code snippets like setting up API_URL, importing modules etc.

app.set('view engine', 'ejs');
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, 'public'), { 'extensions': ['html', 'htm'], 'index': false, 'maxAge': '1d', 'setHeaders': (res, path, stat) => { res.set('Content-Type', 'text/css'); } }));
app.use(express.static(path.join(__dirname, 'public')));

// App routes


app.listen(port, () =>{
    console.log(`Server is running on ${port}`);
});

main.css:

body {
    background-color: red;
}

footer {
    color: green;
}

header.ejs:

Add content here.

index.ejs:

Add content here

footer.ejs:

Add content here

Facing issues with CSS rendering as only the footer styles are applied while others get cancelled. Screenshots can be found below:

Please help me troubleshoot this long-standing issue. Appreciate any assistance. Thank you!

Answer №1

Your website is utilizing a CSS and JS Component library called

<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a3c1ccccd7d0d7d1c2d3e3968d908d91">[email protected]</a>
. The issue you are facing is that your background-color is being overridden by a Bootstrap CSS selector, either because it has higher specificity or is loaded after your own main.css file.

To address this problem, you have two options: either link your main.css file after the Bootstrap one in your HTML, or make your CSS selector more specific like so:

#body {
    background-color: red;
}
<body id="body">

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

Why is the 'name' property used in the export default{} syntax?

Vuejs is my current learning focus, and one thing that puzzles me is the necessity of this particular name. <template> </template> <script> export default { name: 'NotFound' } </script> <style> </style&g ...

Is there a way for me to expand the dropdown menu?

My current dropdown looks like this. I'd like the dropdown menu to span across the screen, something like this: To create my dropdown, I am using https://github.com/angular-ui/ui-select2. AngularJS JQuery Select2 I'm not sure if there is an ...

Leveraging the power of React and Nodejs to seamlessly share code across both the front-end

Currently, my front-end is built in React and backend is developed using Nodejs with the Adonisjs framework. I am looking to share some code between the client and server components of the application. Unfortunately, due to company policies, my team is una ...

installing packages globally in npm with elevated permissions and disregarding security precautions

Attempting to install an npm module by running the command: sudo npm install -g now However, during this process, a warning is encountered: Warning! It is advised to reinstall Now CLI with the option --unsafe-perm. For instance: npm i -g --unsafe ...

Exploring the power of NestJS integration with Mongoose and GridFS

I am exploring the functionality of using mongoose with NestJs. Currently, I am leveraging the package @nestjs/mongoose as outlined in the informative documentation. So far, it has been functioning properly when working with standard models. However, my p ...

Utilizing Reactjs in combination with Azure services

I am currently facing an issue with my webApp created using Nodejs 8.1. After uploading my code via a zip file, I successfully ran npm install and start in the kudu command line debug console. Despite these steps, my website is still not visible. It's ...

What is the best way to resize a div located below a dynamic div in order to occupy the available space?

My website has a dynamic div1 and a scrollable table inside div2. I need the div2 to take up the remaining height of the window, while ensuring all divs remain responsive. I've tried using JavaScript to calculate and adjust the heights on window loa ...

Material-UI's JSS does not adhere to the justify content property

Having trouble aligning elements in my React app using material-ui 1.0 and its JSS solutions. The code I've written below should center justify, but it's not working no matter how I configure it. I suspect there might be a naming issue since mat ...

Dealing with errors in Express 4 within a Node.js application: Tips and tricks

After upgrading to Express 4, I encountered an issue with error handling. In the past, I used to place the following code in app.js after defining all the routes: var routes = require('./routes') app.use(routes.notfound) app.use(routes.error) a ...

HTML input field that shows a hint text when selected

Is there a way to create a text box that shows a hint when clicked on? For example, you can see this feature by clicking on the address text box in the following link: ...

I'm having issues with npm installation, receiving a "module not found" error. I've

My experience with installing modules has been smooth so far, but recently I encountered an issue without changing my usual workflow. I executed: npm i --save mariadb in the main directory of my Node project. Then, I imported the module as follows: con ...

Why is it that when I refresh the page in Angular, my logged-in user is not being recognized? What could be causing this

I am developing a Single Page Application using the combination of Angular JS and Node JS. In my HTML file, I have defined two divs and based on certain conditions, I want to display one of them using ng-if. However, I noticed that the model value used in ...

What happens when an OPTIONS request is processed with the `preFlightContinue` setting enabled?

Recently, I came across the concept of a "preflight OPTIONS request" in Express that I realize I don't fully understand. This is typically how it's handled: const cors = require('cors'); const app = express(); app.use(cors({ preflig ...

Knejx Js is the embodiment of guarantees

I am trying to figure out how to make this function work. I only receive a promise as the output. codeProducts.forEach((code, index) => { const qt = app.db('products').where('code', code).first().then(result => result.quanti ...

My express app's Jest tests are still pending despite executing server.close()

I am trying to run an integration test on my express app but encountering a problem. The express app is exported in the app.js file without being set to listen on any port. Here is how my test case looks like: const app = require('../src/app'); ...

Error: Unable to locate corresponding closing tag for "<%"

I'm struggling to figure out what I might have missed. Everything appears correct, but the nested and somewhat complex code that I am writing seems to be causing an issue with EJS. The variable posts has been passed from node.js to the EJS file. How c ...

Ways to check if the token has expired

I am looking to confirm the expiration status of a token and then send a status along with a message async function verifyToken() { const ticket = await client.verifyIdToken({ idToken: req.body.token, audience: CLIENT_ID }); const payload = ...

I made a request using the post type fetch to submit data to this form, but unfortunately, the server-side response returned

I encountered an issue where after sending the post type fetch to this form, I received 'undefined' on the server side. Here's the code snippet for my fetch request: const { text, id } = Data; fetch('http://localhost:3001/add' ...

Interested in uploading numerous images using express-fileupload

I am looking to improve my image upload functionality by allowing multiple images to be uploaded in a single input field without limiting the number of uploads. Below is the current code snippet that handles individual image uploads: router.post('/a ...

How can I make a 100vh div stick to the screen?

Is there a way to fix a Google map in a div to the screen so that the map on the left side remains fixed while the content on the right side can scroll? I've tried using position:fixed but it doesn't seem to be working. See the pictures below for ...