Declined to implement the stylistic elements of

I have been struggling to resolve an issue on my website for the past two days. The browser is not applying the CSS styling to a specific page, while all other pages on the site are working fine with CSS. Here is the code for the problematic page:

<!DOCTYPE html>
<html lang="en">
 <head>
<%include partails/head %>

<link rel="stylesheet"  href="../stylesheets/resultPage.css"/>
</head>
<body>
<% include partails/header %>
<h3 class="h3 mb-3 font-weight-normal text-center" id="title">نتيجة 
الأختبار</h3>
<div class="container">
<div class="row">
<div class="col-md-10">

Additionally, here is the code snippet from my app.js file for uploading the CSS file:

app.use(express.static("public"));
app.set("view engine" , "ejs");
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json())
app.use(methodOverride("_method"));

Furthermore, here is the file path structure where the CSS file is located:

  • Samples10
    • public
      • stylesheets
        • resultPage.css
    • View
      • resultPage.ejs

Lastly, I received the following error message in the browser:

Refused to apply style from 'http://localhost:3000/result/5b31bbcacc2864263d40d240/stylesheets/resultPage.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

If anyone can offer assistance, I would greatly appreciate it. Thank you.

Answer №1

The style from 'http://localhost:3000/result/5b31bbcacc2864263d40d240/stylesheets/resultPage.css' was rejected

Take a look at that URL.

Now check where your static files are located (in the public directory):

app.use(express.static("public"));

Next, locate the CSS file inside the public directory:

public/stylesheets/resultPage.css

Therefore, the correct URL for the stylesheet should be:

http://localhost:3000/stylesheets/resultPage.css

The HTML document is likely at:

http://localhost:3000/result/5b31bbcacc2864263d40d240/something/

… so using your relative URL:

href="../stylesheets/resultPage.css"

… which only moves up one level and leads to the wrong location!

To fix this, use an absolute path starting from the site's root:

href="/stylesheets/resultPage.css"

Answer №2

an error occurred due to incorrectly writing <% include ../partials/head %>

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

Using MongoDB to push elements into nested arrays

Currently, I am working on my food blog and aiming to create a specific structure for the food recipes stored in my database. recipes : [ {mainCategoryRecipe1: {...}}, {mainCategoryRecipe2: {...}}, subcategory1: [ {recipe1: {...}} ] ] I have a for ...

Expanding on the specific properties of a parent component to its child, using SASS's extend feature

Can selected or specific properties be shared/extended from the parent to the child without the need to create a variable? .main-container { padding: 20px; margin: 20px; ul { padding:$parentPadding(); margin: 0; } ...

Disabling a button does not automatically shift the focus to the next element in the tab order

Is there a way to limit the number of times a button can be clicked using jQuery? For example, I want a button that can only be clicked three times before disabling itself automatically. test.html <div class="main"> <input class="one" type="t ...

Node.js web server operating on port 3000 is running a script

I have developed a Node.js script that extracts data from a database and saves it in a file. Additionally, I have set up a Node.js web server listening on port 3000 using forever to keep it running constantly. However, the script currently lacks a web inte ...

Display a linear list organized in a tree format, showcasing instances where children have multiple parents

I am new to Javascript and programming in general. I am working with a list of "step" objects that have a choice/solution field which references another object in the same list. My goal is to create a tree hierarchy based on this field. [ Below is the arr ...

When attempting to retrieve the highWaterMark property of a Node.js stream in TypeScript, an error is thrown stating: "The property '_readableState' does not exist."

I have a query regarding TypeScript and streams in Node.js. I am looking to extend the stream base class to access the highWaterMark option. While the following code works in TypeScript: import * as stream from 'stream'; class ExampleStream ex ...

Issue: The function `this.isModified` is not recognized as a valid function

Encountering an unusual problem. This code snippet is causing an error and it relies on arrow functions UserSchema.pre('save', next => { const SALT_FACTOR = 5; if (!this.isModified('password')) return next(); bcrypt.genSalt ...

Preventing non-breaking spaces and characters from being added in Jquery Mobile

When developing an application using jQuery Mobile, I encountered a strange issue on my homepage. In between the listview, this code snippet appeared: &nbsp;&nbsp;&nbsp;&nbsp; But without the following meta tag: <meta http-equiv="Cont ...

Engaging grid connected to MySQLi database table

I am new to programming and have been diving into the world of PHP and MySQLi. I understand that the task at hand requires more expertise than what I currently possess. My project involves creating a 3x3 grid where only one square per row can be selected. ...

Vue3 - Managing the Enabling and Disabling of Text Input and Checkbox Based on Input Number

<div class="container-body" v-for="index in 10" :key="index"> <div class="container-content"></div> <div class="container-content"> <input :id="'Row&apo ...

When a specific CORS origin is set, but a wildcard is being returned in the response - NodeJS Express CORS()

I'm encountering a frustrating issue. My nodejs server is running with Apollo Server for GraphQL and express for handling web requests. After a successful login in redis via express-session, I set a cookie. I have configured the origin and credential ...

The style attribute transforms the background-image url quotation to become &quot;

I'm currently working on creating a catalog component that will allow me to display images, titles, and descriptions multiple times. Below is the code for this component: import React from "react"; import '../pages/UI.css'; import ...

Unable to collapse the Bootstrap dropdown menu

For the life of me, I can't seem to find a solution to my problem. I'm currently working on creating a responsive navbar for my website by following a tutorial. The goal is to make it mobile-friendly with a button that expands the menu on smaller ...

What is the best way to change the value of a key in a JSON Object?

I am currently utilizing _underscore library. My goal is to change the value of a specific key. var users = [{ "_id": { "$oid":"3426" }, "name":"peeter" }, { "_id": { "$oid":"5a027" }, "name":"ken" }, { "_id": { "$oid":"5999" }, ...

The use of an import statement outside a module in the /node_modules directory is prohibited

As I embark on migrating some node packages, I find myself facing a significant challenge. Here is the current state of my package.json file: { //These are the updated dependencies and Jest configurations "dependencies": { "@google-cloud/logging-w ...

Preserving the jQuery object during an AJAX post操作

When using AJAX calls, I am looking to preserve the datatable object. See the code snippet below: $(function(){ function applyDataTables(options) { //datatable object var $datatable = $("#table1").dataTable(options); ...

Receiving duplicate data on WordPress pages

I have made some changes to my theme page.php: <?php /* The loop */ ?> <?php while ( have_posts() ) : the_post(); ?> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?> > <header class="entry-header"&g ...

Best way to pass a variable from an html form to a php function using ajax

I am currently developing a voting system for multiple uploads where each uploaded image is within a foreach statement. Each image has a form attached to it with three buttons to vote up, down, or not at all. These buttons are associated with an INT value ...

Are there any software solutions similar to Phabricator designed specifically for managing Node.js applications?

Are there any similar tools to Phabricator that are specifically designed for conducting code reviews on Node.js applications? I am seeking ways to enhance our current code review procedures. ...

Change a reactive variable based on an event

I am currently working on a file upload feature in my application. Template.uploadFile.events({ 'change .set-file': function ( event, template ) { var file = event.currentTarget.files[0]; [...] } }); My goal is to read each row fro ...