CSS substitution for the <center> tag

N

Nathan Sokalski

As most of us probably know, the <center> tag is deprecated. Because many
elements and controls have an align attribute, centering them is easy
enough. However, certain elements/controls do not (such as the ASP.NET
Button and Label controls). For the ASP.NET label control I usually just add
the following attributes:

Width="100%" style="text-align:center;"

However, this does not work for controls such as the ASP.NET Button control.
The only solution I can think of is to nest it inside of <div
align="center"></div> tags. However, this could add a lot of extra tags. Any
suggestions? Thanks.
 
N

Nathan Sokalski

As I said in my original message, I have used that, but would like to have a
way that does not involve any extra tags (in other words, I would like to do
it using CSS). Any other ideas? Thanks.
 
N

Nathan Sokalski

No, I am referring to horizontally centering the button on the page (or
within the div, td, or other tag that it is contained in). Thanks.
--
Nathan Sokalski
(e-mail address removed)
http://www.nathansokalski.com/

Eliyahu Goldin said:
Do you mean aligning the text inside a button? Aligning with
style="text-align:xxx" does work for this.And the text is already centered
by default. Do you mean something else?

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Nathan Sokalski said:
As most of us probably know, the <center> tag is deprecated. Because many
elements and controls have an align attribute, centering them is easy
enough. However, certain elements/controls do not (such as the ASP.NET
Button and Label controls). For the ASP.NET label control I usually just
add the following attributes:

Width="100%" style="text-align:center;"

However, this does not work for controls such as the ASP.NET Button
control. The only solution I can think of is to nest it inside of <div
align="center"></div> tags. However, this could add a lot of extra tags.
Any suggestions? Thanks.
 
P

Przemek Ptasznik

Nathan Sokalski napisa³(a):
No, I am referring to horizontally centering the button on the page (or
within the div, td, or other tag that it is contained in). Thanks.

According to css specifications text-align:center should only center
text content of element. What you want achieve, is done with margin: auto;
IE of course doesn't support it:(
other browsers (opers, firefox, safari) supports it.

In IE you should apply text-align:center to parent element of your
button, because IE applies centering to all content (not only text).
If you don't want to center all content - apply text-align:left to
content which you don't want to center.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top