THE BORE

General => The Superdeep Borehole => Topic started by: GilloD on August 25, 2008, 03:06:19 PM

Title: Centering a <div> in IE7?
Post by: GilloD on August 25, 2008, 03:06:19 PM
In Firefox I used margin:auto or margin:0 20 for my content wrapper and those were fine. But I have Googled and attempted every solution to center the content wrapper div in IE7 and no dice. It stays stuck to the left. Thoughts?
Title: Re: Centering a <div> in IE7?
Post by: patrickula on August 25, 2008, 03:09:29 PM
margin:0 auto 0 auto doesn't work  ???  Sometimes it helps to set the body text to center also, I think.
(BTW should I just be using 0 auto alone in my css? I guess the second set might be redundant)
Title: Re: Centering a <div> in IE7?
Post by: demi on August 25, 2008, 03:11:22 PM
html, body {
text-align: center;
}

#cum-wrapper {
margin-left: auto;
margin-right: auto;
}

should work...
Title: Re: Centering a <div> in IE7?
Post by: GilloD on August 25, 2008, 03:15:56 PM
html, body {
text-align: center;
}

#cum-wrapper {
margin-left: auto;
margin-right: auto;
}

should work...

Awesome. Thanks a ton, again. Like I said- I'm a major n00b when it comes to this and I'm definitley fumbling my way through, so the help is hugely appreciated.
Title: Re: Centering a <div> in IE7?
Post by: demi on August 25, 2008, 03:16:37 PM
if you have text or objects in there, just put

text-align: left; in the wrapper/div object

cause everything will be centered originally - and you should be cool
Title: Re: Centering a <div> in IE7?
Post by: Wolf Gang on August 25, 2008, 03:17:52 PM
demi is king of CSS tricks.

Do you have a design studio?
Title: Re: Centering a <div> in IE7?
Post by: Bocsius on August 25, 2008, 03:28:46 PM
I found a shortcut to centering something prior to the weekend. I had a 900px wide  div I wanted in the center.

.centerDiv
{
 width:900px;
 position:absolute;
 left:50%;
 margin-left:-450px;
}

Put the thing dead-on center, too. Thought it was awesome.

Until I unmaximized my browser window, that is. The left side was cutoff the page, couldn't scroll to it or anything. Oh well, live and learn.

So yeah... "text-align:center;" on the outer div, "margin: 0 auto;" and "text-align:left;" on the inner div.
Title: Re: Centering a <div> in IE7?
Post by: demi on August 25, 2008, 03:31:11 PM
I hate working with absolute/relative positioning... never could get it right
Title: Re: Centering a <div> in IE7?
Post by: Wolf Gang on August 25, 2008, 03:34:55 PM
Does anybody still use tables to form the layout of their webpage? I do.
Title: Re: Centering a <div> in IE7?
Post by: Bocsius on August 25, 2008, 03:35:03 PM
Fortunately, style is not my calling in life. But these div threads did manage to shame me into redoing my own site and getting rid of the tables I was using to control the layout and learn a thing or two about using divs. Wasn't as difficult as I thought it would be once I got the float and clear nonsense down.
Title: Re: Centering a <div> in IE7?
Post by: GilloD on August 25, 2008, 03:39:39 PM
Does anybody still use tables to form the layout of their webpage? I do.

A lot of "Best Practices..." suggest using like ONE table to align your DIVs.
Title: Re: Centering a <div> in IE7?
Post by: Wolf Gang on August 25, 2008, 03:47:06 PM
Yeah, I'd still use table(s) to align the div(s), so I don't have to hack CSS tricks all night.

For all the talk of "loose" tags in the transitional DTD of HTML being deprecated or whatever, I doubt any browser is really going to be so anal about standards that it'll refuse to render any and all webpages using <center> for alignment. HTML/XML validation be damned.

So, I have no qualm about using <center>. In my opinion, it's a feature of any browser to support <center>. That shit simplifies everything.
Title: Re: Centering a <div> in IE7?
Post by: GilloD on August 25, 2008, 04:01:23 PM
Yeah, I'd still use table(s) to align the div(s), so I don't have to hack CSS tricks all night.

For all the talk of "loose" tags in the transitional DTD of HTML being deprecated or whatever, I doubt any browser is really going to be so anal about standards that it'll refuse to render any and all webpages using <center> for alignment. HTML/XML validation be damned.

So, I have no qualm about using <center>. In my opinion, it's a feature of any browser to support <center>. That shit simplifies everything.

Doesn't IE7 already disregard center?
Title: Re: Centering a <div> in IE7?
Post by: APF on August 25, 2008, 05:24:25 PM
I think it's very rare IRL a dev would ever need a <center> tag.  Maybe if it valigned center, but why wouldn't you prefer CSS methods of doing that as well? Centering something isn't like bolding something; you're usually centering some specific item like a block or image, in which case you have that CSS hook already.