Question:
help with my html and css files not wanting to link to each other?
ariel
2017-11-29 13:35:23 UTC
okay, I ve been messing with this for over an hour and i cant seem to find a solution. when i try and add a css file to my html file it just wont work. I m using notepad++ and i think I ve checked for any typos and that not the problem either. this is the code im using to link my html to me css is it wrong and or does it need changed?






this is the title

Three answers:
Chris
2017-11-29 15:23:48 UTC
If your stylesheet is called "main.css" and stored in the same folder as your html file, it should be linked. You can easily check that by pressing Ctrl+U while looking at the web page, then clicking the href part of your . You should see the stylesheet.



However I've once had somebody screw up the rules in their CSS code, which led them to believe they hadn't linked correctly. So how about you show us some of your content and a few of the rules you wrote, so we can exclude that possibility?
Robert J
2017-11-29 14:47:57 UTC
The critical part is the layout or relative locations of files on the web server, or relative to whatever directory your html file is in on your PC.



That location is the "zero reference" for want of a better name, for all other files used in a page or that in any way link to it.



Your css link in the html section does not include any kind of directory path, just the filename. That means the main.css file must be in the same location (directory / folder) as the html file that uses it.



If you were trying to store it in a css directory located in the same place as the html file, the href would become "css/main.css"



If it was a parallel folder, as in the html files are in one directory and css in another, both in the same parent, then the href would be



"../css/main.css"

[double dot mean "parent of"; up a level in the directory structure from wherever you are].



Also be very careful to match filename and extension case - windows & windows programs don't care about mixing upper and lowercase in filenames but most other systems - and specifically normal web servers - are case-sensitive and everything must match perfectly.
cpcii
2017-11-29 13:59:03 UTC
Make sure that main.css is in the same directory as the html file. Make sure its main.css and not Main.css (depending upon server case matters so always use the same case regardless of OS). Add type ="text/css" also to your link. Other than that, hard to tell you what could be wrong without seeing more information.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...