What are these two dots at the beginning of a CSS URL?

Asked

Viewed 372 times

0

I created a css sheet, linked to html to format it, after many attempts the code only accept formatting after I left it so:

h1 {
    background-image: url(../img/sobre-background.jpg);
}

however I do not understand the 2 points at the beginning, and there is no folder or path with these 2 points!!

3 answers

3


The ../ back 1 level in the directory tree, as well as ../../ back 2 levels etc.

The way url(../img/sobre-background.jpg) will search the file sobre-background.jpg inside the briefcase img within the mother folder of the document folder that is calling the file.

inserir a descrição da imagem aqui

1

The colon is to indicate that a level will descend in the folder hierarchy.

Probably your css is in a css folder:

css

css file.

index.html

img

jpg image.

when you give the command ../ you indicate that you are going down a level in the folder and going in the folder img.

1

That’s called a way (path) relative!

What have you done (url(../img/sobre-background.jpg)) will consider the image in the previous directory.

Suppose you have the following directory structure:

  • main directory
    • index.html
    • css
      • main css.
    • img
      • over-background.jpg

If you use the two dots in a CSS url, it means that it will return a directory.

To learn more, I suggest you read:
-> http://www.nce.ufrj.br/ginape/cursohtml/conteudo/ligacoes/absrel.htm

Browser other questions tagged

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