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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DIV and SPAN 1

Status
Not open for further replies.

BowlerBob

Programmer
Jan 16, 2003
21
GB
Hi

Can anyone help clarify the use of <DIV> and <SPAN> tags ?

are they used in the same way as <TR> and <TD>,
or do you use <DIV> within <DIV> ?

cheers

BowlerBob
 
<DIV> Is usually used to define areas of the page which can then be positioned and styled with CSS. You don't have to position them of course but it is becoming commonplace to use CSS-positioning as a better alternative to using HTML tables for layout (which they were never intended for). It makes for much cleaner lighter code as well.
<SPAN> Is used &quot;inline&quot;, for example you might use it to highlight a few words in a sentence and style the class in a different colour for example.
e.g. This is an <span class=&quot;hilite&quot;>example of how you</span> might use <SPAN>. Obviously that won't actually do anything to the text in this example but you get the idea.
I would then have a CSS rule something like this:
.hilite {
color: #ff0000;
font-weight: bold;
}
which would make the words surrounded by the <span> bold and red. Joe Bananas' guide to Perth, Scotland
Bananas' Fawlty Towers site!
 
also note, as mentioned span is an inline element and should really be used this way.

DIV is a block level element, it expands to full width and will not sit along side another div unless you specifically define those divs to be inline (display:inline;)

div can hold any type of content, tables, forms, more divs etc but spans, as Bananas already explained, is more suitable for highlighting a few words etc






<!--#sig value=''É'' url='' -->
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top