How come my ejs files are all affected by the same stylesheet?

Currently, I am in the process of developing a nodeJS application utilizing Express, MongoDB, and EJS template view engine. The server.js file has been successfully created to establish the server. In addition, a separate header.ejs file has been implemented for inclusion in other ejs files such as index.ejs, about.ejs, contact.ejs, etc. However, upon creating a stylesheet solely for the header.ejs file, the styles are being applied across all ejs files including index.ejs and about.ejs.

The header.ejs file is located within the ./public/partials/ directory, while the associated stylesheet can be found in the ./public/assets/ folder. Furthermore, the index.ejs file resides in the ./views/ folder.

Server.js

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

employeeController.js

router.get('/employee' , function(req, res){
    res.render("index");
});

module.exports = router;

header.ejs

<link rel="stylesheet" href="assets/header.css">
<h2>Company Logo</h2>

index.ejs

 <link rel="stylesheet" href="/assets/style.css">
 <% include ../public/partials/header.ejs %>
  <h2>Please Enter the New Employee Information</h2>

It's important to note that defining 'h2 {color: indianred;}' in the header.css file resulted in a color change not just in the header.ejs file, but also in the index.ejs file despite the linkage being exclusive to header.ejs.

In order to restrict the color change to only the h2 element of header.ejs, what measures should be taken?

Answer №1

When you include header.ejs in index.ejs, the css is automatically added, which may be causing the issue you are experiencing.

To resolve this problem, you can add a class or id to the h2 element like so:

<h2 class="h2_css">Company Logo</h2>

or,

<h2 id="h2_css">Company Logo</h2>

Then, you can style your h2 with the added class/id using CSS:

h2.h2_css {color: indianred;} 

or

h2#h2_css {color: indianred;} 

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

Looking for a PHP add-on for fpdf converter that can handle ul li tags

I need assistance with using fpdf to convert dynamic site content to pdf. The issue is that fpdf does not support ul li tags. Is there an add-on available for fpdf that supports ul li and ol li tags in html? To provide more context: The content being con ...

How can I create a join for my initial column in TypeORM?

I am trying to figure out how to create a verification email for my users, but I'm having trouble understanding how to connect the UserToken table with the user's id in TypeORM. Can someone provide some guidance on this? @Entity({name: "use ...

Delay the occurrence of a hover effect until the previous effect has finished executing

As I hover over an element, the desired animation is displayed while hiding other elements on the page. The challenge I'm encountering is that if I quickly hover over many divs, the animations queue up and hide the divs sequentially. I want only one ...

The jQuery.addClass() function seems to be malfunctioning

I'm encountering an issue with the addClass() method. For some reason, it's not functioning properly in this scenario: https://jsfiddle.net/0g1Lvk2j/20/ If you scroll to the end and close the last box by clicking on the orange box, the orange b ...

Have you ever encountered an issue with Node.js modules?

I have recently delved into the world of node.js and am encountering some difficulties with modules. Despite copying and pasting code from the official node.js documentation, I continue to run into errors. module.js File /* ----------------------Additi ...

remove an element from a nested array using MongoDB

Greetings everyone! I am currently working on a materials document that contains arrays of articles, each article having an array of details. Here is a snippet from my collection data: { "_id": "62f2404b42556d62e2939466", "code&quo ...

Here's a unique rewritten version: "Achieving a looping carousel with autoplay in Angular 2+ using with

https://i.sstatic.net/MmmOg.jpg Could someone provide recommendations for an image carousel that is compatible with angular 8? I would also like to know how to customize the images inside the carousel specifically for small devices. Thank you in advance! ...

When using Node.js with Mongoose, you will receive a single object value instead of multiple values in an array

data=[{ locId: '332wn', locadetails: [ { loc: 'ny', status: true }, { loc: 'ca', status: null ...

"HTML Parsing with Simple DOM: Dealing with Class Names Containing Spaces

I am currently utilizing PHP Simple HTML DOM to extract elements from the source code of a website (which is not my own). However, when attempting to locate a ul class named "board List", it is not being found. It seems like there may be an issue with spac ...

Perform the action when the button is clicked

I'm struggling with finding a solution to this problem. I have an input field and a submit button. My goal is to update the value of a variable to match the value in the input field when the submit button is clicked. Additionally, I need to execute a ...

The Geolocation API popup on Safari for iOS kept appearing repeatedly

I have successfully implemented a code using the HTML5 Geolocation API to retrieve the user's current position within a mobile website. Although the code functions properly, there is an issue with Safari on iOS. Whenever the page is reloaded, a syste ...

NodeJs fails to fetch collection from MongoDB, resulting in an empty array being returned

I have a NodeJS server with the following setup: const express = require('express') const bodyParser = require('body-parser') const app = express() app.set('view engine', 'ejs') const MongoClient = require('mong ...

What are some ways to adjust the page being served in node.js?

I have set up my server.js file with necessary dependencies and routing for handling POST requests. However, I am looking to dynamically update the webpage served by this server when a POST request is received on /message endpoint. These requests are trigg ...

Retrieve solely the desired element along with its immediate ancestor from a deeply nested document

I've been working with the following Schema Structure. Artist Schema albums:[Albums Schema] Album Schema songs:[Songs Schema] At this point, my goal is to search by a song ID and retrieve the specific song, its parent album, and details about the a ...

Tips for ensuring an HTML element remains within defined boundaries

Currently working on a visualization tool for search algorithms using React, I've encountered a minor issue when moving the start or end nodes. Upon clicking and dragging the mouse across the grid, the nodes adjust accordingly until reaching the grid& ...

Divs with floating left have a complete vertical border on their right side

I would like the first and second divs to have a full height border on their right side while floating left. CSS: div.wrapper { border: 1px solid black; } div.wrapper > div { text-align: center; width: 50px; padding-left: 5px; fl ...

Mongoose Does Not Allow for Duplicate Data Submissions

I'm currently working on a project to develop a basic blog application. Everything works smoothly when submitting content to the database for the first time, but if you try to submit again, Node crashes unexpectedly. I've been struggling to pinpo ...

Floating elements overlapping fixed elements

I am currently in the process of developing a mobile application and encountering an issue with relative divs overlapping the top and bottom headers fixed with a z-index. Despite my attempt to resolve this by adding a z-index to the relative div, the probl ...

Attempting to enlarge logo or image when cursor hovers over it

Seeking to enhance logo/image size when cursor hovers over it, but facing an issue where it enlarges even on areas outside of the image itself - View Example. I followed a tutorial to achieve this effect, and specified the width as 1024x1024 for the logo/i ...

Utilizing NodeJS and Express to enhance the client side for showcasing an uploaded file

My knowledge of nodeJS, AJAX requests, and routing is still in its infancy. After following a tutorial on nodejs and express examples, I managed to get everything working on the server-side. However, I'm facing difficulty displaying the uploaded file ...