-2

The background is appearing for some of my webpages and not for some.

This is my main.css:

html {
    background: url("../images/bg.png") no-repeat center center fixed;
}

I notice webpages with single path eg. localhost:8080/index will have the background but double path eg. localhost:8080/index/register will not have the background.

Thanks in advance.

Jan
  • 2,853
  • 2
  • 21
  • 26
user2833581
  • 61
  • 2
  • 9
  • I think you need to do research on paths here is a website that might help you. https://www.w3schools.com/html/html_filepaths.asp – J.C Jun 02 '19 at 01:14
  • Possible duplicate of [Stylesheet not loaded because of MIME-type](https://stackoverflow.com/questions/48248832/stylesheet-not-loaded-because-of-mime-type) – Jan Jun 02 '19 at 02:11

1 Answers1

0

Relative paths used inside a stylesheet-file are relative to the path of the stylesheet itself. So if the stylesheet-file is working on one page it should also work on other pages.

It could be that your html-files are not loading the stylesheet at all. You should check the dev-tools (network-tab) and see if there are any 404-errors for either the stylesheet or the background-image.

Update:

Refused to apply style from 'path/to/style.css' because its MIME type ('application/json') is not a supported stylesheet MIME type.

This Error/Warning can be the result of stylesheet that was not found (404). You should check the network-tab of the dev-tols for any 404-errors and also check path of the link-tags in your html-documents. If the stylesheet is working for one document in your environment but not for other documents, it could be that your referenced path to the stylsheet is not an absolute path.

But there could be other reasons for this error/warning. There are already questions about that topic on stackoverflow. For example: Stylesheet not loaded because of MIME-type.

Jan
  • 2,853
  • 2
  • 21
  • 26
  • Thank you for you reply. Here is the error 'consumableAdd:1 Refused to apply style from 'http://localhost:8080/consumable/css/main.css' because its MIME type ('application/json') is not a supported stylesheet MIME type, and strict MIME checking is enabled.' – user2833581 Jun 02 '19 at 01:21
  • How do you load/reference the stylesheet in your html-files? What is the path of the stylesheet-file? – Jan Jun 02 '19 at 01:41