div versus span tags

T

TheKeith

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?
 
E

Eric Bohlman

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.
 
T

TheKeith

Eric Bohlman said:
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.
 

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,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top