/    Sign up×
Community /Pin to ProfileBookmark

centering an absolutely positioned site?

Hi! I’m still a newbie to the whole CSS thing, so bear with me please.
[URL=http://www.team847.com/]This site[/URL] uses the best of my CSS abilities, but I need a little help.
I know it is hard to center things in CSS, but how do I center the site I made?
Just FYI, I use a strict html 4.01 doctype and my pages validate (except the photo gallery, I’ll be working on that later).

Thanks alot!

=edit=

oh, and if anyone has suggestions as to the color scheme, let me know!

thanks again

to post a comment
CSS

7 Comments(s)

Copy linkTweet thisAlerts:
@FangJan 11.2006 — Wrapp a div (#container) around the 'site', add/change:html, body {
background-color: #636163;
color: #ffc308;
font-family: veranda, arial, sans-serif;
font-size: 10pt;
height: 100%;
text-align: [COLOR=Green]center[/COLOR];
width: 100%;
}
* {
border: 0;
margin: 0;
padding: 0;
}
[COLOR=Green]#container {
position:relative;
margin:0 auto;
width:700px;
text-align:left;
}[/COLOR]


btw the universal selector slows the parser, apply the css only where it's required.
Copy linkTweet thisAlerts:
@NogDogJan 11.2006 — I played around with it and came up with the following CSS file. The only change you need to make to the html is to wrap all the content in a <div id="container>...(content)...</div> set of tags. By use of margins and floats, I was able to get rid of all the absolute positioning, which allows the page to adjust better to font resizes by the user.

CSS:
<i>
</i>html, body {
background-color: #636163;
color: #ffc308;
font-family: veranda, arial, sans-serif;
font-size: 10pt;
height: 100%;
text-align: left;
width: 100%;
}
* {
border: 0;
margin: 0;
padding: 0;
}
#container {
width: 704px;
margin: 10px auto;
padding: 0;
}
#banner {
border: 2px #ffc308 solid;
color: #ff0000;
height: 100px;
left: 10px;
width: 700px;
background-color:#000000;
}
#banner .banner_img {
width:700px;
height:100px;
}
#navigation {
background-color: #000000;
color:#ffc308;
border: 2px #ffc308 solid;
text-align: center;
margin: 10px 0;
padding: 3px;
}
#navigation li {
display: inline;
list-style-type: none;
margin: 0 5px
}
#navigation A:link, #navigation A:visited {
background-color: #000000;
color: #ff9900;
font-size: 10pt;
text-decoration: none
}
#navigation A:hover, #navigation A:active {
background-color: #000000;
color: #ef7518;
font-size: 10pt;
text-decoration: none
}
#main {
background-color: #000000;
border: 2px #ffc308 solid;
color:#ffc308;
height: auto;
left: 10px;
padding: 3px 5px 3px 5px;
float: left;
width: 575px;
}
#main h3 {
background-color: #ffc308;
color: #000000;
font-size: 10pt;
font-weight: bold;
margin-bottom: 0;
padding-left: 10px;
}
/* --- all paragraphs except bottom --- */
#main .article1 {
background-color: #333333;
color: #ffc308;
height: auto;
margin-bottom: 15px;
margin-top: 0;
padding: 3px 5px;
text-align: left
}
/* --- bottom or single paragraph only --- */
#main .article2 {
background-color: #333333;
color: #ffc308;
height: auto;
margin-top: 0;
padding: 3px 5px;
text-align: left
}
#main .article1 A:link, #main .article1 A:visited {
background-color: #333333;
color: #FF9900;
font-size: 10pt;
text-decoration: none
}
#main .article1 A:hover, #main .article1 A:active {
background-color: #333333;
color: #ef7518;
font-size: 10pt;
text-decoration: none
}
#main .article2 A:link, #main .article2 A:visited {
background-color: #333333;
color: #FF9900;
font-size: 10pt;
text-decoration: none
}
#main .article2 A:hover, #main .article2 A:active {
background-color: #333333;
color: #ef7518;
font-size: 10pt;
text-decoration: none
}
#subnav {
background-color: transparent;
border: 0;
height: auto;
width: 104px;
float: right;
}
#subnav h3 {
font-size: 10pt;
font-weight: bold;
margin-left: 5px
}
#subnav .subnav1 {
background-color: #454545;
color:#ffc308;
border: 2px #ffc308 solid;
height: auto;
margin-bottom: 10px;
text-align: left;
}
#subnav .subnav1 A:link, #subnav .subnav1 A:visited {
background-color: #454545;
color: #FF9900;
font-size: 10pt;
text-decoration: none
}
#subnav .subnav1 A:hover, #subnav .subnav1 A:active {
background-color: #454545;
color: #ef7518;
font-size: 10pt;
text-decoration: none
}
#subnav .subnav1 ul {
padding: 5px 5px 3px 5px
}
#subnav .subnav1 li {
list-style-type: none;
margin-bottom: 5px
}
/*--- alignment ---*/
#main .left {
float:left;
border:0;
margin-right:5px;
background-color:#000000;
color:#FFCC00;
}
#main .right {
float:right;
border:0;
margin-left:5px;
background-color:#000000;
color:#ffc308;
}
Copy linkTweet thisAlerts:
@Sunny_GauthorJan 11.2006 — Fang, if I used your suggestion, I wouldn't need to change any of the absolute positioning, would I?

By use of margins and floats, I was able to get rid of all the absolute positioning, which allows the page to adjust better to font resizes by the user.[/QUOTE]Would the divs adjust for width if the viewer adjusted the font size?
Copy linkTweet thisAlerts:
@FangJan 11.2006 — Fang, if I used your suggestion, I wouldn't need to change any of the absolute positioning, would I?[/QUOTE]
No, just the changes I gave.

Using so much absolute positioning could lead to other problems in the future.
Copy linkTweet thisAlerts:
@NogDogJan 12.2006 — ...

Would the divs adjust for width if the viewer adjusted the font size?[/QUOTE]

As currently coded, no. Only if you used 'em' instead of 'px' for the related width units.
Copy linkTweet thisAlerts:
@Sunny_GauthorJan 12.2006 — Using so much absolute positioning could lead to other problems in the future.[/QUOTE]Like what?
Copy linkTweet thisAlerts:
@Sunny_GauthorJan 13.2006 — I thought about it, and decided to go with your advice NogDog.

I'll start working on it as soon as possible.

Thanks!

=edit=

Only if you used 'em' instead of 'px'[/QUOTE]
You mean I should use em on the divs, or the text?

=another edit=

OK, I took your advice NogDog and used the stylesheet you made. After you made it I redid the color scheme on that site, so I had to transfer those styles. Now the site looks great when it's centered! Thanks alot!
×

Success!

Help @Sunny_G spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...