How to access the file using the relative path - html

I've got the following folder hierarchy in my web application.
I'm using the following relative path to access my CSS files but the layout doesn't detect the CSS. There are two layouts but I'm calling the CSS from the layout file which resides inside the views folder.
This is the path I used to access the CSS file.
<link rel="stylesheet" type="text/css" href="../style/style.css">
I used this path too but no luck.
<link rel="stylesheet" type="text/css" href="../../style/style.css">
Please help!

Check whether you are not using multiple CSS files. And if you are using Chrome/FF you can check whether your CSS is called or not with tools like firebug.
You can see the full path with these tools.

if your layout file loading in another file try that files path or simply use path like this
<head>
<link href="/style/style.css" rel="stylesheet" type="text/css" />
</head>
your real layout can be work like this too
<head>
<link href="style/style.css" rel="stylesheet" type="text/css" />
</head>

You can use this:
<link type="text/css" href="style/style.css" rel="stylesheet" />

The second Path should be correct.
I also tried it in Visual Studio 2010 with the same folders as you and VS gives me the same Path (Second one) as you said.
Another Question, do you put the link into the header of the HTML page ?
<head>
<link href="../../style/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
</body>

Related

CSS style sheet not found

i spent the last hour figuring out why my style sheet is working.
enter image description here
I tried every possible way, but none of it works.
It just shows error 404 when i check it in the developer mode of my browser.
I tried
<link href="style.css" type="text/css" rel="stylesheet" />
<link href="./style.css" type="text/css" rel="stylesheet" />
<link href="../style.css" type="text/css" rel="stylesheet" />
<link href=".../style.css" type="text/css" rel="stylesheet" />
I also placed the the css file in the same file as my header.php.
The path to the css file is a relative path from the file that's called from the browser, and that's most likely not header.php.
If you start the path with a / it's considered relative to the webroot, so you probably want /css/style.css. Note that you cannot go up (using ../) from the webroot.
../ is meant to go back a folder so if my folder layout is
Root
css
style.css
includes
header.php
I have ho down a folder and enter the css folder like:
<link rel="stylesheet" href="../css/style.css">
You are using many link tag to integrate the css file in you html file. You should use one tag and it would be a relative path like the following <link rel="stylesheet" href="/css/style.css">

How do I link my CSS to the HTML file in Github Pages?

I need some help here.. I tried different links but it does not load the CSS file..
<link rel="stylesheet" type="text/css"
href="https://github.com/cengizkirazjs.github.io/cengizkiraz.github.io/styles.css">
This is the page and the outcome: https://cengizkirazjs.github.io/cengizkiraz.github.io/
Any advice? Its my first time linking CSS with HTML on Github!
As it was said in the comments, what do you think about changing file path a bit?
In your code we have this line
<link rel="stylesheet" type="text/css" href="cengizkiraz.github.io/styles.css">
It contains an absolute path. If you want to stick to this method, maybe just add a protocol, like this
<link rel="stylesheet" type="text/css" href="https://cengizkiraz.github.io/styles.css">
But it would be better if you use relative paths
In this case, our <link> will look like this
<link rel="stylesheet" type="text/css" href="styles.css">
It means that HTML will search for this file in folder, where .html file is saved. Looks slightly better, doesn't it?

Using css href online is OK, then download css file and use it locally it is not working at all

So I am working on personal website project. And I am using html template of w3school. They use css file from online source:
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Raleway">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-
awesome.min.css">
Everthing works fine until I download all the css file locally and load them from local position like below:
<link rel="stylesheet" type="text/html" href="./assets/w3.css">
<link rel="stylesheet" type="text/html" href="./assets/google_raleway.css">
<link rel="stylesheet" type="text/html" href="./assets/font_awesome.min.css">
The form of website is totally wrecked after I use local css file instead of online source. I inspect the page and in console, there is no error message on css part. I don't know why it is not working locally.
Just Download all css in one folder.
And get full path of that files.
Example:
You Downloaded Files in below location (i am using D drive(asset folder in D drive) as an example here) of your computer:
D:\assets\w3.css
D:\assets\google_raleway.css
D:\assets\font_awesome.min.css
<link rel="stylesheet" type="text/css" href="D:\assets\w3.css">
<link rel="stylesheet" type="text/css" href="D:\assets\google_raleway.css">
<link rel="stylesheet" type="text/css" href="D:\assets\font_awesome.min.css">
If this works in full path means there is an error in you relative path you given.
So just do small research to set relative path.

How do I specify relative paths for content such as CSS?

When I am linking to any file I have to specify the absolute path looking like this
<link rel="stylesheet" type="text/css"
href="F:/XmppOld/XAMPP2/htdocs/MAIN_SITE_LAYOUT/css/stylemainpage.css" />
I would like to narrow it down to
<link rel="stylesheet" type="text/css" href="/css/stylemainpage.css" />
I'm not sure how to. I tried placing stylemainpage.css inside the page being viewed, but it didn't work.
The path depends on where you have placed your HTML files
HTML
index.html
CSS
style.css
CSS path in your HTML file would be - <link href="../CSS/style.css" rel="stylesheet"/>
Edit: in your case the path should be -
<link href="../css/stylemainpage.css" rel="stylesheet" type="text/css" />
Try using <link rel="stylesheet" type="text/css" href="css/stylemainpage.css"/> (without the leading slash before css)
<link rel="stylesheet" type="text/css" href="css/stylemainpage.css"/>
put your css into css folder
Keep the CSS file and the HTML pgae in the same folder, then just include the CSS filename. If you want to keep the CSS file in some other folder under the same server root and still want to use relative path names, use .. and /. Use .. to move up a level, and / to move down a level.

Firefox can't find external CSS using absolute file path

On my web page I have the following line in the <head> element:
<link type="text/css" href="C:/myApps/app1/images/css/12.02/main.css" rel="stylesheet" />
When I go to view that page in Firefox 11.0, it is obvious that the main.css is not being loaded. If I go to view page source, I see the <link> element (above) in the HTML, but when I click it I get the following error:
Firefox doesn't know how to open this address, because the protocol (c) isn't associated with any program.
How do I fix this?
try:
<link type="text/css" href="file:///C:/myApps/app1/images/css/12.02/main.css" rel="stylesheet" />
might work
Edit: as per the other answers, this is when you want to use a css file on your local machine, if the website will be hosted then you'll need to use a relative path.
<link type="text/css" href="images/css/12.02/main.css" rel="stylesheet" />
The above assumes that your html file with the link in is located in your "app1" folder.
Martyn
you need to insert an url/uri => file:///C:/myApps/app1/images/css/12.02/main.css
Hi you cas change your css path
<link type="text/css" href="C:/myApps/app1/images/css/12.02/main.css" rel="stylesheet" />
into
xxx.css replace into correct path
<link type="text/css" href="xxx.css" rel="stylesheet" />