Skip to content

Instantly share code, notes, and snippets.

@giuseppeg
Created February 16, 2013 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giuseppeg/4968063 to your computer and use it in GitHub Desktop.
Save giuseppeg/4968063 to your computer and use it in GitHub Desktop.
CSS2.1 menu separator - no last-child or your best friend .last class :)
/**
* CSS2.1 menu separator - no last-child or your best friend .last class :)
*
* @author Giuseppe Gurgone <http://twitter.com/giuseppegurgone>
*/
ul li {
display: inline-block;
padding: 0 5%;
}
*+html ul li { display: inline; } /* IE7 inline-block */
ul li + li { border-left: 5px solid hotpink; } /* here you go */
/* The rules below are needed to style this testcase */
p { width: 50%; }
code {
padding: 0.2em 0.4em;
border-radius: 3px;
background-color: hotpink;
color: #fff;
font-weight: 600;
}
<h1>CSS2.1 menu separator</h1>
<p>A proof of concept to show you how to add a menu separator without using the CSS3 <code>:last-child</code> pseudo-selector or the ugly <code>.last</code> class</p>
<p>This is easily done using the CSS2.1 adiacent sibling selector <code>+</code> to apply a border left to all the <code>li</code> except the first one.</p>
<h2 id="demo">Demo</h2>
<ul>
<li>foo</li>
<li>bar</li>
<li>baz</li>
</ul>
// alert('Hello world!');
{"view":"separate","fontsize":"80","seethrough":"","prefixfree":"1","page":"all"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment