Link resources, such as CSS, within the structure of a website

Asked

Viewed 540 times

4

I am a beginner and I am facing problems with linking scripts, CSS and images. I have the following structure in folders of my site, just an example:

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

Assuming all the pages on my site have the same header, then I would have to import all of them CSS cabeçalho.css. For the home page is easy.

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

  • Tip: Seeing someone else’s page source code is essential for learning web programming (every browser has this functionality).

3 answers

6

One way would be using the tag groundwork to set the default url

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

This way the path will be the same as on the page index.html how much in the html register.

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

4


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

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

  • 5

    ". /" is a reference to the file folder itself - not required in this case.

1

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

  • 7

    First, MVC is not a method, but an architecture. Second, MVC has absolutely nothing to do with his problem. It can use other architectures and be required to write in the same way proposed by you.

  • 1

    It’s true! I used method as a more generalized word.But yes MVC is an architecture.

  • I’ve read about MVC, but I’m only in theory, I’m in my first year of Computer Science and I’m in a project to develop a website, if you can help me with links about mvc applied to Html5/php I’ll be grateful, I understand the logic of this architecture, but not how to apply it in general

Browser other questions tagged

You are not signed in. Login or sign up in order to post.