tags:

views:

47

answers:

4

Hello

What is the preferred methon to create something like

Apples   Apples can be
         green or red or
         more text more text

Bananas  Most of the time
         bananas are yellow
         (or green, if they're
         not ripe)

Item X   Each item should be aligned
         with the previous item, and
         each text (such as this 
         sentence) should be alligned
         with the previous text.

I have tried

.desc {
  margin-left: 140px;
  text-indent: -100px;
}

.item {
  width:100px;
}

...

<div class='desc'>
  <span class='item'>Apples</span> Apples can be green ....
</div>

But it didn't really give the result I expected (at least in Firefox).

Can someone help me here?

Thanks

René

A: 

A real table wouldn't seem to be out of line here since you seem to have tabular data. In that case you would just use the normal table syntax.

Shea Daniels
Thanks. I was thinking of a table myself, but since I might decide to have the "list" in a different visual format in some time to come, I hoped there would be a non-table solution.
René Nyffenegger
If you might have to change it, then the definition list that others are recommending would definitely work. I just wanted to point out that there's nothing wrong with tables if you're using them the right way (i.e. not just for layout).
Shea Daniels
It does *not* look like tabular data to me.
Josh Stodola
Sure it is. Just imagine it with column headings like Term and Definition. If you had to have another column (say, for instance, References) you'd be stuck using a table instead of being able to use definition list.
Shea Daniels
Strictly speaking, it's actually exactly a table display and nothing else. It's not a formatted list, it's not floated divs, it's not indented paragraphs. It's a table. I also think a table here is a superior solution to definition lists.
Tom
+1  A: 

It depends on data you want to use, but semantically speaking it seems like term and it's description, so dl hops in mind ^^

dt { display: block; float: left; width: 140px; }

<dl>
  <dt>Apples</dt>
  <dd>Description to it more lines of text to show it.</dd>
  <dt>Bananas</dt>
  <dd>Description to it more lines of text to show it.</dd>
  <dt>Lemon</dt>
  <dd>Description to it more lines of text to show it.</dd>
</dl>
Adam Kiss
+4  A: 

Semantically, this looks like a case for the little-known <dd> and <dt> elements.

The W3C reference has a nice example:

<DL>
  <DT>Dweeb
  <DD>young excitable person who may mature
    into a <EM>Nerd</EM> or <EM>Geek</EM>

  <DT>Hacker
  <DD>a clever programmer

  <DT>Nerd
  <DD>technically bright but socially inept person

</DL>

However, its default styling is not exactly what you want. Check out this article: Definition lists – misused or misunderstood? it has a number of styling examples:

  • Definition list with background images
  • Definition list as boxes
  • Styling a definition list to look like a table
Pekka
A: 

Using a two-column <table> would be a good solution here, assuming it isn't a very very long table as this loads differently from a bunch of divs or other elements.

Using a table will also leave you with the flexibility of formatting individual elements inside cells as you want, such as a bulleted list inside a <td>.

Tom