I’m working in a Web Application and I ran into an issue relating the <link> element in HTML. Basically, I tried to link my styless.css folder but the style was not applying on the live server.
This is my HTML file:
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<title>Menu - Café</title>
<meta charset="utf-8">
<!-- STYLE -->
<link rel="stylesheet" href="styles.css">
</head>
<body>
<main>
<h1>Mon-Café</h1>
<p>Est. 2019</p>
<!-- SECTION: Cafés -->
<section>
<h2>Cafés</h2>
</section>
<!-- SECTION: Sobremesas -->
<section>
</section>
</main>
</body>
</html>
And this was my CSS file before any changes:
h1, h2, p {
text-align: center;
}
I tried editing the CSS file directly into Firefox Developer, these were my exact steps:
- Inspect Element
- Go to Style Editor
- Manually insert the code:
h1, h2, p {
text-align: center;
}
As soon as I wrote that directly with Firefox Developer, it worked just fine, but with my styles.css file it was not working, only when there was a single element instead of multiple
Then I tried another alternative for my CSS file:
h1, h2, p , .box{
text-align: center;
}
I found about the .box ramdonly while searching for a fix for this, but that alternative worked just fine in the styles.css file, I don’t know if that’s the correct way or if I was doing something wrong the other way.
PS: I save my project multiple times so it can’t be that
2
Answers
I would start by looking at the path linking your CSS file. VSCODE makes it easy for you to check the path leading to your CSS file.
./
refers to the current directory.../
refers to the parent directory<link rel="stylesheet" href="./styles/styles.css">
A. Right-click and click on the file
B. Click on the Copy Relative Path Option
C. Paste it right in the href tag
Ensure that the path to your styles.css file is correct relative to the HTML file. If the stylesheet is in the same directory as your HTML file, the path you provided should work. If it’s in a different directory, you need to adjust the path accordingly.