Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to skew element but keep text normal (unskewed)

Tags:

css

css-shapes

Is it possible to reproduce this image using only CSS?

enter image description here

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; } 
like image 887
Preston Avatar asked Jul 30 '13 12:07

Preston


People also ask

How do you skew an element but keep text normal?

NOTE: SPAN is NOT affected by transform CSS functionality, so you will need a DIV or change span to display: block; otherwise they will NOT be affected. So just put the TEXT inside a separate div and unskew it. Show activity on this post. You can generate your clip from here and use it in your code.

How do you skew an element?

CSS | skew() Function ax: This parameter holds the angle representing the horizontal axis to distort an element. ay: This parameter holds the angle representing the vertical axis to distort an element. If it is not defined then it takes the default value zero. It means completely skew in x direction.

How do you skew an element in CSS?

Syntax. The skew() function is specified with either one or two values, which represent the amount of skewing to be applied in each direction. If you only specify one value it is used for the x-axis and there will be no skewing on the y-axis.

How do you skew one side of a div?

Try this: To unskew the image use a nested div for the image and give it the opposite skew value. So if you had 20deg on the parent then you can give the nested (image) div a skew value of -20deg. @darthmaim's answer (below) to use a psuedo (before or after) to skew the inner border's should be the accepted answer.


2 Answers

skew a parent element (LI) and inverse skew it's children elements

CSS Menu skewed buttons diagonal borders

nav ul {   padding: 0;   display: flex;   list-style: none; } nav li {   transition: background 0.3s, color 0.3s;   transform: skew(20deg); /* SKEW */ }  nav li a {   display: block; /* block or inline-block is needed */   text-decoration: none;   padding: 5px 10px;   font: 30px/1 sans-serif;   transform: skew(-20deg); /* UNSKEW */   color: inherit; }  nav li.active, nav li:hover {   background: #000;   color: #fff; }
<nav>   <ul>     <li><a href="#">Home</a></li>     <li class="active"><a href="#">Products</a></li>     <li><a href="#">Contact</a></li>   </ul> </nav>
like image 112
Roko C. Buljan Avatar answered Sep 21 '22 18:09

Roko C. Buljan


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.

https://jsfiddle.net/DTBAE/

like image 22
udidu Avatar answered Sep 20 '22 18:09

udidu