div versus span tags

Discussion in 'HTML' started by TheKeith, Oct 17, 2003.

  1. TheKeith

    TheKeith Guest

    I know the basic difference between these two tags, but there is one thing I
    don't understand about the span tag? Unlike the div tag, specifying a width
    and height of a span tag doesn't work unless you have "position:absolute"
    within it. Why is this? What does the position style have to do with the
    width and height styles?
    TheKeith, Oct 17, 2003
    #1
    1. Advertising

  2. TheKeith

    Eric Bohlman Guest

    "TheKeith" <> wrote in
    news::

    > I know the basic difference between these two tags, but there is one
    > thing I don't understand about the span tag? Unlike the div tag,
    > specifying a width and height of a span tag doesn't work unless you
    > have "position:absolute" within it. Why is this? What does the
    > position style have to do with the width and height styles?


    First of all, a terminological nitpick: *tags* don't have properties,
    *elements* do. Tags are just the markers that show where elements begin
    and end; they're really a sort of labelled parentheses.

    Span elements are considered inline elements, whereas div elements are
    considered block elements. You can think of block elements as "containers"
    (which may contain sub-containers), whereas inline elements are content
    that doesn't contain any further containers. Properties like height and
    width apply only to block elements. The height and width of inline
    elements is determined by the document flow.

    However, when you position something absolutely, you're taking it out of
    the normal document flow, so it doesn't get to pick up properties from its
    container. A lot of the normal distinctions between block and inline
    elements vanish when you position them absolutely.
    Eric Bohlman, Oct 17, 2003
    #2
    1. Advertising

  3. TheKeith

    TheKeith Guest

    "Eric Bohlman" <> wrote in message
    news:Xns94178E86DF008ebohlmanomsdevcom@130.133.1.4...
    > "TheKeith" <> wrote in
    > news::
    >
    > > I know the basic difference between these two tags, but there is one
    > > thing I don't understand about the span tag? Unlike the div tag,
    > > specifying a width and height of a span tag doesn't work unless you
    > > have "position:absolute" within it. Why is this? What does the
    > > position style have to do with the width and height styles?

    >
    > First of all, a terminological nitpick: *tags* don't have properties,
    > *elements* do. Tags are just the markers that show where elements begin
    > and end; they're really a sort of labelled parentheses.
    >
    > Span elements are considered inline elements, whereas div elements are
    > considered block elements. You can think of block elements as

    "containers"
    > (which may contain sub-containers), whereas inline elements are content
    > that doesn't contain any further containers. Properties like height and
    > width apply only to block elements. The height and width of inline
    > elements is determined by the document flow.
    >
    > However, when you position something absolutely, you're taking it out of
    > the normal document flow, so it doesn't get to pick up properties from its
    > container. A lot of the normal distinctions between block and inline
    > elements vanish when you position them absolutely.


    Thanks a lot. That explains it.
    TheKeith, Oct 17, 2003
    #3
    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. Lloyd Dupont
    Replies:
    2
    Views:
    770
    Lloyd Dupont
    Jan 8, 2006
  2. sherpaa
    Replies:
    2
    Views:
    4,101
    brucie
    Jun 1, 2004
  3. KiwiBrian

    span versus div

    KiwiBrian, Nov 24, 2004, in forum: HTML
    Replies:
    28
    Views:
    5,022
    Lauri Raittila
    Nov 25, 2004
  4. Dan Bishop

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

    Dan Bishop, Jun 7, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    265
    Kilic Beg
    Jun 7, 2004
  5. Paul Butcher
    Replies:
    12
    Views:
    694
    Gary Wright
    Nov 28, 2007
Loading...

Share This Page