HTML not loading CSS file

前端 未结 25 1396
执念已碎
执念已碎 2020-12-01 13:55

I am completely stumped as to why this doesn\'t work. It seems the HTML file can\'t load the CSS for some reason, even though both are in the same directory. Any idea what m

25条回答
  •  栀梦
    栀梦 (楼主)
    2020-12-01 14:40

    Also make sure your link tag's media attribute has a valid value, in my case, I was using WordPress CMS and passed the boolean value true in the media field so it showed like that.

    
    

    That's why it was giving error. There are three main attributes on which the css style loading depends.

    1. Make sure that your link tag's relation rel attribute's value must be valid for a css file i.e. stylesheet.
    2. Make sure that your link tag's target href attribute's value must be pointing to a valid an existing Cascading Stylesheet file. Like in your case it's ./style.css.

      Remember that you can use both absolute and relative paths in the href attribute's value. That means if your file style.css is present at the root i.e. / then you can also use /style.css in the href attribute's value or else if the file is present in the same directory in which your HTML file is present then you can use ./style.css as the value in your link tag's href attribute's value.
    3. Make sure that your link tag's media attribute should be one of the following.
      1. For every device you can use the all keyword as your media attributes's value.
      2. For PC's and laptops only you can use the screen as your media attribute's value.
      3. For webpage prints you can use the print keyword as your media attributes's value. Note that it also applies when you press the Print Screen button to capture the screen's image.
      4. At last for screen readers you can use the speech keyword as your `media attribute's value.

    By following these rules your HTML structure for link tag will be.

提交回复
热议问题