Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html not linking css

I'm having an issue with linking html and Css and have no idea why. I'm doing everything like the book and tutorials says. However, I'm not getting to do the external configuration of css.

This is the code(just a test):

<!DOCTYPE html>
<html lang = "eng">
    <head>
        <meta name="viewport" content="width=device-width; initial-scale=1.0">

        <title>title</title>
        <meta name="description" content="">
        <meta name="keywords" content="">

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

    <body>
        <h1>test</h1>
    </body>
</html>

and CSS:

body {
    background-color:#CCCCCC;
}

h1 {
    color:#0000EE;
}

Maybe I miss something, because when I do internal css (within my html code with ) it goes ok and the web browser is able to read that. It seems like the html is not linked with css, but it's even on the same folder so the path shouldn't be the problem.

I'm using Linux and Aptana Studio.

I've searched a lot the last 2 hours and cannot find where the mistake is.

like image 997
Telmo Vaz Avatar asked Aug 24 '13 20:08

Telmo Vaz


4 Answers

I invite you to read this article Absolute and Relative Paths

Then we pass to your code:

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

Should be :

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

Your styles.css should be in the same folder as your html file.

To verify that you have an error , check Console of your browser,you will be noticed that your file doesn't exist(404 error).

An other way to make your css working is to integrate it inside your page without separation:

Example:

 <style type='text/css'>

    body {
        background-color:#CCCCCC;
   }

    h1 {
        color:#0000EE;
    }
</style>
like image 194
Charaf JRA Avatar answered Oct 25 '22 20:10

Charaf JRA


If the other suggestions don't work, you can try re-saving the HTML and CSS sheets with "UTF-8" encoding and declare UTF-8 encoding in the HTML under the <head> with <meta charset="utf-8>"

like image 31
Jeff Avatar answered Oct 25 '22 19:10

Jeff


The rel attribute should just have stylesheet in it, singular not plural as well

like image 2
Stuart Miller Avatar answered Oct 25 '22 21:10

Stuart Miller


I had the same problem correct the correct directory structure solved my problem. This is a good visualiton on how to organize your directory structure.

http://rosebusch.net/jeff/miscellaneous/tree.html

That is, the index.html folder is on the same level as the CSS folder. If you want to put index.html in a HTML folder, to link to the CSS folder you would have to backout first by linking href="../css/stylesheet.css". The ".." will take you up a level.

like image 2
Taranjit Randhawa Avatar answered Oct 25 '22 20:10

Taranjit Randhawa