I think I might have cracked this in pure CSS... it does contain a bit of a hack to reverse the natural z-index
which I don't like, but it sorts things out.
The theory is this: you set a fixed height for the li
and give it a border-top-width
of the same value. You can then "stack" the list items on top of one and other so that the top border can "pretend" to be the background for the item above.
Enough gassing let's show the code...
JSFiddle: http://jsfiddle.net/gvee/Awjmp/
HTML
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
</ul>
CSS
* {
margin: 0;
border: 0;
padding:0;
}
ul {
width: 200px;
border: 1px solid black;
list-style-type: none;
background-color: #eee;
margin: 10px;
overflow: hidden;
/* stop the first item's border bursting the container */
}
li {
height: 20px;
border-top-width: 20px;
/* li.height */
border-top-style: solid;
border-top-color: #eee;
/* ul.background-color */
position: relative;
margin-top: -20px;
/* -li.height */
}
li:hover {
background-color: red;
/* "current" colour */
border-top-color: yellow;
/* "previous" colour */
}
li:hover + li {
background-color: lime;
/* "next" colour */
}
/* HACK... reverse the natural z-index */
li:nth-child(9) {
z-index: 1
}
li:nth-child(8) {
z-index: 2
}
li:nth-child(7) {
z-index: 3
}
li:nth-child(6) {
z-index: 4
}
li:nth-child(5) {
z-index: 5
}
li:nth-child(4) {
z-index: 6
}
li:nth-child(3) {
z-index: 7
}
li:nth-child(2) {
z-index: 8
}
li:nth-child(1) {
z-index: 9
}