Search code examples
htmlcssimportstylesheet

@import doesn't seem to work even though I have the correct setup


I'm trying to import multiple css files into my html using @import but for some reason it doesn't work. A tree of my project looks something like this:

root
--assets
----css
------body.css
------main.css
--index.html

My main.css looks like this: @import "body.css";

I put this line in the header in the index <link rel="stylesheet" type="text/css" href="css/main.css">

And for some reason the styles in my body.css aren't showing up.

I did recently get a new laptop, is there any configuration/download I need to do that I just forgot needs to be done?


Solution

  • I guess the solution to this would be to use <link rel="stylesheet" type="text/css" href="assets/css/main.css">

    Also on how to find such issues the next time: Press F12 in your browser, navigate to the network tab and reload your site. If you see a red entry there it means it couldn't be loaded (or there were other errors with it)

    If it's a 404 error (like Failed to load resource: net::ERR_FILE_NOT_FOUND )this is your hint that it literally can't find the file. in 99.9999% it's a wrong url. You can even copy-paste the URL and open it on it's own.