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

Tips for sending a localstorage value as a parameter in an axios request

Currently, in my React app, I am using Express to handle all of my database queries. One thing I am attempting to achieve is passing the user id stored in local storage into a post request. This is necessary for my application since it revolves around use ...

utilize javascript variables within an HTML document

I keep encountering a strange error (Express 400 Error: Bad Request) Some lines are translated to the variable value, while others just output an error. This is an example of my code: exports.add_comment = function(req, res){ var id = req.params.id; ...

RabbitMQ - determining the optimal prefetch count for each consumer

Could someone clarify the usage of the node-amqp library for creating multiple consumers in RabbitMQ? I am unsure if the prefetch-count option applies to each individual consumer or if it is shared among all consumers. I want each consumer to have its own ...

Discovering the smallest, largest, and average values across all properties in an array of objects

Given an array of objects with varying values, the task is to determine the minimum, maximum, and average of the properties in that array. For example, consider the following array: const array = [{ "a": "-0.06", "b": "0.25", "c": "-0.96", ...

Is pairing Node.js and ColdFusion on a single server a good idea?

I have a question regarding setting up a server application with Node.js. Currently, I have a ColdFusion application running on my server and I am able to test my code using the browser URL. However, for Node.js, I can only run the code through the comm ...

Tips for formatting dates in a Mongoose model

I'm new to using mongoose and I've set the type of my "holidayDate" column as "Date". I only want to store the date without the time in this column. Is there a way to define the date format in the domain model so that when my domain is saved, the ...

Issue encountered while invoking the jQuery html method

Embarking on my first adventure with javascript + jQuery, creating a basic page but running into errors. I've gone through the code multiple times and still can't seem to find the issue. Below is the error message I am encountering: The complet ...

Creating a conditional query in Mongoose: A step-by-step guide

The code below functions without any query strings or with just one query string. For example, simply navigating to /characters will display all characters. However, if you specify a query string parameter like /characters?gender=male, it will only show ma ...

Why is it that comparing the childNodes of two identical nodes results in false, while comparing their innerHTML yields true?

Currently, I am in the process of developing a simple function in Node.js that compares two DOMs. My goal is to not only identify any differences between them but also pinpoint the exact variance. Interestingly, upon reconstructing identical DOMs using jsd ...

Using Node.js and Express for sending attachments with Nodemailer

Is there a way to attach a file to an email using Nodemailer that actually works? I've tried various methods following the instructions on , with .pdf, .txt files but nothing seems to be working. Any suggestions or ideas? Here is the code snippet from ...

Conceal information within a label

I am encountering an issue with a wordpress plugin and I am attempting to conceal (or alternatively, replace which would be fantastic) the terms "DD", "MM" and "YYYY" in the provided code: <div class="smFormInlineFormCont"> <div class="smInli ...

Certain issues arise when adjusting the padding within the background color of solely the inline text element

Appreciate your time. I'm working on adding background color to the TEXT exclusively, and have successfully done so by styling .post-title { text-transform:capitalize; margin-top:4px; margin-bottom:1px; font-size:22px; background-color:#FFF; dis ...

When a dialog box is displayed, a scrollbar will automatically appear

I've encountered a strange issue while working with Angular dialogs: A vertical scrollbar unexpectedly appears, even though I've set the dialog to have a fixed width. component.ts const dialog = this.dialog.open(DialogComponent, { width: ...

Creating a flexible grid layout in CSS without relying on any pre-made frameworks

Suppose I am working with the following HTML structure <div class="option"> <input type="checkbox" /> <label>Checkbox</label> </div> <div class="option"> <input type="checkbox" /> <label>Chec ...

Connecting radio buttons to data in Vue using render/createElement

How do you connect the value of a selected radio button to a specific variable in the data object within a Vue application when using the render/createElement function? ...

Combine two languages into a single <p>

I'm dealing with a WordPress website where I have a paragraph that contains two different languages. What I want to achieve is to display each language in a distinct font-family (font-face). For example: <p>למרות הכל its worth it</p& ...

Change the marquee scrolling back to its original starting point

I am trying to implement a continuous image scroll (marquee) in HTML. My goal is to have the marquee stop scrolling when the mouse hovers over it, with the images returning to their initial position. Once the mouse moves away, I want the marquee to resume ...

Breaking down JavaScript arrays into smaller parts can be referred to

Our dataset consists of around 40,000 entries that failed to synchronize with an external system. The external system requires the data to be in the form of subarrays sorted by ID and created date ascending, taken from the main array itself. Each ID can ha ...

Creating a CSS section that expands with a minimum height of 100% and perfectly centers its content vertically

Seeking an elegant solution for having sections with a minimum height of 100% (window height). The div should expand to fit the content if it exceeds 100%, and vertically center the content within the div if it is smaller. I have managed to find a simple ...

How to place a child <div> within a parent <div> that is fixed on the page

I am currently working on creating a modal window using HTML/CSS. My goal is to have the modal window fixed in position relative to the browser window, with a white background. Inside the modal, there will be an image at the top and a div element at the bo ...