Results 1 to 2 of 2

Thread: span versus div

  1. #1
    Join Date
    Apr 2012
    Central New Jersey
    Thanked 3 Times in 3 Posts

    Default span versus div

    This works:

    <div style="text-align:center; ">Far Hills</div>
    This doesn't:

    <span style="text-align:center; ">Far Hills</span>
    Can someone please explain why?

    (I think someone answered this for me years and years ago. I tried to find the thread, failed.)

    Last edited by marain; 07-05-2020 at 01:41 AM. Reason: Mark "Resolved"

  2. #2
    Join Date
    Mar 2011
    Thanked 116 Times in 113 Posts
    Blog Entries


    Try the following html -
    HTML Code:
    <div style="text-align:center;background-color:red">Far Hills</div>
    <span style="text-align:center;background-color:green">Far Hills</span>
    The div tag is a "block" element and its default width is 100% of the page.
    The span tag is an "inline" element and its default width is the width of its contents.

    Because of this, the center on the div tag puts the text in the middle of the div (which is in the middle of the page), but the center on the span does nothing as the width is just the size of the contents.
    Last edited by keyboard; 07-05-2020 at 01:27 PM. Reason: fiixed typo

  3. The Following User Says Thank You to keyboard For This Useful Post:

    marain (07-05-2020)

Similar Threads

  1. Mock-up versus my CSS
    By katiebugla in forum CSS
    Replies: 21
    Last Post: 10-04-2012, 09:44 PM
  2. IE7 borked layout versus other browsers
    By PhxVyper in forum CSS
    Replies: 1
    Last Post: 08-20-2010, 02:21 PM
  3. Replies: 5
    Last Post: 01-29-2009, 10:08 AM
  4. CSS versus Frames
    By jackii_8 in forum CSS
    Replies: 1
    Last Post: 01-16-2008, 03:18 AM
  5. <b> versus <strong>
    By John_fresh in forum HTML
    Replies: 13
    Last Post: 03-24-2007, 01:05 AM


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts