Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linking CSS File on a HTML Document In Same Directory On my Hard Disk (Windows)

Tags:

html

css

windows

I am using Windows (7) trying to create an offline html page that should link to a separate CSS file located in same directory. I tried to use

<link rel="stylesheet" type="text/css" href="/styles.css"  />

but no luck.

And I also want to import another css file named styles2.css within style.css. Didn't check yet but putting @import "style2.css"; on style.css may be not work as well. I can use absolute links like C:\Users\ELITEBOOK\Desktop\offline\style.css but it won't work if I move the folder anywhere else from Desktop. Any help? I mean, any code that calls/adds the link of the folder?

like image 232
Sahriar Saikat Avatar asked Nov 11 '14 18:11

Sahriar Saikat


People also ask

How do I reference a CSS file in the same folder?

If both HTML and CSS files are in the same folder, enter only the file name. Otherwise, include the folder name in which you store the CSS file. media – describes the type of media the CSS styles are optimized for. In this example, we put screen as the attribute value to imply its use for computer screens.

How do I link CSS to same file in HTML?

CSS can be added to HTML documents in 3 ways: Inline - by using the style attribute inside HTML elements. Internal - by using a <style> element in the <head> section. External - by using a <link> element to link to an external CSS file.

Can you have CSS and HTML in the same file?

CSS and HTML are best kept separate so that the CSS is uniformly accessible to all pages on a site, not just the document it is included in. Integrating CSS into webpages is an inefficient way to style a site.

Should CSS file be stored in base folder?

I always tend to store my css in directories under the root folder. Which would contain all my ie6 specific overrides. It is all personal preference though, pick whichever style suits you.


1 Answers

Use <link rel="stylesheet" type="text/css" href="./styles.css" /> instead. Note: href="/styles.css" changed to href="./styles.css", which is current directory of your script.

like image 171
Damilola Olowookere Avatar answered Oct 25 '22 09:10

Damilola Olowookere