Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

Center align a DIV without <center> tags

Question posted by: DiamondEagle (Guest) on June 27th, 2008 07:16 PM
Is there a way to center the following div without using the <center>
tags?

<body bgcolor="#FFFFFF">
<center>
<div id="Test" style="background-color:#000000; color:#ffffff; width:
80%; text-align:center; line-height:100px;">Hello</div>
</center>
</body>

I want the div AND the text in the div to be aligned to the center.

Thanks...

(It's probably REALLY simple and I'll be quite embarassed that I
asked... but it's been one of "THOSE" days...)
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
Steve Pugh's Avatar
Steve Pugh
Guest
n/a Posts
June 27th, 2008
07:16 PM
#2

Re: Center align a DIV without <center> tags
On Jun 18, 2:43*pm, DiamondEagle <and...@webmail.co.zawrote:
Quote:
Originally Posted by
Is there a way to center the following div without using the <center>
tags?
>
<body bgcolor="#FFFFFF">


1. Use CSS not HTML attributes.
2. Set foreground and background colours together to avoid clashes
with user defaults.
Quote:
Originally Posted by
<center>
<div id="Test" style="background-color:#000000; color:#ffffff; width:
80%; text-align:center; line-height:100px;">Hello</div>
</center>
</body>
>
I want the div AND the text in the div to be aligned to the center.


It's not 100% obvious and hence it is a FAQ. Set margin-left and
margin-right to auto.

Make sure that your doctype is triggering standards mode or IE won't
co-operate.

Steve


dorayme's Avatar
dorayme
Guest
n/a Posts
June 27th, 2008
07:16 PM
#3

Re: Center align a DIV without <center> tags
In article
<13ba6d07-04fe-448d-8734-611c82d5d4a7@34g2000hsf.googlegroups.com>,
DiamondEagle <andyza@webmail.co.zawrote:
Quote:
Originally Posted by
Is there a way to center the following div without using the <center>
tags?
>


The first two pages of

<http://netweaver.com.au/centring/>

should give you a good idea of how to do both these things.

--
dorayme

Ed Jay's Avatar
Ed Jay
Guest
n/a Posts
June 27th, 2008
07:16 PM
#4

Re: Center align a DIV without <center> tags
dorayme scribed:
Quote:
Originally Posted by
>In article
><13ba6d07-04fe-448d-8734-611c82d5d4a7@34g2000hsf.googlegroups.com>,
DiamondEagle <andyza@webmail.co.zawrote:
>
Quote:
Originally Posted by
>Is there a way to center the following div without using the <center>
>tags?
>>

>
>The first two pages of
>
><http://netweaver.com.au/centring/>
>
>should give you a good idea of how to do both these things.


That seems like a very helpful site. Is there a navigation page? The home
page seems to have only a mail form.

--
Ed Jay (remove 'M' to reply by email)

Win the War Against Breast Cancer.
Knowing the facts could save your life.
http://www.breastthermography.info

dorayme's Avatar
dorayme
Guest
n/a Posts
June 27th, 2008
07:16 PM
#5

Re: Center align a DIV without <center> tags
In article <jiij54dac3jgodiadghr9mjgv7ea1m37oe@4ax.com>,
Ed Jay <edMbj@aes-intl.comwrote:
Quote:
Originally Posted by
dorayme scribed:
>
Quote:
Originally Posted by
In article
<13ba6d07-04fe-448d-8734-611c82d5d4a7@34g2000hsf.googlegroups.com>,
DiamondEagle <andyza@webmail.co.zawrote:
Quote:
Originally Posted by
Is there a way to center the following div without using the <center>
tags?
>


The first two pages of

<http://netweaver.com.au/centring/>

should give you a good idea of how to do both these things.

>
That seems like a very helpful site. Is there a navigation page? The home
page seems to have only a mail form.


The things on this server are mainly just sets of self-contained pages.
This set seems short enough not to need a menu but if I grow it, I guess
I will put some navigation beyond the pages menu at top and bottom.

I am a bit worried at the slightly artificial connection of things under
the topic of centring in this set. What else should I put?

* My views on the aesthetics of centring?

* My take on why centring has such an appeal (I reckon it has to do
with the importance of left/right symmetry in animal evolution)?

* Perhaps an attempt at humorous, maybe even florid writing, about why
archery targets have the bull's eye in the centre; after all, even a
bull does not have its eye in the dead centre of its bulk, neither
mass-fully nor geometrically speaking? And besides, it has two eyes.

* Why don't dart boards have two bulls eyes like bulls, you could get
100 only if you can throw two darts at once each landing on different
eyes? Perhaps I could make and market a special and more rational
dart-board, closer to bull. (psst, Boji, wanna send me some $buckeroos
as an advance payment for one of these?)

--
dorayme

 
Not the answer you were looking for? Post your question . . .
184,042 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors