I am facing difficulty in implementing external CSS in my HTML document

I am encountering an error in the browser console, could someone please explain what it means?This is a screenshot of the HTML file displaying the error.

https://i.sstatic.net/8Y7Ri.png

Currently, I am working on a web page using Bootstrap. I have included the Bootstrap CSS and my own CSS within the "head" tag. Here is the code-

 <head>


     <!-- Required meta tags -->
     <meta charset="utf-8">
     <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!--Bootstrap css-->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

      <title>
        first web page using bootstrap
      </title>
<!-- Font awesome for brand name-->
      <link href="https://fonts.googleapis.com/css?family=Permanent+Marker&display=swap" rel="stylesheet"> 

      <!--Our CSS-->
      <link rel="stylesheet" href="CSS\style.css" >

  </head> 

Below is the CSS code I have added:

.mybanner{

  background-color: rgb(12, 8, 5);
  text-align: center;
}


.mybg{

  background-color: rgb(161, 86, 86);
}

.other{
  width: 30px;
 height: 30px;

}

The complete code including the HTML, CSS, and Bootstrap components have been included. However, the classes do not seem to be working as expected. Please provide some guidance on where the issue may lie. Thank you.

Answer №1

To navigate from the current html folder, use ".." to go up one level, then specify the folder to enter, which is /CSS/. Finally, select the file style.css like this:

<link rel="stylesheet" href="../CSS/style.css" />

Answer №2

Kindly make this exchange:

 <link rel="stylesheet" href="CSS\style.css" >

Replace with:

 <link rel="stylesheet" href="../CSS/style.css" >

UPDATE: As @renaldo-balaj mentioned, since you are inside an HTML folder, you must use ../ to move up a level in your folder structure before accessing the CSS folder and retrieving styles.css

Additionally, note that you mistakenly used \

UPDATE 29/11:

I have removed the unnecessary HTML to demonstrate that the solution is correct. Perhaps the implementation is not correct on your end. There are already numerous posts on the same relative path issues, so this post should be closed due to redundancy and lack of context.

<!DOCTYPE html>
<html lang="en">
  <head>


     <!-- Required meta tags -->
     <meta charset="utf-8">
     <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

      <title>
        first web page using bootstrap
      </title>

      <!--Our CSS-->
      <link rel="stylesheet" href="../CSS/style.css" >
  </head> 
<body>

</body>
</html>
body {
    background-color: black;
}

Folder Structure:

Project
│ 
│   
├───CSS
│       style.css
│       
└───HTML
        index.html

Allow me to elaborate on the issue further.

\ backslashes are not used in file paths, as mentioned in @birspider's answer and supported by the HTML validator.

Your index.html is located in an HTML folder, which is unconventional for a static website. Therefore, unless your CSS file is in the same directory as the HTML file, you need to utilize ../ to move out of the HTML folder, followed by /CSS to access your CSS folder, and finally /style.css to fetch the style.css file to display it correctly.

Your DevTools console would have indicated where it was attempting to locate the file, aiding you in debugging.

Please consider closing this post and selecting a solution.

Here is an image from my browser showing that the background-color: black; is functioning from the style.css file: https://ibb.co/ys1Kvvt

Answer №3

Looks like there are some issues with your HTML markup:

Why not give a try? It will help you identify the errors, such as:

Error: Bad value CSS\style.css for attribute href on 
element link: Backslash ("\") used as path segment delimiter.

At line 20
   <link rel="stylesheet" href="CSS\style.css" >

---

Error: Bad value ../Image\unsplash.jpg for attribute src on 
element img: Backslash ("\") used as path segment delimiter.

At line 84
          <img src="../Image\unsplash.jpg"  alt="Los Angeles" style="width:100%;">↩  

---

Error: Duplicate attribute class.

At line 124

ass="row" class="mybanner" sty

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

Expanding and collapsing all elements with Angular Bootstrap 4's collapse feature

How can I make only one item in my ngFor expand and close using the Bootstrap 4 collapse component? This is the code implementation: <div class="card-footer account clickthrough" *ngFor="let attachment of item.attachments; let j=index" (click)="isColl ...

Is there a way to implement the border-box property for Internet Explorer versions 6 and

Similar Question: How to implement box-sizing in IE7 Anyone know a method or workaround to apply box-sizing:border-box; in IE6 and IE7? Even just for IE7? ...

Struggling to ensure buttons on my page respond and resize properly alongside the other elements

Despite making most of this page responsive, I'm having trouble getting the two buttons to scale appropriately. They are utilizing javascript for a mouseover effect, and I suspect that might be causing some issues. Ideally, I would like the images to ...

``Text Aligns Perfectly in the Middle Horizontally, yet Shifts Slightly Off-C

Two rectangular divs were created, each measuring 60px wide and 150px tall with text inside. The goal was to align the text vertically within the rectangles, achieved by using transform: rotate(-90deg). The challenge arose when trying to center the vertic ...

Changing the color of an element on click using jQuery's .css() method,

There is a table and I am using fadeToggle on the list to hide and show the table. The background of the list is green color, but I want to change the list color when hiding the table and revert it back to green when clicking to show the table. Unfortunate ...

Ways to position an element at the edge of the browser either on the left or right side when the image is not in a centered container

Looking to create a unique layout that involves: Utilizing a three-column structure Incorporating a div element that spans two columns Positioning an image within the two-column div so that it extends to the left edge of the browser window while staying ...

Choose with text partially aligned on the right side

Is there a way to align a portion of the option's text to the right? Below, you will see a select element with names on the left and "(vertical)" on the right. I want to move "(vertical)" to the right side. Is it possible to achieve this? https://i. ...

I want to show error messages using jquery only when the username or password is entered incorrectly. How can this be achieved?

document.getElementById("buttonClick").addEventListener("click", mouseOverClick); function mouseOverClick(){ document.getElementById("buttonClick").style.color = "blue"; } $("#buttonClick").hover(function() { $(this).css('cursor',&apos ...

Expanding Viewports with Dynamic Scrolling Bootstrap Columns

Striving to achieve a specific design in Bootstrap, but hitting roadblocks. The criteria are as follows: No scrolling in the browser window. Display occupying 100% of browser height. Columns for Menu, Left contents, and Right contents must scroll indepen ...

Ways to modify the header dimensions using CSS

I've been trying to figure this out, but I can't find a solution. For the structure, I'd like to use an h2 header to make it more semantic, but I want it to appear as an h5 header visually. However, CSS is not cooperating with this idea an ...

Styling a div to wrap around an image

I'm working with an image element that has the style attribute set to style='width:40%;height:40%'. My goal is to add a div around this image that will automatically adjust its size to wrap around the image. However, when I try inserting the ...

Text randomly appears on the html page

I've been dedicating a significant amount of time to finding a solution, but haven't had any luck. I'm aiming to create a visual effect where 10 words with varying font sizes slide in from different directions on a canvas within my document ...

The background color spills outside the column when using 100% width

Bootstrap 5 is being used, and two columns have been created on the page. The current output looks like this: https://i.stack.imgur.com/P6oZs.png Now, there's a need to display an orange color from end to end of the left column. To achieve this, h- ...

Creating a sliding bottom border effect with CSS when clicked

Is there a way to animate the sliding of the bottom border of a menu item when clicked on? Check out the code below: HTML - <div class="menu"> <div class="menu-item active">menu 1</div> <div class="menu-item">menu 2</ ...

Button with small width containing an icon and text

I am trying to create a simple HTML button that has an icon on top and a description below it. <div class="mybtn"> <div><img src="someimage.png"></div> <div>Button description</div> </div> My question is, ...

Change the width of the webpage inside the iframe

I am working with an iframe that has a fixed width and height of 400px. I want to load a web page in the iframe, but I need to adjust the width of the source to fit my iframe perfectly. The height is not an issue as I can add a scrollbar if needed. Here ...

Having trouble getting your Bootstrap v4 carousel to function properly?

Currently, I have implemented the carousel feature from Bootstrap v4 in a Vue web application. I am following the same structure as shown in the sample example provided by Bootstrap, but unfortunately, it is not functioning correctly on my local setup and ...

the neighboring div sliding to the left causing the div not to expand with its content

I am trying to create a website similar to this one. When I click on the arrow, the left div collapses and the right one expands. However, the content of the right div does not expand as expected! Below is my HTML code: <div class="tools-bg"> & ...

jQuery - Modify Turn.js to exclusively implement the page Peel effect

I am attempting to implement the peel effect from turn.js into my code, where hovering over the bottom right corner of the page causes it to peel slightly and appear as if it is bending upwards. I specifically want only the peel effect and not the entire ...

Emphasize the checkbox

In my table, I have radio buttons that should turn the neighboring cell green when clicked. Using JQuery, I added a "highlight" class on $.change event to achieve this effect. However, I encountered an issue where some radio buttons load with the "checked ...