Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DIV vs SPAN 1

Status
Not open for further replies.

DKL01

Programmer
Sep 14, 2000
233
US
Hi,

I was wondering what's the difference between DIV and SPAN tags. Under what circumstances we use these tags ? I really appreciate any response.

Thanks
 
i don't know. i use div in every time. but you said you would "appreciate any response" so i desided to respond.
 
Ok. Here is the difference. A "DIV" has breaking space. Therefore its actually better to use "SPAN" when you are using it to give style to text, and use "DIV" for more DHTML stuff i.e hide/show layers and things....even though you can actually use "span" for that as well. But that is the difference as far as I know. Hope that was of some help. :-D
 
Yep, realgaz is right. a DIV breaks meaning that whatever
is after a DIV, it will be below it. A SPAN however does not
break. Try out this example:

<html>
<body>
<span> This text is in a span. </span> This text is after a span. As you can see it doesnt break.
<br><br><br>
<div> This text is in a div. </div> This text is after a
div and is below it.

I hope this helps,
[bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
bobbafet and realgaz are right. Despite a span tag's hability to be positionned like a Div a span tag is more for formatting and design then it is for content disposition.

Div's are containers that you use for your page content and spans are there if you want to add style to a part of your document.

Example of usage :

<style>
.boldedRedText
{
font-weight: bold ;
color : red ;
}
</style>

<div style=&quot;position:absolute;left:20;top:100;&quot;>
This is my <span class=boldedRedText>content</a>
</div>

I hope this helps. Gary Haran
 
Technically speaking, DIV is a block level tag and SPAN is an inline tag. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top