Linking resources, such as CSS, within the structure of a site

4

I'm a beginner and I'm having trouble linking scripts, CSS, and images. I have the following structure in my site folders, just an example:

- Pasta Raiz    
  --cadastro  
    --- cadastro.html
  --images  
    --- icon.png  
  --script  
    --- script.js  
  --style  
    --- cabecalho.css
  index.html

Assuming all the pages in my site have the same header, then I would have to import all of the CSS cabeçalho.css to them. For the homepage it's easy.

But to call this same css on page cadastro.html ? In my view, for cadastro.html style cabecalho.css does not exist, wanted to know how to link them, because it's a complete clutter to leave all your pages in the root folder.

    
asked by anonymous 24.06.2014 / 21:03

3 answers

4
<link rel="stylesheet" type="text/css" href="./style/cabecalho.css"> 
<link rel="stylesheet" type="text/css" href="../style/cabecalho.css">

The first one starts the path from the root folder and the second from the previous level, but are equivalent in your case.

    
24.06.2014 / 21:14
6

One way would be to use the base tag to set the default url

<head>
<base href="http://meu-dominio/">
<link rel="stylesheet" type="text/css" href="style/cabecalho.css">
</head>

In this way the path will be the same both on the index.html and the profile.html

<link rel="stylesheet" type="text/css" href="http://meu-dominio/style/cabecalho.css">
    
24.06.2014 / 21:36
1

As you probably do not work with the MVC method you will be required to write ../style/cabecalho.css , already in the index it is only to use style/cabecalho.css ;

    
24.06.2014 / 21:11