How to center a span element using external css?

K

Ken Adams

Hey, How does one center a span element using an external css. I seem to be
able to change the text color and size and all that, but for some reason I
can't center it. I have the following.
document.write('<span id="tP" class="clock">+eval(oT)+'</span>');



with the following css

..clock {

color: maroon;

font-family: 'Times New Roman';

font-size: x-small;

text-align: center
 
M

Mitja

Hey, How does one center a span element using an external css.

span is an inline element and therefore can't be aligned. Make it a p or a
div instead of a span, or explicitly make the span block-level by using
display:block.
 
S

Steve Pugh

Ken said:
Hey, How does one center a span element using an external css. I seem to be
able to change the text color and size and all that, but for some reason I
can't center it. I have the following.
document.write('<span id="tP" class="clock">+eval(oT)+'</span>');

text-align: center

text-align centers the text within the span. As the span is only as
wide as the text it contains, centering that text has no effect.

To center the span you need to apply text-align: center; to whatever
block level element is the span's parent.

Steve
 

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,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top