Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slanted border using CSS [duplicate]

Tags:

css

css-shapes

How could I style a div to like the below image?

enter image description here

like image 731
Arun Bertil Avatar asked Nov 13 '15 10:11

Arun Bertil


People also ask

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.


1 Answers

You can use half triangle with the pseudo element.

.container {
  padding: 20px;
  background-color: #F8F8F8;
  max-width: 200px;
}
.rectangle {
  width: 200px;
  height: 100px;
  background-color: #003781;
  position: relative;
}
.rectangle:after {
  content: '';
  position: absolute;
  bottom: 0;
  right: 0;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0 0 25px 25px;
  border-color: transparent transparent #F8F8F8 transparent;
}
<div class="container">
  <div class="rectangle"></div>
</div>

Jsfiddle

like image 50
Alex Avatar answered Sep 20 '22 09:09

Alex