How to center a span element using external css?

Discussion in 'HTML' started by Ken Adams, Apr 25, 2005.

  1. Ken Adams

    Ken Adams Guest

    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
    Ken Adams, Apr 25, 2005
    #1
    1. Advertising

  2. Ken Adams

    Mitja Guest

    On Mon, 25 Apr 2005 17:26:26 +0200, Ken Adams <>
    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.
    Mitja, Apr 25, 2005
    #2
    1. Advertising

  3. Ken Adams

    Steve Pugh Guest

    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
    Steve Pugh, Apr 25, 2005
    #3
  4. 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
    David Dorward, Apr 25, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fulio Open

    Can span include span?

    Fulio Open, Jun 26, 2009, in forum: HTML
    Replies:
    5
    Views:
    534
    dorayme
    Jun 26, 2009
  2. Stéphane Klein
    Replies:
    2
    Views:
    1,733
    John Nagle
    Mar 30, 2010
  3. Stefan Behnel
    Replies:
    0
    Views:
    474
    Stefan Behnel
    Mar 29, 2010
  4. Cal Who
    Replies:
    5
    Views:
    945
    Cal Who
    Apr 26, 2010
  5. Dan Bishop

    DataGrid (body only) contained in <span>...</span> tags

    Dan Bishop, Jun 7, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    261
    Kilic Beg
    Jun 7, 2004
Loading...

Share This Page