Why is my CSS file not linking to my HTML file? - html

Here is the path I am working with - /public_html/websystems/websystems.css
The HTML file I am trying to link is in the public_html directory and named index.html
The CSS file I am trying to link is in the websystems directory and named websystems.css
The contents of the files are shown in the images below.
HTML file
CSS file
Why are none of the styles I've set in my CSS file applying to my HTML file?
Thanks for your help.

Try this,
websystems/websystems.css
Note that, (taken from Quick Reminder About File Paths)
Is the image in the same directory as the file referencing it?
Is the image in a directory below?
Is the image in a directory above?
By "below" and "above", I mean subdirectories and parent directories.
Relative file paths give us a way to travel in both directions. Take a
look at my primitive example:
Here is all you need to know about relative file paths:
Starting with "/" returns to the root directory and starts there
Starting with "../" moves one directory backwards and starts there
Starting with "../../" moves two directories backwards and starts there (and so on...)
To move forward, just start with the first subdirectory and keep moving forward

Change the /websystems/websystems.css to just websystems/websystems.css and see if that works. That's a path relative to the current path of index.html.

Related

HTML path to the CSS file doesn't work without two dots

I want the path to the file to look like this: "/assets/style/home.css"
But even though VSCode recognizes this path, and takes me there when I click it, the CSS doesn't appear on the page. It only appears when the path has the two dots: "../assets/style/home.css"
Any ideas on how can I fix this? This is what the entire path looks like:
It's like that with every single path I use in this project, actually. I have to use the two dots for everything.
The "../" means that it is to return a directory, as your HTML file is inside the PAGES directory it is necessary to use the "../".
To call the css file like this "/assets/style/home.css" you need to move the assets folder into the PAGES folder
The "../" before the file path is used to move up one directory level. It seems that the HTML file linking to the CSS file is in a subdirectory and the CSS file is in a directory one level up. If you want to use the path "/assets/style/home.css" the file should be in the same directory as the HTML file or a subdirectory of the HTML file.
You could also consider using absolute path instead of relative path, it would work regardless of where the HTML file is.
Upvote if it helps.
Your code should work if RANDOMWEBSITE is the root folder of the web server.
It will work in VSCode if you open the folder RANDOMWEBSITE, but perhaps your webserver is configured to use a different root folder above your directory.
For example the root folder might be html, and your website is at html/RANDOMWEBSITE/. In this case it would look for the css file in html/assets/style/home.css, rather than html/RANDOMWEBSITE/assets/style/home.css.
Check what the root folder of the webserver is set to and reconfigure, or alternativly remove the RANDOMWEBSITE folder from your folder tree and work within the existing root folder.
You have to do that because .html is isn't "in the same line" as css. You can imagine that it's something like a crossroad if turn right but then you realise that you want to go left firstly you have to go back and than you can turn left. If you want do do "/assets/etc" you need to move you .html file to "randomwebsite/.html"

Relative File Path For a Picture

I have a problem with relative file paths. I wrote this line:
<img src="\bootstrap\Rezepte\GrilledFruitKebab.jpg">
It's not showing the picture, so I wanted to ask if anyone of you can help me.
The whole file path is:
C:\Users\if160109\Downloads\bootstrap-20171222T093142Z-001\bootstrap\Rezepte
The file path of my HTML file:
C:\Users\if160109\Downloads\bootstrap-20171222T093142Z-001\bootstrap\startbootstrap-blog-post-gh-pages\index.html
(I'm working on Windows)
Thank you for reading
(Sry if I'm doing any mistakes, but this is the first questions I ever asked here)
Try, <img src="../../Rezepte/GrilledFruitKebab.jpg">
Remember,
Is the image in the same directory as the file referencing it?
Is the image in a directory below?
Is the image in a directory above?
By "below" and "above", I mean subdirectories and parent directories. Relative file paths give us a way to travel in both directions. Take a look at my primitive example:
Here is all you need to know about relative file paths:
Starting with "/" returns to the root directory and starts there
Starting with "../" moves one directory backwards and starts there
Starting with "../../" moves two directories backwards and starts
there (and so on...)
To move forward, just start with the first subdirectory and keep
moving forward
Given your directory structure, the correct path would be
../Rezepte/GrilledFruitKebab.jpg
Because the Rezepte directory is a level above where your html lives.
Try change the \ to / and remove the first /
Because this symbol in the first position will take the picture in your root folder. Or look the permission of the image.
You can see more about this here:
Here is all you need to know about relative file paths:
Quick Reminder About File Path
Starting with "/" returns to the root directory and starts there
Starting with "../" moves one directory backwards and starts there
Starting with "../../" moves two directories backwards and starts there (and so on...)
To move forward, just start with the first subdirectory and keep moving forward
or HTML File Paths

CSS Code: Background image not working

I have made a HTML website connected with a CSS.
body{
background-image: url("imag.jpg");
}
When I run my code, why wouldn't the image show up? As my background image. I have tripled checked all the spelling and the file format of my image.
Does anyone know why the background image won't show up?
The problem is your image is not on the CSS folder. If that line of code is in your style.css file, then its reading from that folder,
if the picture is in another folder then you go for example:
background-image: url("../img/imag.jpg");
Is the image in the same directory as the file referencing it?
Is the image in a directory below?
Is the image in a directory above?
By "below" and "above", I mean subdirectories and parent directories. Relative file paths give us a way to travel in both directions. Take a look at my primitive example:
Here is all you need to know about relative file paths:
Starting with "/" returns to the root directory and starts there
Starting with "../" moves one directory backwards and starts there
Starting with "../../" moves two directories backwards and starts
there (and so on...)
To move forward, just start with the first subdirectory and keep
moving forward

Html root path isn't correct

I have a problem in my html pages
when I use "root-relative" paths it isn't make the path correctly
instead of direct to the folder of index.html it direct to the father folder.
Example:
My index.html is: Websites/MySite/index.html
when I make a link in index.html to "/" it direct me to Websites/
what is the problem?
Root is the first folder that your work begins. Your site root is actually Websites/. So it acts correct. Maybe some hosts consider the folder that your html file is on it as root. If you want to have no problem with this, you should make all relative links work with your main root.
There is a php function that gives your current html file path. You can use it before your links. like:
<?php php_function ?>/mylink
The root path is a setting in the server config. If you want to reach something relative to your index.html than you would use ./ and ../
You can go back with ../ and stay in the directory with ./ where the file you are using is in.
For example if you want to reach the file
Websites/someFile.txt
from your index.html in
Websites/MySite/index.html
you would have to use the relative path
../someFile.txt
and if you wanted to use the file
Websites/MySite/subDirectory/some.css
from the same index.html you would write
./subDirectory/some.css
I hope that helps, if not feel free to ask, or make you question more precise.
And if you want to read more about relative url's you can visit the mozilla develop network ("Going back in the directory tree")

How to use a relative path to link to another local file?

This is a very basic html question, but I can't seem to locate the answer.
I have a local file located here:
/Users/Me/Desktop/Main/June/foo.txt
In an .html document located within the /Main directory, I can link to the foo.txt file using the full path:
Full Path Link
I would like to use relative paths to link to foo.txt. Does anyone know how to create a relative path link to this foo.txt file?
I tried the code below and a number of similar permutations, but I can't seem to successfully write the relative path link for this local file.
Relative path Link
Remove the file:/// part to have just ../June/foo.txt.
This should help you out.
If you simply drag your file from the solution explorer into the razor/html page, it will create for you everything you need.