Trouble centering my layout
Posted: 05 June 2008 06:05 PM   [ Ignore ]
Newbie
Rank
Total Posts:  9
Joined  2008-05-23

Hey everyone, I have a simple one-column fixed layout that I’m trying to center but I’m having some problems. Whenever I try to add 50% padding to the body and give the wrapper a width and a margin-left equal to half that width, it shifts my content (except for my nav menu which it does nothing to) way down the page and does weird things when I resize my browser. Any suggestions?

Here is a link to the website:
http://alexmel7.site88.net/exercise6/index.html

Here is my CSS:

htmlbody {
margin
0px;
padding50%;
}

#wrapper {
width1000px;
margin-left: -500px;
}

#header {
background-imageurl(images/header.gif);
width995px;
height156px;
background-repeatno-repeat;
margin-top5px;
}

.about a {
position
absolute;
top18px;
left410px
displayblock;
background-imageurl(images/navabout.gif);
width99px;
height29px;
text-decorationnone;
outlinenone;
}

.about a:Hover  {
position
absolute;
top3px;
left404px;
background-imageurl(images/navrollabout.gif);
width120px;
height51px;


.services a {
position
absolute;
top18px;
left535px
displayblock;
background-imageurl(images/navservices.gif);
width107px;
height29px;
text-decorationnone;
outlinenone;
}

.services a:Hover  {
position
absolute;
top5px;
left528px;
background-imageurl(images/navrollservices.gif);
width126px;
height48px;


.portfolio a {
position
absolute;
top18px;
left660px
displayblock;
background-imageurl(images/navportfolio.gif);
width128px;
height34px;
text-decorationnone;
outlinenone;
}

.portfolio a:Hover  {
position
absolute;
top3px;
left654px;
background-imageurl(images/navrollportfolio.gif);
width145px;
height48px;


.contact a {
position
absolute;
top21px;
left810px
displayblock;
background-imageurl(images/navcontact.gif);
width113px;
height28px;
text-decorationnone;
outlinenone;
}

.contact a:Hover  {
position
absolute;
top5px;
left802px
background-imageurl(images/navrollcontact.gif);
width132px;
height47px;


#main {
background-imageurl(images/main.gif);
width927px;
height350px;
background-repeatno-repeat;
}

#footer {
background-imageurl(images/footer.gif);
width990px;
height28px;
Profile
 
 
Posted: 06 June 2008 05:07 AM   [ Ignore ]   [ # 1 ]
Jr. Member
RankRank
Total Posts:  38
Joined  2007-09-03

Alex,

You do not specify which browser you are using - I looked at your site and tried resizing in Firefox, IE6 and Opera 9.1 and didn’t notice anything especially weird.  Having said that, attempting to do horizontal centering via 50% etc is not a good idea.  A far better way is to use margin:auto.  If you want to center the main body of your contents you might want to consider one or more of the following

a. Place them in a div
b. Adjust the margin and padding attributes for the div
c. Use margin:auto to center the div

Given you are so early in the site design process - make sure you check your site with a number of browsers.  In practice, nontechie sites tend to get traffic that is mostly IE (it is mainly only techie types go and seek out other browsers) but even so it is worthwhile checking out the site with different browsers.  Apart from local tests, a handy tool once you have got your site online is BrowserShots

Profile
 
 
Posted: 09 June 2008 07:20 PM   [ Ignore ]   [ # 2 ]
Newbie
Rank
Total Posts:  1
Joined  2008-06-09

I’ve been using the following for quite some time with no problems.
No need for the padding in the HTML/BODY declaration.

#wrapper {
    
position:relative;
    
left:50%;
    
width:1000px;
    
margin-left:-500px;
    
padding:0;

ExplainThat!, why is the 50% thing bad, or not as good as margin:auto?

Profile
 
 
Posted: 19 October 2009 01:14 PM   [ Ignore ]   [ # 3 ]
Newbie
Rank
Total Posts:  1
Joined  2009-10-19

It actually looks fine to me. I’m using chrome btw. It’s probably just because of the browser your using. It looks different with each browser.

 

Regards,
Claire
Simulation pret immobilier

Profile
 
 
Posted: 21 December 2010 07:56 AM   [ Ignore ]   [ # 4 ]
Jr. Member
RankRank
Total Posts:  42
Joined  2010-12-14
frankenglove - 09 June 2008 07:20 PM

I’ve been using the following for quite some time with no problems.
No need for the padding in the HTML/BODY declaration.

#wrapper {
    
position:relative;
    
left:50%;
    
width:1000px;
    
margin-left:-500px;
    
padding:0;

ExplainThat!, why is the 50% thing bad, or not as good as margin:auto?

It worked pretty nicely.

Profile
 
 
Posted: 21 December 2010 08:19 AM   [ Ignore ]   [ # 5 ]
Newbie
Rank
Total Posts:  4
Joined  2010-12-21

Are you looking for the best Jerseys? Cheap NFL Jerseys can be served in our website in surprise a series of design and style, you didn’t need to see any further than our website, for your needs? Show your spirit and pride,  This is a simple shirt but far from plain, nfl youth jerseys,this is filled with delicate style. Mainly from new - style. Different mode sleeve. The team’s badge embroidered trademark heart, center, so are you sure this is a genuine team products. nfl women jerseys, Grid moisture control panel and advanced fabrics to give your amazing comfort no matter how long the train or playing the game you like most international refueling. to show your support team to be unique hockey clothing. nike dunk,Design uniform exact specifications champion athlete. It features included - wicking fabric, so you must keep calm when action heating! This performance shirt is by 100% recycled polyester, with excellent technology, as the final comfort. Another feature of the specific signs, cheap jerseys, uniform embroidered marks the collar of the one you like.
  NFL Jerseys visit your favorite shirt, style. Add it to your passion sport! This advanced shirt is just like the one wearing clothes with world champion team of professionals. cheap nhl jersyes,This is an engineered grid team jersey lightweight, how - copy comfort. It includes a two-layer gridding everywhere for unbelievable ventilated. Jersey is by 100% polyester characteristic, then it behind insert screening number and name and includes an open and welding hem, double layer construction. cheap nfl jerseys
  Get a bold look from the dominion referee high five football shirtsto match your team’s bold play! The jersey is made of 100% polyester with Essortex moisture management technology. It prominently features sublimated vertical stripes on body, buy nfl jerseys, engineered sublimated double stripes on sleeves, V-neck fashion-knit collar and patch pocket with circular Velcro hook and loop patch for officials badges. Match the on-field excitement in this jersey in the stands!
Usa soccer jerseys are now available in incredible designs that can truly pump adrenalin into you! Visit our site and choose from the wide variety of choices available!
view more: http://www.999plaza.com/

Profile