View Full Version : The difference between <Div> and <Span>
william
07-22-2002, 10:08 AM
i am now learning how to create a WebPages and i think the tag <div> is similar to <span>. so i want to know is there any difference between these to tags?
Can some one help me
Thanks
Mhtml
07-22-2002, 11:10 AM
I'm not quite sure about this but I just always thought that the <div> tag was originally IE and <span> was NS but I may be wrong.
I don't think the 'id' attribute works in the <div> tag but does in <span>. also I think that the <span> tag is more easily accessable through javascript than the <div> tag is.
But this is just what I thought.. So don't count on this being correct.
boxer_1
07-22-2002, 11:40 AM
Both the span and the div element can be assigned an 'id' ;) . Here's a link with a little more information on the difference between the 2 elements:
http://developer.irt.org/script/915.htm
You can find out about each element by searching around here: http://www.w3.org/
Zvona
07-22-2002, 11:40 AM
For example :
<div id="divContent" style="width:400px;height:200px;position:absolute;left:100px;top:100px;">
<p>This is an example of using <span style="font-weight:bold;">DIV and SPAN elements</span>.
You can refer to this fragment with DOM method
<span style="text-decoration:underline;">document.getElementById('divContent')</span>.
For more information, visit at <a href="http://www.w3.org" title="W3C">W3 Consortium</a>.
</p>
</div>
There are mis-displayed line breaks.. :(
Mhtml
07-22-2002, 11:48 AM
Oh, ok.. That explains when i learnt html (3-4 years ago) I learnt about stting css visability style using <span> I always just assumed that it was because id didn't work with div because that's how it was done and was called from javascript...
Oh well learn something new everyday I guess.:D
mouse
07-22-2002, 02:01 PM
<span> is inline, you can use it as a powerful replacement for <font>, <b>, <u> and so on...
<div> is not inline, doesn't work like <span> and is used to style sections, position sections (layers and so on.
BrainJar
07-22-2002, 04:34 PM
DIV is a block element, like P or H1, H2, etc. By default, it starts on a new line. There is an implied line break before and after those elements.
SPAN is an inline element like B, I, U, A, etc. There is no implied line break.
Both are perfectly valid HTML. Any browser should recognize them. Their main benefit is that they don't imply any sort of formatting. A P tag, for example, is usually rendered with margins which makes it look like there are blank lines above and below it. A DIV tag doesn't have those margins by default. Likewise, a SPAN tag won't affect the text it surrounds like a B or an I tag would.
This makes DIV and SPAN good for grouping text and/or other elements so that you can apply your own styles to them.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.