Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

How to make two column list from array?

LEGEND ,
Oct 02, 2008 Oct 02, 2008

Copy link to clipboard

Copied

Hi All,

I want to display an unordered list, generated by an array, in two
columns. How can this be done?

> <ul>
> <?php
> // take text field and create array using explode
> $farray = explode(', ', $row_fieldArray['features']);
> // loop through the array to process each line
> foreach ($farray as $value) {
> // output each line as a <li> element
> echo "<li> $value </li>"; }
> ?>
> </ul>

I thought of enclosing the <ul> in a width constrained div and setting
the <li> to float left, but I know that shorter length <li> elements
will cause more bullets per "line" than longer ones. How can I create a
two or three column list of bullet points?

TIA

Brett
TOPICS
Server side applications

Views

853
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 02, 2008 Oct 02, 2008

Copy link to clipboard

Copied

.oO(Brett)

>I want to display an unordered list, generated by an array, in two
>columns. How can this be done?
>
>> <ul>
>> <?php
>> // take text field and create array using explode
>> $farray = explode(', ', $row_fieldArray['features']);
>> // loop through the array to process each line
>> foreach ($farray as $value) {
>> // output each line as a <li> element
>> echo "<li> $value </li>"; }
>> ?>
>> </ul>
>
>I thought of enclosing the <ul> in a width constrained div and setting
>the <li> to float left, but I know that shorter length <li> elements
>will cause more bullets per "line" than longer ones.

You could also give each li the same width (for example defined in em)
and then float them, but this might cause new problems and ugly gaps,
dependent on the text length in each li:

o 1st item o 2nd item o 3rd item
with some o 4th item
more text with some
more text
o 5th item o 6th item o 7th item
o 8th item o 9th item

>How can I create a
>two or three column list of bullet points?

Some other ideas:

1) Split the entire list into two or three lists, print them one after
another and use CSS to arrange them side by side. The example from above
could then look like this:

o 1st item o 4th item o 7th item
o 2nd item with some o 8th item
with some more text o 9th item
more text o 5th item
o 3rd item o 6th item

2) Use CSS 3(!) to let the browser automatically render the single list
in multiple columns. Will only work in Gecko-based browsers like Firefox
for now.

Micha

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 02, 2008 Oct 02, 2008

Copy link to clipboard

Copied

Thanks Micha,

I've decided to go with the first solution of specifying the width of
the <ul> element and setting a specific width for the <li> too. You are
right, it does leave gaps in between when some lines run longer, but I
don't find it too offensive.

Yes, the column support in CS3 is quite exciting, though who knows how
long it will be before it is fully supported, it could be a decade, ugh!

As always, thanks for your help.

Regards,

Brett

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 02, 2008 Oct 02, 2008

Copy link to clipboard

Copied

.oO(Brett)

>Thanks Micha,
>
>I've decided to go with the first solution of specifying the width of
>the <ul> element and setting a specific width for the <li> too. You are
>right, it does leave gaps in between when some lines run longer, but I
>don't find it too offensive.

OK. I just got the same effect a while ago in an image gallery, which
contained images of different height. Sometimes it was just a single
pixel, but it was enough to cause such gaps. And in a gallery this looks
really ugly. If it's not too bad in your case - good.

>Yes, the column support in CS3 is quite exciting, though who knows how
>long it will be before it is fully supported, it could be a decade, ugh!

True. But I've already played around a bit with it. I tried it on track
listings of music CDs. In most browsers it was just a single list, but
FF showed it as a two-column list. Looked good.

It's nothing important, but IMHO a nice-to-have little effect. I even
use the 'text-shadow' property on my headings, although at the moment
Opera 9.5 is the only browser which fully supports it. ;-)

>As always, thanks for your help.

You're welcome.

Micha

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 02, 2008 Oct 02, 2008

Copy link to clipboard

Copied

On 02 Oct 2008 in macromedia.dreamweaver.appdev, Michael Fesser wrote:

> True. But I've already played around a bit with it. I tried it on track
> listings of music CDs. In most browsers it was just a single list, but
> FF showed it as a two-column list. Looked good.

Got a sample?

--
Joe Makowiec
http://makowiec.net/
Email: http://makowiec.net/contact.php

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 02, 2008 Oct 02, 2008

Copy link to clipboard

Copied

Micha,

In this case it is only text, which is a feature list and will most
likely be short phrases, so the first solution will be fine. As you
pointed out, this would really only work with an unordered list, as an
ordered list will appear out of order. Furthermore, I think limiting it
to a two-column list is wise since the "gaps" issue compounds as more
columns are added.

Brett

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 02, 2008 Oct 02, 2008

Copy link to clipboard

Copied

.oO(Joe Makowiec)

>On 02 Oct 2008 in macromedia.dreamweaver.appdev, Michael Fesser wrote:
>
>> True. But I've already played around a bit with it. I tried it on track
>> listings of music CDs. In most browsers it was just a single list, but
>> FF showed it as a two-column list. Looked good.
>
>Got a sample?

Hmm, not online anymore. I think I still have the CSS somewhere.
Would you like to see a live example or just the HTML/CSS?

Micha

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 02, 2008 Oct 02, 2008

Copy link to clipboard

Copied

On 02 Oct 2008 in macromedia.dreamweaver.appdev, Michael Fesser wrote:

> .oO(Joe Makowiec)
>
>>On 02 Oct 2008 in macromedia.dreamweaver.appdev, Michael Fesser
>>wrote:
>>
>>> True. But I've already played around a bit with it. I tried it on
>>> track listings of music CDs. In most browsers it was just a single
>>> list, but FF showed it as a two-column list. Looked good.
>>
>>Got a sample?
>
> Hmm, not online anymore. I think I still have the CSS somewhere.
> Would you like to see a live example or just the HTML/CSS?

Either way. I suppose from your description that the HTML would be just
a straight ul? The difference is in the CSS?

--
Joe Makowiec
http://makowiec.net/
Email: http://makowiec.net/contact.php

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 02, 2008 Oct 02, 2008

Copy link to clipboard

Copied

.oO(Joe Makowiec)

>On 02 Oct 2008 in macromedia.dreamweaver.appdev, Michael Fesser wrote:
>
>> .oO(Joe Makowiec)
>>
>>>On 02 Oct 2008 in macromedia.dreamweaver.appdev, Michael Fesser
>>>wrote:
>>>
>>>> True. But I've already played around a bit with it. I tried it on
>>>> track listings of music CDs. In most browsers it was just a single
>>>> list, but FF showed it as a two-column list. Looked good.
>>>
>>>Got a sample?
>>
>> Hmm, not online anymore. I think I still have the CSS somewhere.
>> Would you like to see a live example or just the HTML/CSS?
>
>Either way. I suppose from your description that the HTML would be just
>a straight ul? The difference is in the CSS?

It was a normal ordered list with two special CSS properties (Mozilla-
only until now). I've found the old page and will put a short example
online the next days.

Micha

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 03, 2008 Oct 03, 2008

Copy link to clipboard

Copied

On 02 Oct 2008 in macromedia.dreamweaver.appdev, Michael Fesser wrote:

> It was a normal ordered list with two special CSS properties (Mozilla-
> only until now). I've found the old page and will put a short example
> online the next days.

Thanks!

--
Joe Makowiec
http://makowiec.net/
Email: http://makowiec.net/contact.php

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 03, 2008 Oct 03, 2008

Copy link to clipboard

Copied

Joe,

A while back I fooled around with CSS3 column support, here is an
excerpt of my stylesheet and markup (I'm only including one <li> element
for brevity sake).

body {
width: 92%;
min-width: 640px;
margin: auto;
}
h1 {
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size: 1.5em;
}
h2 {
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size: 1.25em;
}
div#content {
width: 100%;
border: thin solid black;
}
ul {
padding: 1em 2em;
column-width: 18em;
column-gap:25px;
list-style-type:none;

-moz-column-width: 18em;
-moz-column-gap: 25px;
-moz-column-rule: thin solid black;
}
li {
margin-top:1em;
}
</style>
</head>

<body>
<div id="content">
<ul>
<h1>Primary headline.</h1>
<li>Placerat vel magna nonummy demonstraverunt lobortis. Luptatum soluta
vel nihil sollemnes habent. Ipsum fiant eleifend legentis insitam
suscipit. In exerci delenit eodem ad iusto. Formas lobortis processus
mirum litterarum littera. Illum mazim typi ut est aliquam. Qui claritas
vel qui tempor cum. Quarta tation augue dolor dignissim duis.</li>

In Firefox, this displays as either two or three or more columns
depending on the width of the browser viewport. The min-width
declaration prevents it from collapsing to one column. You must use the
-moz prefix in your declaration, the normal one is for other browsers,
if and when they decide to support it so it's good to include it now.
It is exciting to see the columns of text re-flow as the browser window
resizes, but you can end up with widows and orphans. I think they are
working on some fixes for that, but which browsers will implement it and
when is always the question.

Anyway, play around with it to see what the future looks like.

Brett


Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 03, 2008 Oct 03, 2008

Copy link to clipboard

Copied

On 03 Oct 2008 in macromedia.dreamweaver.appdev, Brett wrote:

> Anyway, play around with it to see what the future looks like.

Thanks!

--
Joe Makowiec
http://makowiec.net/
Email: http://makowiec.net/contact.php

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 04, 2008 Oct 04, 2008

Copy link to clipboard

Copied

.oO(Michael Fesser)

>It was a normal ordered list with two special CSS properties (Mozilla-
>only until now). I've found the old page and will put a short example
>online the next days.

OK, here we go:

http://mfesser.de/test/tracks.html

This was part of an eBay auction a while ago. The links don't work,
because the samples are not online anymore. In Firefox it will be
rendered in two columns, all other browsers just show a normal list.

Micha

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 04, 2008 Oct 04, 2008

Copy link to clipboard

Copied

On 04 Oct 2008 in macromedia.dreamweaver.appdev, Michael Fesser wrote:

> .oO(Michael Fesser)
>
>>It was a normal ordered list with two special CSS properties (Mozilla-
>>only until now). I've found the old page and will put a short example
>>online the next days.
>
> OK, here we go:
>
> http://mfesser.de/test/tracks.html
>
> This was part of an eBay auction a while ago. The links don't work,
> because the samples are not online anymore. In Firefox it will be
> rendered in two columns, all other browsers just show a normal list.

Thanks! That's easy. Works as advertised (sort of - if you go too
narrow with a browser window, the columns overlap).

--
Joe Makowiec
http://makowiec.net/
Email: http://makowiec.net/contact.php

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 04, 2008 Oct 04, 2008

Copy link to clipboard

Copied

LATEST
.oO(Joe Makowiec)

>On 04 Oct 2008 in macromedia.dreamweaver.appdev, Michael Fesser wrote:
>
>> OK, here we go:
>>
>> http://mfesser.de/test/tracks.html
>>
>> This was part of an eBay auction a while ago. The links don't work,
>> because the samples are not online anymore. In Firefox it will be
>> rendered in two columns, all other browsers just show a normal list.
>
>Thanks! That's easy.

You're welcome.

>Works as advertised (sort of - if you go too
>narrow with a browser window, the columns overlap).

Quite possible. But such little problems should be solvable ('min-width'
for example). I haven't tried it any further since then, but maybe I'll
play with it again if I should need such a listing somewhere.

Micha

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines