Unable to apply styling to body element in style.css file when using Node.js

I recently launched a basic Node.js website but encountered an unusual issue. When trying to style the body using the default style.css stylesheet provided by Express, I found that it was not recognizing it. The only workaround was to add the class body directly to the body tag and modify the CSS declaration to .body. Why is the code below failing to work?

style.css

.body {
    background-color: black;
    margin-top: 50px;
}

.navbar {
    height: 50px;
}

.footer {
    text-align: center;
}

index.ejs

<!DOCTYPE html>
<html lang="en">
  <head>
    <% include partials/head %>
  </head>
  <body>
     <% include partials/nav %>
    <div class="container-fluid">
        <div class="row">
            <div class="col-xs-12">
                <h1><%= title %></h1>
            </div>
        </div>
    </div>
    <% include partials/footer %>
  </body>
</html>

Answer №1

My custom css file was being overridden by Bootstrap. By rearranging the order of declarations, placing the custom css file after the Bootstrap declaration, I was able to successfully override the styles set by Bootstrap.

Initially:

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title><%= title %> | NodeSite</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Core CSS -->
<link href="stylesheets/style.css" rel="stylesheet">
<link href="stylesheets/bootstrap.css" rel="stylesheet">

Revised Order:

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title><%= title %> | NodeSite</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Core CSS -->
<link href="stylesheets/bootstrap.css" rel="stylesheet">
<link href="stylesheets/style.css" rel="stylesheet">

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 the functionality of multiple index pages in angularjs

I am trying to access the localhost:3000/admin which is located in my views. The index.html and admin.html are two separate base files, one for users and the other for the admin dashboard respectively. Here is a snippet from my app.routes.js file: angul ...

Looking to retrieve the checkbox value from HTML in AngularJS and pass it to the controller

How can I retrieve the value of a checkbox on button submit in a controller Function? <input id="Check" type="checkbox" ng-model="CheckValue" /> ...

Setting up SSL on KeystoneJS using letsencrypt and apache2, ensuring secure and encrypted

My current setup involves deploying a KeystoneJS app on Ubuntu 16 using docker-compose, along with a valid LetsEncrypt certificate. In my keystone.js file, I've included the following settings: 'ssl': true, 'port': 3000, 'ad ...

Creating a React button animation with CSS vibes

When I click a button, I want a subtle sparkle to appear and disappear quickly, within half a second. I've thought about using a gif, but it requires a lot of manual artistic work to achieve the desired effect. Is there a way to utilize the Animatio ...

A request that returns an empty body in the response

I am encountering an issue with the code snippet below: var request = require('request'); var cheerio = require('cheerio'); var URL = require('url') var fs = require('fs') fs.readFile("urls.txt", 'utf8', f ...

Accessing Protobuf File From Another Git Repository in gRPC Node Server

Overview: We operate multiple microservices that are maintained by separate teams The majority of our services are written in Java, with the exception of one service which is developed using Node.js The interface for the Node.js service is specified in a ...

Modify the color of an Ionic button for a single button, rather than changing the color for all buttons

How can I modify this code so that only the clicked button changes its color, not all of them? Here is the current code: .html: <ion-col size="6" *ngFor="let data of dataArray" > <ion-card> <ion-card-header> ...

Error message: The color shade "100" is not in the color palette. The only available shades are primary, accent, and contrast

I am in the process of upgrading from Angular 12 to 13. Encountering this error, and so far I haven't been able to find a solution for it. Could someone please guide me in the right direction? Here is my package.json file: { "name": &quo ...

Finding the total amount in VueJS2

I'm having trouble calculating the total row in Vuejs2 as shown in the image below: This is the code I have been using: <tr v-for="(product, index) in form.items" :key="index"> <td class="saleTable--td">{{ product.name }}</td& ...

Modify the appearance of HTML dialog box using CSS styling

Currently, I am working on a Java Spring project that includes a single CSS file consisting of around 1500 rows. Recently, I was tasked with adding a dialog box to one of the screens in the project. The issue I encountered is that the style of the dialog b ...

Encountering the issue of "Module build failed: Error: Cannot find module 'ajv'" can be frustrating and can disrupt your workflow

Encountering the error message Module build failed: Error: Cannot find module 'ajv' while attempting to execute vue-cli-service serve --mode dev in my application. The package ajv is installed as a dependency of other packages, and not directly ...

Tips for resolving a top bar on the left side Grid with CSS without it covering the adjacent right side Grid element

I am currently working with material-ui and react, and facing an issue with the positioning of a top bar within a Grid element. The top bar is meant to be fixed in its position, but not at the very top of the page as it is inside a parent Grid element. I ...

Transitioning from mongodb to MongoLab with the help of Node.JS

I need help implementing a similar setup to what's described in this question on Stack Overflow: How do I setup MongoDB database on Heroku with MongoLab? Currently, my app is working on Amazon EC2 and I want to deploy it to Heroku with the MongoLabs ...

What is the best way to arrange form inputs in a single row?

My form consists of three input boxes. While the first two inputs are single line, the third is a description field with 10 rows set as default. However, for some reason, this third box is not aligned properly with the other two. Please refer to the screen ...

Encountering the error message "string spec is required" when trying to run npm install

I am facing an issue while trying to run a react app that I developed two years ago. Upon running the app using "npm install", I encountered the following error: npm ERR! must provide string spec npm ERR! A complete log of this run can be found in: npm ERR ...

What steps should I take to set up a user registration system that is exclusive and invite-only

Currently, I am in the process of developing a website that involves user authentication. I am considering implementing restrictions through either invites or another method. This site is being constructed using Node, Express, and MongoDB. My plan is to u ...

What steps can be taken to reduce the size of the cards in ant.design?

Currently, I am using the ant.design Card component to present messages in a chat webapp built with react/redux. However, each card is displaying too much space around the text. Is there a way to adjust the card so that it wraps the text more closely? htt ...

Tips on submitting an Array from a Textarea to mongoDB

I have a question regarding posting an array of serial numbers. When I try to post the serial numbers added in the textarea, they are posted as a single string. Here is my form: <form class="" id="serialsForm" action="/serialsnew" method="post"> &l ...

Scraping multiple websites using NodeJS

I have been immersing myself in learning NodeJS and experimenting with web scraping a fan wikia to extract character names and save them in a json file. I currently have an array of character names that I want to iterate through, visiting each URL in the a ...

Tips for sending data through an AJAX call to the app.post() function in Express

I am currently working on a blog application using express and node. In order to save a blog post without using a database (as the posts are stored in an array), I need to pass an array of keywords to the app.post() method. To display keywords as separate ...