Petah
Petah

Reputation: 46040

Render nested list like a tree

How would I make the vertical border in this stop at the last element?

It can be CSS3/modern browser compatible only. But needs to work on various backgrounds (i.e. be transparent).

http://jsfiddle.net/ShgD6/

From this:

Unwanted list

To this:

Wanted list

Upvotes: 7

Views: 2328

Answers (2)

robynhenderson
robynhenderson

Reputation: 1368

I solved this via modifications to the css in this fiddle:

http://jsfiddle.net/YYdwc/2/

Upvotes: 9

Will
Will

Reputation: 151

You can select the last list item by using the CSS :last-child pseudo-class like this:

ul li:last-child {
    height: 0.7em;
}

Settings its height to 0.7em seemed to work for me, chopping off the tail on the left border. I added a few more nested groups in my fiddle to show it'll work even when the content changes and more nested groups are added.

http://jsfiddle.net/wdages/sC5pc/3/

Upvotes: 2

Related Questions