So I decided it would be a good idea to clarify this issue.
The DIV element is a "block" element. This means it occupies a full block when rendered, which also means that by default the browser will render a new line before and after rendering the DIV element. SPAN, on the other hand, is rendered inline. This makes SPAN perfect for formatting text which is part of a paragraph.
Want to see the difference? Create an HTML file containing the below code, and run it in a browser:
<html>
<body>
<p>Here goes for span: <span style="color:red" >hello</span> world</p>
<p>Here goes for div: <div style="color:red">hello</div> world</p>
</body>
</html>
And if you're lazy, this is how it looks like:
Here goes for span: hello world
Here goes for div:
hello
worldMakes sense, right?
Short and to the point. Quite useful, will remember that.
ReplyDeleteThe span example is missing the style property...
ReplyDeleteOrgad, thanks. Fixed.
ReplyDelete