You are here: Re: Really stupid newb question- <div> « HTML « IT news, forums, messages
Re: Really stupid newb question- <div>

Posted by Andy Dingley on 12/13/55 11:49

Jeremy Brown wrote:
> OK, I see the <div> tag referred to allot- What exactly does it do and what
> is its usage?

What does it do? - Not a lot.
What can it do? - A great deal.

It's there as a deliberately anonymous way of structuring your content.
It adds little implicit behaviour (i.e. your browser will barely show
you a difference) but it lets you hook lots of new behaviours onto it,
typically through CSS.

<div> has a closely related element called <span>. They're used in
similar ways, but <div> is a block-level element and <span> is inline
(*). In HTML this means you can put <span> inside <div>, but you
CANNOT put <div> inside <span>. Similarly for other block level
elements like <p> or inlines like <b>. <div> offers a bit extra
though, in that you can put <div> or <p> inside a <div>, even though
you couldn't put either inside <p>. You can't change any of this
stuff - you're stuck with it.

<div> also has some CSS behaviours attached to it. These have implicit
values (in the browser), but you can (and will) easily change them by
writing your own stylesheets. In particular, <div> has the
"display:block;" declaration and <span> has "display:inline;" This
makes <div> render on your page with linebreaks around it, but <span>
flows with the text. These values are usually adequate, but they're
easily changed. Typically you make <div> display:inline; so that you
can have valid HTML that looks like inline text, even though it has
HTML content in it that couldn't be placed into a <span>.

By using the <div class="..." > attribute, you can attach CSS to
specific <div>s on a page. This is how you control presentation and
layout these days.

You _could_ write a whole HTML page using little more than <div> and
CSS. It would even look good. But this wouldn't be a good idea. If you
have "a paragraph" according to the rules of language and grammar, then
still mark it up as <p>. Use <div> when you need to define blocks of
content (for any reason) and they don't fit a more specific HTML
element type (and you can't use <span> instead)

There's also an id attribute that you can attach to elements. This is
mainly used for JavaScript, as a way of "finding" blocks on a page so
that they can either be read or modified. You can also use id to hang
your CSS onto, a bit like class.


(*) Strictly HTML doesn't have such an idea as "block level elements".
It describes this in two separate ways, "Where you can use this
element" and "What else you can put into this element". Generally
though these two are the same and we can talk about "a block element"
or "an inline element". To understand this fully you'll need to learn
about concepts like "DTD" and "validity" -- search this newsgroup, or
c.i.w.a.h

I've also simplified many of the technical details of HTML, so as to
fit an introduction into this short post. Bean counters can sod off!

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация