Search code examples
csscss-transformsskew

How to skew a ul li but not the <a> in ul li a?


I have a ul li a menu and want to skew the ul li but not the a. The ul li skews, but the a won't skew to normal position.

header ul li {
    display: inline-block;
    background: #f5c207;
    padding: 10px 20px;
    margin-left: 10px;
    transform: skew(-20deg);
}
header ul li a {
    transform: skew(20deg);
}
<div id="top" class="container">
    <ul>
        <li><a href="">About us</a></li>
        <li><a href="">Other</a></li>
        <li><a href="">Contact</a></li>
    </ul>
</div>


Solution

  • You can't skew inline elements, try this:

    header ul li {
        display: inline-block;
        background: #f5c207;
        padding: 10px 20px;
        margin-left: 10px;
        transform: skew(-20deg);
    }
    header ul li a {
        display:inline-block;
        transform: skew(20deg);
    }
    <header id="top" class="container">
        <ul>
            <li><a href="">About us</a></li>
            <li><a href="">Other</a></li>
            <li><a href="">Contact</a></li>
        </ul>
    </header>