Position the background image so that it's fixed at the top left and is 100% wide and 100% in height. Add this to your style sheet:
img#bg {
position:fixed;
top:0;
left:0;
width:100%;
height:100%;
}
Add all your content to the page inside of a <div> called "content". Add this below the image:
<div id="content">All your content here - including headers, paragraphs, etc.</div>
Note: it's interesting to look at your page now. The image should display stretched out, but your content is completely missing. Why? Because the background image is 100% in height, and the content division is after the image in the flow of the document — most browsers won't display it.
Position your content so that it's relative and has a z-index of 1. This will bring it above the background image in standards-compliant browsers. Add this to your style sheet:
#content {
position:relative;
z-index:1;
}
But you're not done. Internet Explorer 6 isn't standards compliant and still has some problems. There are many ways to hide the CSS from every browser but IE 6, but the easiest (and least dangerous) is to use conditional comments. Put the following after your style sheet:
...
</style>
<!--[if IE 6]>
<![endif]-->
Inside the highlighted comment, add another style sheet with some styles to get IE 6 to play nice:
<!--[if IE 6]>
<style type="text/css">
html { overflow-y: hidden; }
body { overflow-y: auto; }
img#bg { position:absolute; z-index:-1; }
#content { position:static; }
</style>
<![endif]-->
Mas como disse sou novo e não consegui por para funcionar.
Pergunta
Tarragô
Boa tarde gente,
Sou novo por aqui e não sei nada de programação, por isso me inscrevi, para aprender - rs
Estou tentando desenvolver meu site para poder vender meus serviços que são de design.
Espero que vocês possam me ajudar.
Uma coisa interessante que gostaria de aplicar em meu site seria um Bg randomico como o gmail faz.
O Bg muda a cada refresh de página e o bg é auto ajustavel aos diferentes formatos.
Para isso peguei os seguintes códigos:
BG Radom
<script language="JavaScript">
<!-- Activate cloaking device
var randnum = Math.random();
var inum = 4;
// Change this number to the number of images you are using.
var rand1 = Math.round(randnum * (inum-1)) + 1;
images = new Array
images[1] = "zebra.jpg"
images[2] = "tiler3.jpg"
images[3] = "wicker3.jpg"
images[4] = "aaa4.jpg"
// Ensure you have an array item for every image you are using.
var image = images[rand1]
// Deactivate cloaking device -->
</script>
Use this code in place of the <body> tag:
<script language="JavaScript">
<!-- Activate cloaking device
document.write('<body background="' + image + '" text="white">')
// Deactivate cloaking device -->
</script>
E BG Stretch
<style type="text/css">
html, body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
Add the image you want as the background as the first element of the web page, and give it the id of bg:
<body>
<img src="bgimage.jpg" alt="background image" id="bg" />
</body>
Position the background image so that it's fixed at the top left and is 100% wide and 100% in height. Add this to your style sheet:
img#bg {
position:fixed;
top:0;
left:0;
width:100%;
height:100%;
}
Add all your content to the page inside of a <div> called "content". Add this below the image:
<div id="content">All your content here - including headers, paragraphs, etc.</div>
Note: it's interesting to look at your page now. The image should display stretched out, but your content is completely missing. Why? Because the background image is 100% in height, and the content division is after the image in the flow of the document — most browsers won't display it.
Position your content so that it's relative and has a z-index of 1. This will bring it above the background image in standards-compliant browsers. Add this to your style sheet:
#content {
position:relative;
z-index:1;
}
But you're not done. Internet Explorer 6 isn't standards compliant and still has some problems. There are many ways to hide the CSS from every browser but IE 6, but the easiest (and least dangerous) is to use conditional comments. Put the following after your style sheet:
...
</style>
<!--[if IE 6]>
<![endif]-->
Inside the highlighted comment, add another style sheet with some styles to get IE 6 to play nice:
<!--[if IE 6]>
<style type="text/css">
html { overflow-y: hidden; }
body { overflow-y: auto; }
img#bg { position:absolute; z-index:-1; }
#content { position:static; }
</style>
<![endif]-->
Mas como disse sou novo e não consegui por para funcionar.
Tentei colocar nos lugares sugeridos e nada.
Alguém tem alguma sugestão?
Obrigado.
Link para o comentário
Compartilhar em outros sites
4 respostass a esta questão
Posts Recomendados
Participe da discussão
Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.