'How to create italic box in css?

How to create italic box in css like this

enter image description here

my code is

.ml {
  list-style-type: none;
  margin: 0;
  padding: 0;
}

.ml li {
  display: inline-block;
  border: solid 1px #000;
  font-style: italic;
  padding: 5px 10px;
}

.ml li.active,
.ml li:hover {
  background: #000;
  color: #ffffff
}
<ul class="ml">
  <li class="active">day</li>
  <li>week</li>
  <li>month</li>
  <li>year</li>
</ul>
css


Solution 1:[1]

Just need to add skew property to your CSS

.ml {
    list-style-type: none;
    margin: 0;
    padding: 0;
}

.ml li {
    display: inline-block;
    border: solid 1px #000;
    font-style: italic;
    padding: 5px 10px;
    transform: skewX(-20deg);
}

.ml li.active,
.ml li:hover {
    background: #000;
    color: #ffffff
}
<ul class="ml">
    <li class="active">day</li>
    <li>week</li>
    <li>month</li>
    <li>year</li>
</ul>

Solution 2:[2]

The problem with some of the answers I've seen thus far is that the text becomes over-skewed. The <li>s are already italic, but adding skew to the elements makes the effect over-pronounced.

enter image description here

We want the boxes skewed, but the text left alone.

enter image description here

To do this, I add a span to each li and unskew the text in the inverse direction.

/* Keep things organized and store skew value in CSS variable */
:root {
  --skew-value: -20deg;
}

.ml {
  list-style-type: none;
  margin: 0;
  padding: 0;
}

.ml li {
  display: inline-block;
  border: solid 1px #000;
  font-style: italic;
  padding: 5px 10px;
 
  /* Skew the box */
  transform: skew(var(--skew-value));
}

.ml li > span {
  /* Unskew the text */
  transform: skew(calc(var(--skew-value) * -1));
  display: inline-block;
}

.ml li.active,
.ml li:hover {
  background: #000;
  color: #ffffff
}
<ul class="ml">
  <li class="active"><span>day</span></li>
  <li><span>week</span></li>
  <li><span>month</span></li>
  <li><span>year</span></li>
</ul>

http://jsfiddle.net/xftywz1h/

Solution 3:[3]

Try this

div {
  width: 300px;
  height: 100px;
  background-color: yellow;
  border: 1px solid black;
  margin:20px;
}

div#myDiv {
  -ms-transform: skewX(-20deg); /* IE 9 */
  -webkit-transform: skewX(-20deg); /* Safari */
  transform: skewX(-20deg); /* Standard syntax */
}
<!DOCTYPE html>
<html>
<head>

</head>
<body>

<div id="myDiv">
This div element is skewed 20 degrees along the X-axis.
</div>

</body>
</html>

Solution 4:[4]

You can try this:

you can't show box font-style italic its needed transform and value skewX, because of the scewX rotate the box normally X-axis, and a box rotates this inner element or children auto rotate.

.ml{
list-style-type:none;margin:0;padding:0;}
.ml li {
  display:inline-block;
  border:solid 1px #000;
  font-style:normal;
  padding:5px 10px;
  transform:skewX(-15deg);
  text-transform: uppercase;
  margin-right: 5px;
}

.ml li.active, 
.ml li:hover {
   background:#000; color:#ffffff
}
<ul class="ml">
  <li class="active">day</li>
  <li>week</li>
  <li>month</li>
  <li>year</li>
</ul>

Solution 5:[5]

Here what you need, You might need tot use one more wrapper to retain the border property

html

<ul class="ml">
<li class="active"><span>day</span></li>
<li><span>week</span></li>
<li><span>month</span></li>
<li><span>year</span></li>
</ul>

CSS

.ml li:after, .ml li span:after {
  content: '';
  position: absolute;
  bottom: -1px;
  right: -1.5px;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0 0 31px 5px;
  border-color: transparent transparent #f8f8f8 transparent;
}

.ml li:before, .ml li span:before {
  content: '';
  position: absolute;
  top: -1px;
  left: 0px;
  width: 0;
  height: 0;
  border-style: solid;
 border-width: 30px 5px 0 0;
    border-color: #000 transparent transparent transparent;
}

.ml li span:before{
  left: -1px;
  border-color: #F8F8F8 transparent transparent transparent;
}

.ml li span:after{
  right: -0.5px;
  border-color: transparent transparent #000 transparent;
}

jsfiddle see working copy here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Thegerdfather
Solution 2
Solution 3 Biswajit Nath
Solution 4 Md. Abu Sayed
Solution 5 Anto