473,378 Members | 1,555 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

General question about DIV usability

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.
Jul 21 '05 #1
11 4790
In our last episode,
<YY*****************@newsread1.news.pas.earthlink. net>,
the lovely and talented Hello
broadcast on comp.infosystems.www.authoring.stylesheets:
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.
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.
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.
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.
Why people like DIV so much? Please
explain because I do struggle for understanding of this topic.

--
Lars Eighner ei*****@io.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_
Jul 21 '05 #2
Lars Eighner <ei*****@io.com> wrote:
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.
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.
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.
SPAN is closed whenever the block containing it is closed.


Span should always be closed
http://homepage.ntlworld.com/spartanicus/lars.htm

--
Spartanicus
Jul 21 '05 #3
Spartanicus wrote:
Lars Eighner <ei*****@io.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.)
Jul 21 '05 #4
On Thu, 10 Mar 2005, Lars Eighner wrote:
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.
Jul 21 '05 #5
Johannes Koch <ko**@w3development.de> 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.


Ah yes, I'm accustomed to the rules of my custom DTD :-)

--
Spartanicus
Jul 21 '05 #6
>>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 >>youuse 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

Jul 21 '05 #7
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" <th*****@gmail.com> wrote in message
news:11********************@o13g2000cwo.googlegrou ps.com...
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 >>youuse 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

Jul 21 '05 #8
Hello wrote:

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


There is absolutely a better way, but please post a URL showing what you
have so far.

CSS layouts work best on well-structured, semantic (and validated) HTML.
Chances are, your code has turned into a pile of "div soup" that would
benefit from more appropriate markup.

--
Reply email address is a bottomless spam bucket.
Please reply to the group so everyone can share.
Jul 21 '05 #9
>
One more question:
Is it possible to use DIV but to force it not to produce a line break withCSS style?

I need a line break on the bottom but not on the top of some code block, Iused 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; orelse? 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.

Jul 21 '05 #10
How to pack the menu? I used SPAN tags + BR for a line break. What would you
do?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Blah</title>
<style type="text/css">
<!--
body {font: x-small Georgia, Tahoma, Helvetica, sans-serif;}
span.rollover { padding: 0 0 0 226px;}
span.rollover a {color: #0000FF;}
span.rollover a:hover {color: blue;}
span.rollover a:link span {color: #C0C0C0;}
span.rollover a:visited span {color: #C0C0C0;}
span.rollover a:hover span {color: blue;}
a:hover.roll, a:link.roll, a:visited.roll {text-decoration: none;}
a:hover.nroll, a:link.nroll, a:visited.nroll {text-decoration: none; color:
blue;}
span.nonroll {font: Georgia; padding: 0 0 0 220px; color: blue;}
-->
</style>
</head>
<body bgcolor="#C0C0C0">
<span class="rollover"><a class="roll" href="#"><span>●</span>Menu
Option1</a></span><br>
<span class="nonroll"><a class="nroll" href="#"><span style="font-family:
Helvetica; color: red;">►</span>Menu Current Page</a></span><br>
<span class="rollover"><a class="roll" href="#"><span>●</span>Menu
Option3</a></span><br>
<span class="rollover"><a class="roll" href="#"><span>●</span>Menu
Option4</a></span><br>
<span class="rollover"><a class="roll" href="#"><span>●</span>Menu
Option5</a></span><br>
</body>
</html>
"thulsey" <th*****@gmail.com> wrote in message
news:11**********************@l41g2000cwc.googlegr oups.com...

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.

Jul 21 '05 #11
>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>

Jul 21 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

111
by: Retlak | last post by:
The recommended (on dozens of websites) and effective (works in Netscape, MSIE, Mozilla, probably others) way to detect if a browser has Javascript turned off is to put this in the <head>: ...
9
by: Barbara de Zoete | last post by:
I am getting more and more confused as to the meaning of the words 'accessibility' and 'usability' *in the context of the world wide web*. What do these two words mean? How do they differ from one...
4
by: bissatch | last post by:
Hi, I am a web designer and have just recently took up the position of web marketer for a company managing their intranet and external website. I was interested in a book that provided good tips...
10
by: Steven T. Hatton | last post by:
# -- "If our hypothesis is about anything and not about some one or more particular things, then our deductions constitute mathematics. Thus mathematics may be defined as the subject in which we...
0
by: usable_us | last post by:
Hello, Oracle's Usability group will be conducting an incentive-based two hour usability activity. (This is not a job posting but an invitation to a two hour activity) This email was not...
11
by: Simon Shutter | last post by:
Forgive me if I am posting to wrong newsgroup and for a couple of loaded questions. First, from what I understand, one of the advantages of XHTML/CSS is the ability of screen readers/braille...
9
by: Gomaw Beoyr | last post by:
Two question about the "partial classes" (in the next wersion of ..NET). Question 1 ========== Will partial classes (in the next version of C#) have to be declared "partial" in ALL places. ...
65
by: Steven Watanabe | last post by:
I know that the standard idioms for clearing a list are: (1) mylist = (2) del mylist I guess I'm not in the "slicing frame of mind", as someone put it, but can someone explain what the...
60
by: deko | last post by:
As I understand it, most browser manufacturers have agreed on 16px for their default font size. So, this should be an accurate conversion for percentages: px % 16 = 100 14 = 87.5 13 =...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.