External file link explanation
Adding external css file to html doc
html - Linking an external stylesheet - Stack Overflow
Linking to External CSS files
Videos
I feel stupid and like I have taking 3 steps back in my learning. I am trying to figure out the 3 different implementations of css. Doing External now. Just trying this super simple code, the colors did not show up in the browser like they did on w3schools.
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Is it because I don't have a css file on my computer? Do I need to download one? Copy and paste from somewhere? I don't get it. I prefer building with the css and html on the same document because I haven't learned how to do anything else yet. I have been able to follow tutorials fine but for some reason, now it's not clicking.
Once you move your CSS to an external file, you need to remove the HTML tags. CSS has it's own formatting guide lines.
For example, for inline CSS (included in the HTML), you would do:
<html>
<head>
<title>Video Game Reviews</title>
<style>
body {
background-color: rgb(255, 0, 255);
color: black;
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
font-size:16px;
}
</style>
</head>
<body...
But once you move the CSS to an external file, the HTML tags are removed. For example:
HTML file
<html>
<head>
<title>Video Game Reviews</title>
<link rel="stylesheet" type="text/css" href="./mystyle.css">
</head>
<body...
CSS file called mystyle.css
body {
background-color: rgb(255, 0, 255);
color: black;
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
font-size:16px;
}
There a few other things to check for.
If you are referencing mystyle.css like this ./mystyle.css, then the CSS file needs to be in the same folder or directory as the HTML file. That is what the ./ means.
If you store all your utility files (like CSS files) in a single location (something like /rc) you can use a full path like this:
<link rel="stylesheet" type="text/css" href="/rc/mystyle.css">
In this case, the / (no dot) means from the root directory of the website. But that is really a different question.
that's the correct way to do it, however ensure that your file path matches. for your example above, the css file has to be in the same folder as the page you are working on and named correctly.