Jump to content

what is <div>?


GOO

Recommended Posts

Somehow I find it weird when i use <div> and <span> to write these:<div> type:<html><body><p><div style="color:#ff0000;">Here it is!</div></p></body></html><span> type:<html><body><p><span style="color:#ff0000;">Here It is!</span></p></body></html>There is no difference!!!Why?What is the difference?Or what is the use of those?

Link to comment
Share on other sites

Div's, Paragraphs, and Spans are usually not utilizised the way you have them up there. Typically, a Div contains paragraphs and a paragraph will contain spans. If you were to learn a little more html or xhtml and read the specifications for the use of these tags, you would be aware of the difference between Block Level and Inline tags. Start by learning the difference between those terms.

Link to comment
Share on other sites

The differences between a div, span and p are more semantical then visual. By semantic I mean their meaning... their purpose if you want. They are about "what" is the data in them, not "how it looks".A block to put it more simply means "bunch of stuff".A paragraph is a block of text. You've written essays in literature classes, haven't you? The introduction and thesis are written in one paragraph each.Visually, most browsers put a small margin around a paragraphs and put each on a new line.A "div" is used to define a "division". A devision may contain all sorts of things, but it's supposed to be a division of things, not simply a division of block of text, as with the paragraph. For example a div may contain several blocks of text (several paragraphs). If I go to the essay association again- you write each argument in it's own paragraph. The arguments together form a statement.Visually, browsers put each div on a new line.And "span" is used to mark text that may be found inside a line of a block of text (in a line=inline). This can be a word or prase or anything else.Visually, browsers don't do anything with a span, because span alone doesn't define the text in it to be anything special.

Link to comment
Share on other sites

So, that means,if i wrote a <div>, it should contain <p>.And in the <p>, it should contain <span>, right?Like this:<html><head></head><body><div style="color:#488e5e"><p>Some text here. Some text here. Some text here.</p><p>Some text here. Some text here. Some text here.</p><p>Some text here. <span style="color:#2232ed">Some text here.</span> Some text here.</p></div></body></html>

Link to comment
Share on other sites

Correct, but a <div> can contain all other sots of stuff as well. It may contain other divisions, one or more lists, one or more tables, etc.It's like a piece of the page you've decided to "cut" into it's own territory.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...