HighDots Forums  

General question about DIV usability

Cascading Style Sheets Layout/presentation on the WWW (comp.infosystems.www.authoring.stylesheets)


Discuss General question about DIV usability in the Cascading Style Sheets forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Hello
 
Posts: n/a

Default General question about DIV usability - 03-10-2005 , 12:31 AM






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.

Thank you.



Reply With Quote
  #2  
Old   
Lars Eighner
 
Posts: n/a

Default Re: General question about DIV usability - 03-10-2005 , 02:04 AM






In our last episode,
<YYQXd.6099$cN6.5041 (AT) newsread1 (DOT) news.pas.earthlink.net>,
the lovely and talented Hello
broadcast on comp.infosystems.www.authoring.stylesheets:

Quote:
Hello, I am a self-taught home developer:
Unfortunately, in this case it shows.

The fist step is to learn to write valid HTML. I don't think
you have done that, but your questions indicate that you do not
know what valid HTML is. If you do not begin with a valid
document, you only dig yourself in deeper and deeper by trying
to style your document.

Quote:
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?
DIV is an arbitrary *block* element. It can contain other block
elements (including other DIVs). P is block element for
paragraphs. P cannot contain other block elements; it cannot
contain other Ps; it cannot contain DIVs. DIV does not create a
new P. But DIV will close any P that is open.

Quote:
I tend to use SPAN because it does not generate any line break.
SPAN is an *inline* element. It cannot contain a block element.
SPAN is closed whenever the block containing it is closed.

Quote:
Am I missing something?
Yes, you seem to be missing even the most basic grasp of what
HTML is all about. There are many free tutorials on HTML
available on the web. Google for them, and work through a few.

Quote:
Why people like DIV so much? Please
explain because I do struggle for understanding of this topic.

--
Lars Eighner eighner (AT) io (DOT) com http://www.io.com/~eighner/
War on Terrorism: History a Mystery
"He's busy making history, but doesn't look back at his own, or the
world's.... Bush would rather look forward than backward." --_Newsweek_


Reply With Quote
  #3  
Old   
Spartanicus
 
Posts: n/a

Default Re: General question about DIV usability - 03-10-2005 , 03:45 AM



Lars Eighner <eighner (AT) io (DOT) com> wrote:

Quote:
The fist step is to learn to write valid HTML.
The first step is to mark up a document so that it's correctly
structured and semantically marked up, validity is far less important.

Quote:
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.

Quote:
SPAN is an *inline* element. It cannot contain a block element.
Span is an inline element in the html sense, it can be set to a block
level element with css, and it can contain other html inline elements
that have been set to block.

Quote:
SPAN is closed whenever the block containing it is closed.
Span should always be closed
http://homepage.ntlworld.com/spartanicus/lars.htm

--
Spartanicus


Reply With Quote
  #4  
Old   
Johannes Koch
 
Posts: n/a

Default Re: General question about DIV usability - 03-10-2005 , 04:04 AM



Spartanicus wrote:
Quote:
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.
div will close any p element that is open in HTML, not in XHTML. There
is no difference between Strict and Transitional versions.
--
Johannes Koch
In te domine speravi; non confundar in aeternum.
(Te Deum, 4th cent.)


Reply With Quote
  #5  
Old   
Alan J. Flavell
 
Posts: n/a

Default Re: General question about DIV usability - 03-10-2005 , 04:28 AM



On Thu, 10 Mar 2005, Lars Eighner wrote:

Quote:
There are many free tutorials on HTML available on the web.
Indeed there are, but relatively few of them are much good. All too
many of them are aimed at promoting some particular author's
(misguided) concept of HTML as "commands" for designing a visual
layout, for example.

I've been at this for too long to know what would be best for a
beginner, but the WDG (htmlhelp) site has some reliable material
IMHO.


Reply With Quote
  #6  
Old   
Spartanicus
 
Posts: n/a

Default Re: General question about DIV usability - 03-10-2005 , 05:03 AM



Johannes Koch <koch (AT) w3development (DOT) de> wrote:

Quote:
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.
Ah yes, I'm accustomed to the rules of my custom DTD :-)

--
Spartanicus


Reply With Quote
  #7  
Old   
thulsey
 
Posts: n/a

Default Re: General question about DIV usability - 03-10-2005 , 06:09 AM



Quote:
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



Reply With Quote
  #8  
Old   
Hello
 
Posts: n/a

Default Re: General question about DIV usability - 03-10-2005 , 07:43 AM



Thank you for your detailed answer.

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?

"thulsey" <thulsey (AT) gmail (DOT) com> wrote

Quote:
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




Reply With Quote
  #9  
Old   
thulsey
 
Posts: n/a

Default Re: General question about DIV usability - 03-10-2005 , 11:00 PM



Quote:
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?
Actually, as someone mentioned, it's easier if you can post an example
of what you've got/what you need and your current method.

There is definitely a way to do it in CSS, but it'd be guess-work at
the moment as to what exactly you require.

If I *do* understand you correctly, you could try padding-bottom: 1em;
or something to that affect.

Post more, we'll have a look.



Reply With Quote
  #10  
Old   
thulsey
 
Posts: n/a

Default Re: General question about DIV usability - 03-12-2005 , 03:59 AM



Quote:
How to pack the menu? I used SPAN tags + BR for a line break. What
would you
do?

Have you taken a look at using lists for the menu? Semantically,
that's what it is: a list of links. You can set list-style to none and
get rid of any default list decoration.
..rollover {
list-style: none;
}

<ul class="rollover">
<li><span>●</span>Menu
Option1</a></li>
</ul>



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.