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

Angular file upload component with customizable file size limits

I'm currently developing an upload file feature that will transmit the file via nodejs. However, I am encountering an issue related to file size. Whenever the file exceeds a few kilobytes, I encounter the following error: Error: request entity too la ...

After attempting to install npm manually using deb.nodesource.com/setup_14.x, it was still missing from the docker image

Regarding my docker file, I have included both python3 and node 14 in the docker image: FROM python:3.8-slim ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 ENV DJANGO_DEVELOPMENT 1 #Installing necessary packages RUN apt-get update && apt-ge ...

Transform an array of strings into an array of object IDs

Recently, I encountered an issue with transforming an array of strings into object IDs using mongoose type. Unfortunately, my attempt was unsuccessful as it seems the method only works for single string inputs, not arrays. let stringObjectIdArray = [&apos ...

Utilize the display flex property within a nested flex container

I can't seem to get my link text centered both vertically and horizontally, it keeps aligning to the left. I was under the impression that using flex-based alignments would solve this issue. I have gone through the information on using a flex item as ...

Expanding Material Ui menu to occupy the entire width of the page

I'm encountering an issue with a menu I created where I can't seem to adjust its height and width properly. It seems to be taking up the full width of the page. import React, { Component } from "react"; import Menu from "@material-ui/core/Menu"; ...

What is the solution for positioning an input or select element at the end of a tr element?

Within a table, I have a form where each <td> tag contains either a <select> or an <input>. However, due to the varying lengths of the labels within the <td> tags, the <input> or <select> fields are not aligned in the sa ...

Resolving formatting challenges in R markdown with Blastula

Dealing with formatting problems while trying to include an R markdown file in an email body. As a CSS novice, I'm struggling to find a solution and it's becoming quite frustrating. The table has the following CSS styling: <!DOCTYPE html ...

Assistance needed to integrate vaccine center data with the administration, MongoDB, and MEAN stack project

Hey there, I'm a beginner in developing a MEAN stack project. Currently, I am facing an issue with two collections: one for users who are admins and another for healthcare centers providing vaccines. My task involves registering an admin to a healthca ...

Move the div in an animated way from the bottom of the screen to the right

I am facing an issue with the image animation in my project. Currently, the image moves from the bottom to the left corner, but I want it to move from the bottom to the right corner instead. I have attempted using the transform translate property to achiev ...

How can I resolve the issue of var opts = Object.create(options || null) displaying an error?

I created a small server and encountered the following issue: //const http = require('http'); const cors = require('cors'); const path = require('path'); const port = process.env.PORT || 8080; const knex = require('k ...

Absolute positioned content causing unexpected spacing on top of relative positioned content

I've been experimenting with a fantastic technique by Chris Coyier for implementing full page video backgrounds with content scrolling over the video. However, I've encountered an issue where there's an unexpected gap to the right in Windows ...

Efficiently log and save detailed request data through our new logging system

Exploring Logging Options Node.js offers a variety of logging libraries such as winston, bunyan, and console.log. Logging request information along with response data is crucial for troubleshooting and monitoring system activity. The Dilemma A common cha ...

Different ways to adjust the appearance of table borders in HTML

I find myself at a standstill, hence why I am reaching out with this question. This Table presents itself with various border sizes and colors, along with similar complexities in the background of its cells. Could anyone provide me with guidance on how t ...

Ways to efficiently handle numerous asynchronous requests in a NodeJS/Express API

I am looking to consolidate a variety of REST APIs into a single, easy-to-use API. My plan is to develop a straightforward nodejs/express API that will handle the individual calls asynchronously and then aggregate all the results together at once. The Jav ...

Tips for dynamically resizing an image to suit any screen size, such as with Bootstrap 4

I am having trouble centering an image on the screen and making sure it fits properly without requiring the user to scroll (on screens larger than a tablet). Here is my desired outcome: https://i.sstatic.net/LbfV8.png The top row shows the expected resu ...

Using unicode characters to style your Angular application

Hey there! I have an Angular 5 app on StackBlitz that implements table sorting. You can check it out here: https://stackblitz.com/edit/angular-rxdzom. The code for this app is based on the example from . In the app, I've used a stylesheet at ./app/sor ...

Error: When running the NPM CI command in a GitHub action, the package nice-napi is not accessible from

I've recently set up a Github action to build and run tests on every pull request. However, the action suddenly stopped working even though no changes were made to the code base. Here is the current code for the action: name: Test pull request on: ...

The AppBar is consuming space and obstructing other elements on the

As I dive into React/Material-UI and learn the ropes of CSS, I've come across a challenge with my simple page layout featuring an AppBar. Unfortunately, this AppBar is overlapping the elements that should be positioned below it. In my quest for a sol ...

Mongoose encounters difficulty in establishing a reference -Schema.Types.ObjectId- to another document

As I attempt to save a document using mongoose following the guidelines on http://mongoosejs.com/docs/populate.html, my approach involves calling parent.save initially and then utilizing child.save within the callback of parent.save. However, upon checking ...

What are the steps to troubleshooting using VS Code and Chrome browser with Webpack?

Can anyone provide guidance on how to debug webpack in VS Code with the Chrome browser? As a beginner in programming, I'm struggling because webpack minifies everything into one line which makes traditional debugging methods ineffective. I haven' ...