2

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>
TylerH
  • 20,799
  • 66
  • 75
  • 101

3 Answers3

5

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>
Dale
  • 1,911
  • 11
  • 18
  • There is another way to doing this. We can use pseudo class rather changing to the element. We can use this code. header ul li { display: inline-block; padding: 10px 20px; margin-left: 10px; position: relative; } header ul li:before { background: #000; width: 100%; height: 100%; position: absolute; top: 0; left: 0; content: ""; z-index: -1; } header ul li a { display:inline-block; color:#fff; } – Harden Rahul Oct 14 '17 at 09:31
4

You need to add display: block (or inline-block) to the a inside the list items.

header ul li {
  display: inline-block;
  background: #f5c207;
  padding: 10px 20px;
  margin-left: 10px;
  transform: skew(-20deg);
}

header ul li a {
  display: 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>
Blazemonger
  • 90,923
  • 26
  • 142
  • 180
1

You're trying to skew an inline element. Transforms can only be applied to transformable elements, most commonly block-level elements. From the spec:

A transformable element is an element in one of these categories: an element whose layout is governed by the CSS box model which is either a block-level or atomic inline-level element, or whose display property computes to table-row, table-row-group, table-header-group, table-footer-group, table-cell, or table-caption an element in the SVG namespace and not governed by the CSS box model which has the attributes transform, ‘patternTransform‘ or gradientTransform.

To fix this set a to display: inline-block; or simply display: block;

CyberAP
  • 1,195
  • 1
  • 11
  • 17