Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parallelogram navigation background with CSS

I'm trying to create this nav menu (green highlight is the active page, gray is hover state):

Nav Menu

I can make the parallelogram with the following CSS:

ul#nav li a {
    text-decoration:none;
    padding:4px 10px;
    border-radius:3px;
    transform: skew(-10deg);
    -o-transform: skew(-10deg);
    -moz-transform: skew(-10deg);
    -webkit-transform: skew(-10deg);
    color:#757575;
}

ul#nav li a:hover {
    background:#f3f1eb;
}

ul#nav li a.current-menu-item {
    color:#fff;
    background:#5d9732;
}

ul#nav li a.current-menu-item:hover {
    background:#5d9732;
}

Unfortunately, this causes the text to skew as well, appearing italic:

Nav Menu Skewed

Here's a jsfiddle showing the setup (although the skew doesn't work in jsfiddle): http://jsfiddle.net/K3bQJ/4/

Is there any way to prevent the skew of the text, so it doesn't appear italic? I'm loading jQuery but would prefer to avoid it or at least have a usable CSS fallback.

Thanks for any advice!

like image 714
R.J. Avatar asked Jul 10 '12 17:07

R.J.


1 Answers

Try this Add a span inside your tags and set it's skew to the opposite direction (note the use of skewX which is considered correct according to https://developer.mozilla.org/en/CSS/-moz-transform)

<ul id="nav">
    <li><a class="current-menu-item" href="#"><span>Nav Item 1</span></a></li>
<li><a href="#"><span>Nav Item 2</span></a></li>
<li><a href="#"><span>Nav Item 3</span></a></li>
</ul>

ul#nav li a {
    display: inline-block;
    text-decoration:none;
    padding:4px 10px;
    border-radius:3px;
            transform: skewX(-10deg);
         -o-transform: skewX(-10deg);
       -moz-transform: skewX(-10deg);
    -webkit-transform: skewX(-10deg);
    color:#757575;
}

ul#nav li a span {
    display: inline-block;
            transform: skewX(10deg);
         -o-transform: skewX(10deg);
       -moz-transform: skewX(10deg);
    -webkit-transform: skewX(10deg);
}
like image 189
Jason Sperske Avatar answered Oct 23 '22 15:10

Jason Sperske