Grazie ragazzi, risposte utili che mi ha fatto leggere un po ', e alla fine ho letto this article e rimosso tutta la dipendenza da JavaScript e utilizzato lo pseudo-selettore nth-last-of-type
per applicare lo sfondo speciale agli ultimi elementi di una lista (ignorando l'ul che viene dopo l'ultimo li).
Il codice finale è here. Accetterò la mia risposta, a meno che qualcuno non indichi qualche problema. (Non credo che la compatibilità con i vecchi browser sia importante per me in questa fase.)
Grazie a @Aram per la risposta. @OneTrickPony, la tua risposta è andata oltre la testa di questo noob :) Sono sicuro che fa la cosa giusta, ma è un po 'troppo complicato per me.
<style type="text/css">
/* ul[class=tree] and every ul under it loses all alignment, and bullet
* style.
*/
ul.tree, ul.tree ul {
list-style-type: none;
margin:0;
padding:0;
}
/* Every ul under ul[class=tree] gets an indent of 1em, and a background
* image (vertical line) applied to all nodes under it (repeat-y)
*/
ul.tree ul {
padding-left: 1em;
background: url(vline.png) repeat-y;
}
/* ... except the last ul child in every ul; so no vertical lines for
* the children of the last ul
*/
ul.tree ul:last-child {
background: none;
}
/* Every li under ul[class=tree]
* - gets styling to make it bold and blue, and indented.
* - gets a background image (tilted T), to denote that its a node
* - sets height to match the height of background image
*/
ul.tree li {
margin:0;
padding: 0 1.2em;
background: url(node.png) no-repeat;
line-height: 20px;
color: #369;
font-weight: bold;
}
/* The last li gets a different background image to denote it as the
* end of branch
*/
ul.tree li:nth-last-of-type(1) {
background: url(lastnode.png) no-repeat;
}
fonte
2013-02-17 20:10:49
inviare sempre il relativo codice e markup ** nella domanda stessa **, non fare proprio collegamento. http://meta.stackexchange.com/questions/118392/add-stack-overfow-faq-entry-or-similar-for-putting-code-in-the-question –