Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > How to center a span element using external css?

Reply
Thread Tools

How to center a span element using external css?

 
 
Ken Adams
Guest
Posts: n/a
 
      04-25-2005
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


 
Reply With Quote
 
 
 
 
Mitja
Guest
Posts: n/a
 
      04-25-2005
On Mon, 25 Apr 2005 17:26:26 +0200, Ken Adams <(E-Mail Removed)>
wrote:

> 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.
 
Reply With Quote
 
 
 
 
Steve Pugh
Guest
Posts: n/a
 
      04-25-2005
Ken Adams wrote:
> 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

 
Reply With Quote
 
David Dorward
Guest
Posts: n/a
 
      04-25-2005
Ken Adams wrote:

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


http://dorward.me.uk/www/centre/

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't code a css class that makes a span element the same size as a button element Cal Who ASP .Net 5 04-26-2010 05:35 PM
I'm looking for html cleaner. Example : convert <h1><span><font>my title</font></span></h1> => <h1>my title</h1>… Stéphane Klein Python 2 03-30-2010 12:35 AM
Re: I'm looking for html cleaner. Example : convert <h1><span><font>my title</font></span></h1> => <h1>my title</h1>… Stefan Behnel Python 0 03-29-2010 08:14 PM
Can span include span? Fulio Open HTML 5 06-26-2009 10:24 PM
DataGrid (body only) contained in <span>...</span> tags Dan Bishop ASP .Net Datagrid Control 2 06-07-2004 04:00 PM



Advertisments