javascript
Brief description  about Online courses   join in Online courses
View dhanashree chetan tupkar 's Profile

Span and Div

Hello Can anybody tell me the differences between span and div
Asked by dhanashree chetan tupkar | Sep 13, 2012 |  Reply now
Replies (2)
View dhanashree chetan tupkar 's Profile
Thank you for your reply
Sep 28, 2012
View teacher siliconindia 's Profile
Hi

Using the DIV Tag

To use the DIV element, simply surround the area of your page that you want as a separate division with the <div> and </div> tags:

<div id="mydiv">
<p>contents of div</p>
</div>

The DIV element gives you the chance to define the style of whole sections of the HTML. You can define a division of your page as a call out and give that area a different style from the surrounding text. That area could have images, paragraphs, headlines, anything you wanted. The DIV element also gives you the ability to ID areas of your documents so that you can change them with Ajax and dynamic HTML.


The SPAN Element

The SPAN element has very similar properties to the DIV element, in that it changes the style of the text it encloses. But without any style attributes, the SPAN element won’t change the enclosed items at all.

The primary difference between the SPAN and DIV elements is that SPAN doesn’t do any formatting of it’s own. The DIV element includes a paragraph break. The SPAN element simply tells the browser to apply the style rules to whatever is within the SPAN.

To use the SPAN element, simply surround the text that you want to add styles to with the <span> and </span> tags:

<div id="mydiv">
<p><span class="highlight">Highlighted text</span> and non-highlighted text.</p>
</div>


Regards
Sep 24, 2012