Busca avançada Meus favoritos Como criar site grátis em PHP, HTML, CSS, JS ...
Postes RECENTES
Iremos aprender neste mini tutorial como inserir imagem como background usando o CSS.
O código para inserir uma imagem como background é esse aqui:
<style type="text/css">
body { background-image: url("/images/css.gif");}
</style>
Por padrão a imagem de background irá repetir na vertical e na horizontal. Para impedir que a imagem de background, ou de fundo, se repetir usamos esse código:
<style type="text/css">
body { background-image: url("/images/css.gif");}
background-repeat: no-repeat;
</style>
Desta forma a imagem irá aparecer uma única vez.
Para a imagem de background repetir somente na vertical o código é esse aqui:
<style type="text/css">
body { background-image: url("/images/css.gif");}
background-repeat: repeat-y;
</style>
Para a imagem de background repetir somente na horizontal o código é esse aqui:
<style type="text/css">
body { background-image: url("/images/css.gif");}
background-repeat: repeat-x;
</style>
Podemos ainda posicionar a imagem de background facilmente com css. Vamos posicionar o background no canto superior direito:
<style type="text/css">
body { background-image: url("/images/css.gif");}
background-repeat: no-repeat;
background-position: top right;
</style>
A imagem de foi posicionada no canto superior da margem direita.
Podemos ainda posicionar a imagem a uma certa distância das margens, para fazer isso usamos o código:
<style type="text/css">
body { background-image: url("/images/css.gif");}
background-repeat: no-repeat;
background-position: 250px 50px;
</style>
Com o código acima a imagem de background ficou posicionada 250px da margem esquerda e 50px da margem superior.
Com css podemos fixar a imagem de background na tela. Com a imagem fixa, ao usarmos o scroll a imagem não "rola" junto com a página, veja:
<style type="text/css">
body { background-image: url("/images/css.gif");}
background-repeat: no-repeat;
background-attachment: fixed;
</style>
Para a imagem "rolar" junto com a página não há necessidade de usar o código: background-attachment: scroll uma vez que esse é o padrão.
background-image
background-repeat
background-position
background-attachment
Até a próxima, qualquer dúvida use os comentários para perguntar.
DEIXE SEU COMENTÁRIO