![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||||
| |||||
|
|
Hello, I am a self-taught home developer: |
|
Question: As it seems, most CSS people like to use DIVs as a division between styles. So, they would have a style for a div tag that would hold some other styles and other tags... One thing I fail to understand about people being so addicted to DIV is that it this tag is similar to <P> tag; it creates a new paragraph whenever you use DIV. What is a difference then between P and DIV? |
|
I tend to use SPAN because it does not generate any line break. |
|
Am I missing something? |
|
Why people like DIV so much? Please explain because I do struggle for understanding of this topic. |
#3
| ||||
| ||||
|
|
The fist step is to learn to write valid HTML. |
|
But DIV will close any P that is open. |
|
SPAN is an *inline* element. It cannot contain a block element. |
|
SPAN is closed whenever the block containing it is closed. |
#4
| |||
| |||
|
|
Lars Eighner <eighner (AT) io (DOT) com> wrote: But DIV will close any P that is open. Under transitional rules, under strict rules the element needs to be closed before a preceding open block element closes. |
#5
| |||
| |||
|
|
There are many free tutorials on HTML available on the web. |
#6
| |||
| |||
|
|
But DIV will close any P that is open. Under transitional rules, under strict rules the element needs to be closed before a preceding open block element closes. div will close any p element that is open in HTML, not in XHTML. There is no difference between Strict and Transitional versions. |
#7
| |||
| |||
|
|
One thing I fail to understand about people being so addicted to DIV is that it this tag is similar to <P> tag; it creates a new paragraph whenever >>you use DIV. What is a difference then between P and DIV? |
#8
| |||
| |||
|
|
One thing I fail to understand about people being so addicted to DIV is that it this tag is similar to <P> tag; it creates a new paragraph whenever >>you use DIV. What is a difference then between P and DIV? What you're missing here is that <p> tags and <div> tags create a new line because they are both "block" level elements (i.e., they create a new 'block' in the flow of the html). this is different from <span>, li>, and other elements that are "inline" or create no new line. There are several different block-level tags that could be used, for example any list tag (<ul> or <ol> for example) or even tables. You use what fits your needs, or the semantics of what it is you're trying to do with the markup. Use <p> when you have a paragraph, use span> when you have a line (a span of text, if you will). div> has become the workhorse of css based layouts much the way <td was the workhorse of table based layouts. It doesn't create any special replaced elements on the page, and basically is perfect for giving every tag contained within it a skeleton with which to drape all the styles you want on it (by giving it a class or id, for example) since css 'cascades' and styles are inherited. However, depending on your situation, you may be better off using span> if you have a situation where you don't want a line break. It's not necessary to litter <div> tags all over the place, as you could probably just apply the styles to other block level elements that you have in your markup anyway. It's considered good practice to apply styles to elements you already have, instead of creating 'empty tags' that have no business in your documents. Sometimes, you just need a <div>, though. It is a great container element. Hope that helps. Travis |
#9
| |||
| |||
|
|
One more question: Is it possible to use DIV but to force it not to produce a line break with CSS style? I need a line break on the bottom but not on the top of some code block, I used SPAN and <BR> after the SPAN. Is there a better way to derive with CSS the same results like having DIV where top break somehow is suppressed; or else? Padding? |
#10
| |||
| |||
|
|
How to pack the menu? I used SPAN tags + BR for a line break. What would you |
![]() |
| Thread Tools | |
| Display Modes | |
| |