Forum Moderators: not2easy

Message Too Old, No Replies

Using an Unordered List as a Table

ideas please

         

Deleted

7:06 am on Jun 15, 2006 (gmt 0)



Good day all,

what I'm trying to accomplish is a list that behaves like a grid (table).

Not that it doesn't work, it works, but only under certain circumstances (e.g. small font, no background colors, border problems are just around the corner...).

I want this list to be displayed correctly under any circumstance, no matter if there are 20 <h1>'s in it or if the padding of each list item is set to 12 em. If you do that now, the list items will render off (intended) position.

Also, the .specs classed #divs have to float (both left and right if needed), but that's not a big deal.

If one would be so kind as to lend me a hand, I would be much appreciative.

Sincerely,

Deleted.

This is what I got so far:

------------------------------------
The styles:

.grid {
font-size:10px;
font-family:verdana;
width:350px;
float:left;
border:0px solid red;
margin:10px;
}
.grid ul {
padding:0;
margin:0;
list-style:none;
width:100%;
border:1px solid silver;
border-top-width:0;
}
.grid ul li {
float:right;
border-top-width:0;
border-right-width:0;
border-left:1px solid silver;
width:38%;
padding:1px;
}
.grid .first {
float:left;
border-left-width:0;
width:60%;
}

---------------------------
The HTML:

<div class="grid">
<ul>
<li class="first">Field</li>
<li>Value</li>
</ul>
<ul>
<li class="first">Field</li>
<li>Value</li>
</ul>
<ul>
<li class="first">Field</li>
<li>Value<br />Value<br />Value<br />Value</li>
</ul>
<ul>
<li class="first">Field</li>
<li>Value</li>
</ul>
</div>

<div class="grid">
<ul>
<li class="first">Field</li>
<li>Value</li>
</ul>
<ul>
<li class="first">Field</li>
<li>Value<br />Value<br />Value<br />Value</li>
</ul>
<ul>
<li class="first">Field</li>
<li>Value</li>
</ul>
<ul>
<li class="first">Field</li>
<li>Value</li>
</ul>
<ul>
<li class="first">Field</li>
<li>Value</li>
</ul>
</div>

mattur

8:16 am on Jun 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd guess the best option is to use tables - the data doesn't appear to fit into the limited syntax of an unordered list. Alternatively, a <dl> list might be applicable.

Deleted

8:18 am on Jun 15, 2006 (gmt 0)



A <dl> list?
Go on, you've excited me :-)
Can you give an example?

Robin_reala

8:30 am on Jun 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A <dl> element marks up a 'definition' list - that is, a list of terms and their definitions. It's a useful replacement for a simple <table> at times, although it's worth thinking about whether your data really fits this pattern. Sample markup for a <dl> would be:

<dl>
<dt>Eggs</dt>
<dd>Tasty round food</dd>
<dt>Bacon</dt>
<dd>Food made out of pigs</dd>
</dl>

Each <dt> (term) has an associated <dd> (definition). <dl>s allow for 1-to-many and many-to-1 relationships to be expressed as well by using multiple <dt>s followed by one <dd>, or vice versa.

The default styling on a <dl> isn't very table-like but you can approximate a normal table styling with CSS like:

dt {
width: 12em; /* plucked out of thin air */
float: left;
clear: left;
}
dd {
float: left;
}

benihana

8:34 am on Jun 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



really looks like tabular data to me ;)

Deleted

8:41 am on Jun 15, 2006 (gmt 0)



Robin_reala:

Thanks alot, I've tried it, it works better than the list items, so thanks for that (-;

The only problem left are some borders overlappeng (I think I can fix that myself...) and some weird spacing between each <dl>

This has to look and act as a 2 column table, borders and cell-growth including ...

It still breaks down if one messes with the size, padding (larger dan 2px) etc... :(

This is what I have so far:

---------------------------
.specs {
font-size:11px;
font-family:verdana, sans-serif;
margin:5px;
width:300px;
float:left;
}
.specs dt,
.specs dd {
border:1px solid silver;
float: left;
margin:0;
padding:2px;
width:48%;
border-bottom:0;
}
.specs dt {
clear: left;
border-right:0;
border-left:0;
}
.specs dl {
padding:0;
margin:0;
}
.last dd,
.last dt {
border-bottom-width:1px;
}
.specs dd {
border-right:0;
}

<div class="specs">
<dl>
<dt>Field</dt>
<dd>Value</dd>
</dl>
<dl>
<dt>Field</dt>
<dd>Value</dd>
</dl>
<dl>
<dt>Field</dt>
<dd>Value<br />Value<br />Value<br />Value</dd>
</dl>
<dl class="last">
<dt>Field</dt>
<dd>Value</dd>
</dl>
</div>

mattur

1:15 pm on Jun 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Use tables (sorry for mentioning <dl>'s). Is there any reason why you don't want to use tables?

doodlebee

3:50 pm on Jun 15, 2006 (gmt 0)

10+ Year Member



I'm in agreement - I'd use tables. They *are* for tabular data!