css dilemma(large backgrounds)
I'm using a large background in <body>
tag and I wa开发者_如何转开发nt to make a container div with a width of 960px.
I want the container div to be positioned 15px down from the top, I guess i have to use position:absolute.
My dilemma is; the rest of the div's inside the container have to contain the same position or i could continue this like an normal 960px wide website?
Sorry for my bad english.
Please help me!
This should give your container a 960px width and center it with a 10px top (and bottom!) margin.
#container {
width: 960 px; /* set width for container */
margin: 10px auto; /* 10px top and bottom, center screen */
}
You don't have to use absolute positioning. A simple
body {margin: 0; padding: 0}
#container {width: 960px; margin: 15px 0 0;} /* or margin: 15px auto 0 */ if you want it centered
will do :)
You do not need to use position:absolute;
what that does is puts a div in a specific place on the page irrleevant of broswer window size which isn't what you want in this instance,
What you need is simply a margin-top:$$px;
If you are using an id
use the #
identifier:
#container {
margin-top:15px;
width:960px;
}
If you are using a class
use the .
identifier:
.container {
margin-top:15px;
width:960px;
{
All div
s within this tag can be written and position as they normally would, no extra padding
or margin
s necessary.
精彩评论