Is it possible to reproduce this image using only CSS?

I want to apply this to my menu, so the brown background appears on hover
instance
I don't know how to do this, I only have;
.menu li a:hover{
display:block;
background:#1a0000;
padding:6px 4px;
}
skew
a parent element (LI
) and inverse skew it's children elements

nav li {
display:inline-block;
transition: background 0.2s;
transform: skew(20deg); /* SKEW */
}
nav li a {
display:block;
text-decoration:none;
padding: 5px 10px;
font: 30px/1 sans-serif;
transform: skew(-20deg); /* INVERSE SKEW */
color: #0bf;
}
nav li.active,
nav li:hover{
background:#000;
}
<nav>
<ul>
<li><a href="#">Home</a></li>
<li class="active"><a href="#">Products</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
Here is a fiddle for use across different browsers - I created in a couple of minutes.
Try playing with the arguments, I used :before
and :after
to do this.
You can use the transform: skew(X, Y)
property to achieve this. Creating a skewed outer container, then skew the opposite amount on an inner container to skew the text back to being straight. See this fiddle for example;
From what you have said, I believe this is what you want, if not please clarify when the item should display the background.
To have IE support just add -ms-transform: skew(20deg, 0deg);
beside all the other transform: skew(20deg, 0deg);
s.
.skew {
background: green;
color: #fff;
padding: 50px;
transform: skewX(-7deg);
font-size: 20px;
font-weight: 700;
}
.skew p {
transform: skewX(7deg);
}
<div class="skew">
<p>This is caption</p>
</div>
Here's an example
来源:https://stackoverflow.com/questions/17947565/how-to-skew-element-but-keep-text-normal-unskewed