Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slanted element in 3D space with CSS3

Tags:

html

css

shapes

I'd like to make this slanted / rotated element with CSS3.

enter image description here

I've tried with clip-path but after the shape is created I can't add border, box-shadow or border-radius to it.

clip-path: polygon(5% 7%, 98% 0, 100% 83%, 0 74%);

I've tried with transform but this is not only rotated, because the sides have different orientation. Also I've tried with SVG, but information that I've found was insufficient for me to find a solution to my problem. This is my last solution, I'd rather use CSS3 than SVG, if possible...
Any sugestions?

like image 364
Andrew Avatar asked Sep 02 '25 02:09

Andrew


1 Answers

You can use CSS3 rotate3dMDN

  • perspective on a parent element
  • transform: rotate3d(x, y, z, a) on it's child

/*QuickReset*/ *{margin:0;box-sizing:border-box;} html,body{height:100%;font:14px/1.4 sans-serif;}
body{background: #2C8BF9;}



.slantedParent{
  position:relative;
  width: 300px; height:200px;
  top:10px; left:10px;
  
  perspective: 800px;
}


.slanted{
  background: #fff;
  border-radius: 32px;
  height:100%;
  padding: 32px;
  box-shadow: 0 8px 16px rgba(0,0,0,0.1);
  
  transform: rotate3d(3, -2, 0.4, 25deg); /* play with those values */
}
<div class="slantedParent">
  <div class="slanted">
    <h1>Some content?</h1>
  </div>
</div>
like image 106
Roko C. Buljan Avatar answered Sep 04 '25 15:09

Roko C. Buljan