Author Topic: Centering a <div> in IE7?  (Read 857 times)

0 Members and 1 Guest are viewing this topic.

GilloD

  • TAKE THE LIFE OF FRED ASTAIRE. MAKE HIM PAY. TRANSFER HIS FAME TO YOU.
  • Senior Member
Centering a <div> in IE7?
« 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?
wha

patrickula

  • Member
Re: Centering a <div> in IE7?
« Reply #1 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)

demi

  • cooler than willco
  • Administrator
Re: Centering a <div> in IE7?
« Reply #2 on: August 25, 2008, 03:11:22 PM »
html, body {
text-align: center;
}

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

should work...
« Last Edit: August 25, 2008, 03:14:12 PM by demi »
fat

GilloD

  • TAKE THE LIFE OF FRED ASTAIRE. MAKE HIM PAY. TRANSFER HIS FAME TO YOU.
  • Senior Member
Re: Centering a <div> in IE7?
« Reply #3 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.
wha

demi

  • cooler than willco
  • Administrator
Re: Centering a <div> in IE7?
« Reply #4 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
fat

Wolf Gang

  • Junior Member
Re: Centering a <div> in IE7?
« Reply #5 on: August 25, 2008, 03:17:52 PM »
demi is king of CSS tricks.

Do you have a design studio?

Bocsius

  • is calmer than you are
  • Senior Member
Re: Centering a <div> in IE7?
« Reply #6 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.

demi

  • cooler than willco
  • Administrator
Re: Centering a <div> in IE7?
« Reply #7 on: August 25, 2008, 03:31:11 PM »
I hate working with absolute/relative positioning... never could get it right
fat

Wolf Gang

  • Junior Member
Re: Centering a <div> in IE7?
« Reply #8 on: August 25, 2008, 03:34:55 PM »
Does anybody still use tables to form the layout of their webpage? I do.

Bocsius

  • is calmer than you are
  • Senior Member
Re: Centering a <div> in IE7?
« Reply #9 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.

GilloD

  • TAKE THE LIFE OF FRED ASTAIRE. MAKE HIM PAY. TRANSFER HIS FAME TO YOU.
  • Senior Member
Re: Centering a <div> in IE7?
« Reply #10 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.
wha

Wolf Gang

  • Junior Member
Re: Centering a <div> in IE7?
« Reply #11 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.

GilloD

  • TAKE THE LIFE OF FRED ASTAIRE. MAKE HIM PAY. TRANSFER HIS FAME TO YOU.
  • Senior Member
Re: Centering a <div> in IE7?
« Reply #12 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?
wha

APF

  • Senior Member
Re: Centering a <div> in IE7?
« Reply #13 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.
***