How to make a polygon div in CSS - html

I am able to make a normal square div and a triangle div in CSS. But I don't know how to make such a shape with a single div. Can anyone help me out ?
Also I want this to spread to the entire width of it's parent but border properties don't support percentages. ( eg border-left: 160px solid transparent; )
.container{
width: 100%;
position: relative;
}
.v-div {
width: 0;
height: 0;
border-left: 160px solid transparent;
border-right: 160px solid transparent;
border-top: 100px solid #f00;
}
.box{
height: 80px;
width: 320px;
background: red;
}
<div class="container">
<div class="box">
</div>
<div class="v-div">
</div>
</div>

you can use clip path css property
#clippedDiv{
width:200px;
height:200px;
background-color:red;
-webkit-clip-path: polygon(50% 0%, 100% 0, 100% 35%, 50% 70%, 0 35%, 0 0);
clip-path: polygon(50% 0%, 100% 0, 100% 35%, 50% 70%, 0 35%, 0
}
<div id="clippedDiv"></div>
for more shapes you can visit http://bennettfeely.com/clippy/

you can do it with :after pseudo classes. If you uncomment the :before in this example you get a hexagon
#hexagon{
position: relative;
height:100px;
width:50%;
color: white;
background: green;
padding-bottom: 15%;
overflow:hidden;
background-clip: content-box;
}
#hexagon:after {
content: "";
position: absolute;
top:100px;
left: 0;
background-color:green;
padding-bottom: 50%;
width: 57.7%;
transform-origin: 0 0;
transform: rotate(-30deg) skewX(30deg);
}
<div id="hexagon"></div>

use :after css selector.
.container{
width: 100%;
position: relative;
margin-top: 100px;
}
.box {
width: 100px;
height: 55px;
background: red;
position: relative;
}
.box:after {
content: "";
position: absolute;
bottom: -25px;
left: 0;
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-top: 25px solid red;
}
<div class="container">
<div class="box">
</div>
</div>

<svg width="12cm" height="4cm" viewBox="0 0 1200 400"
xmlns="http://www.w3.org/2000/svg" version="1.1"><polygon fill="lime" stroke="blue" stroke-width="10" points="850,75 958,137.5 958,262.5 850,325 742,262.6 742,137.5" /></svg>

Related

Create right responsive arrow [duplicate]

I am trying to create an arrow label, using css :after
.one-line {
font-size: 2em;
width: 150px;
min-height: 50px;
height: auto;
background: blue;
margin: 5px;
position: relative;
color: #fff;
}
.one-line:after {
content: '';
display: block;
position: absolute;
top: 0;
left: 100%;
width: 0;
height: 0;
border-top: 25px solid transparent;
border-bottom: 25px solid transparent;
border-left: 25px solid red;
}
<div class="one-line">text<br>text<br></div>
I want the after element to take the same height which is of parent, how can I do this by either css or js?
Note: The text inside the label is dynamically populating. [Max length of text: 2 lines]
It might not be possible, as I am thinking, to adjust it any height of parent. Currently I am trying it to adjust for both one and two lines of text.
Here is a solution using clip-path. The idea is to use % values in the polygon to only show the needed shape and it will always work whatever the height is:
.one-line {
font-size: 2em;
width: 150px;
min-height: 50px;
height: auto;
background: blue;
margin: 5px;
position: relative;
color: #fff;
}
.one-line:after {
content: '';
display: block;
position: absolute;
top: 0;
bottom: 0;
width: 25px;
right: -25px;
background: red;
-webkit-clip-path: polygon(100% 50%, 0 0, 0 100%);
clip-path: polygon(100% 50%, 0 0, 0 100%);
}
<div class="one-line">text<br>text<br></div>
<div class="one-line">text<br>text<br>text<br></div>
<div class="one-line">text</div>
<div class="one-line">text<br>text<br>text<br>text<br>text<br>text<br>text<br></div>
Here is another solution that rely on both pseudo elements and some skew transformation to create the arrow. You will notice that this one will keep ratio of the arrow.
.one-line {
font-size: 2em;
width: 150px;
min-height: 50px;
height: auto;
background: blue;
margin: 5px;
position: relative;
color: #fff;
}
.one-line:after {
content: '';
display: block;
position: absolute;
top: 0;
height: 50%;
width: 50%;
right: -25px;
background: red;
transform: skewX(20deg) translateX(-33%);
transform-origin: top;
z-index: -1;
}
.one-line:before {
content: '';
display: block;
position: absolute;
bottom: 0;
height: 50%;
width: 50%;
right: -25px;
background: red;
transform: skewX(-20deg) translateX(-33%);
transform-origin: bottom;
z-index: -1;
}
<div class="one-line">text<br>text<br></div>
<div class="one-line">text<br>text<br>text<br></div>
<div class="one-line">text</div>
<div class="one-line">text<br>text<br>text<br>text<br>text<br>text<br>text<br></div>
Another way with only one pseudo element and linear-gradient.
.one-line {
font-size: 2em;
width: 150px;
min-height: 50px;
height: auto;
background: blue;
margin: 5px;
position: relative;
color: #fff;
}
.one-line:after {
content: '';
display: block;
position: absolute;
top: 0;
height: 100%;
width: 50px;
right: -50px;
background:
linear-gradient(to bottom left, transparent 49.4%, red 50%) top,
linear-gradient(to top left, transparent 49.4%, red 50%) bottom;
background-size:100% 50.2%;
background-repeat:no-repeat;
}
<div class="one-line">text<br>text<br></div>
<div class="one-line">text<br>text<br>text<br></div>
<div class="one-line">text</div>
<div class="one-line">text<br>text<br>text<br>text<br>text<br>text<br>text<br></div>
And finally without any pseudo element and only background on the main element:
.one-line {
font-size: 2em;
width: 200px;
padding-left:50px;
min-height: 50px;
height: auto;
background:
linear-gradient(blue,blue) left/calc(100% - 50px) 100%,
linear-gradient(to bottom left, transparent 49.4%, red 50%) top right/50px 50.2%,
linear-gradient(to top left, transparent 49.4%, red 50%) bottom right/50px 50.2%;
background-repeat:no-repeat;
margin: 5px;
position: relative;
color: #fff;
}
<div class="one-line">text<br>text<br></div>
<div class="one-line">text<br>text<br>text<br></div>
<div class="one-line">text</div>
<div class="one-line">text<br>text<br>text<br>text<br>text<br>text<br>text<br></div>
Well, you could opt to keep the arrow the same size and align it in the middle by changing top to top: 50%; and adding transform: translateY(-50%);
.one-line{
width: 150px;
min-height: 50px;
height: auto;
background: blue;
margin: 5px;
position: relative;
color: #fff;
}
.one-line:after{
content: '';
display: block;
position: absolute;
left: 100%;
width: 0;
height: 0;
border-top: 25px solid transparent;
border-bottom: 25px solid transparent;
border-left: 25px solid red;
top: 50%;
transform: translateY(-50%);
}
<div class="one-line">text<br>text<br>text<br>text</div>
<div class="one-line">text<br>text<br>text<br>text<br>text<br>text<br>text<br>text<br>text<br>text<br>text</div>
using an svg path as a background-image, you could stretch the background-size property to 100% 100%. Just make sure the svg has preserveAspectRatio="none"
.one-line:after {
background-image: url('data:image/svg+xml;charset=UTF-8,<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" preserveAspectRatio="none" viewBox="0 0 25.1 50" style="enable-background:new 0 0 25.1 50;" xml:space="preserve"><polygon class="st0" points="0,50 0,50 25,25 0,0" fill="#ff0000"/></svg>');
position: absolute;
top: 0;
left:100%;
height: 100%;
width: 25px;
background-size: 100% 100%;
background-repeat:no-repeat;
display: block;
content:'';
}
https://jsfiddle.net/7jm54u6L/

Created a CSS Triangle with 3 different coloured borders, but can it be done with less/ more simple CSS code?

So I've managed to create a CSS Triangle with 3 different coloured borders. It can be seen here: https://codepen.io/nuul/pen/oNbeZey
CSS code:
$bg: #0000e5
$color: ((#00007c, #0000e5), (#0000b0, #0000e5), (#0000ff, #0000e5))
#mixin linear-gradient($direction, $gradients...)
background-image: linear-gradient($direction, $gradients...)
#function colorL($some-color, $num)
#return nth($some-color, $num)
#for $i from 1 through length($color)
.sq-#{$i}
#include linear-gradient(colorL(nth($color, $i), 2) 60%, colorL(nth($color, $i), 1) 75%)
$height: 9px
$width: $height * 3.47
body
background: #3D4849
.blueCore
position: absolute
left: 5px
top: 15px
.sq-wrapper
width: $width
height: $height
font-size: 0
display: inline-block
clip-path: polygon(50% 0%, 0 100%, 100% 100%)
position: absolute
left: 0
top: $height
transform-origin: 50% 0
.sq-1-wrapper
transform: rotate(0deg)
.sq-2-wrapper
transform: rotate(240deg)
.sq-3-wrapper
transform: rotate(-240deg)
.sq
width: 100%
height: 100%
.blueBlock
background-color: #0000e5
border: 3px solid
border-top-color: #0000ff
border-right-color: #00007c
border-bottom-color: #00007c
border-left-color: #0000ff
width: 42px
height: 42px
position: relative
z-index: 10
Though I am happy with the result, I am still wondering if the CSS code for this can be simplified (since there is a lot of CSS code needed for just a triangle). Perhaps with a :before :after? The looks should stay the same
Any thoughts?
ps: You can ignore the square around it, I just want to put it in a div for future usage
Thanks!
In terms of your question, I wouldn't recommend using CSS for this and maybe in this situation, an image or even font-awesome would be more efficient. However, you could possibly tweak something like below. It uses two elements to create this shape.
.outer {
position: relative;
height: 200px;
width: 200px;
background: dimgray;
}
.outer:before {
/*Bottom Border Here*/
content: "";
position: absolute;
height: 10%;
width: 90%;
left: 5%;
top: 88%;
z-index: 10;
background: darkblue;
transform: perspective(100px) rotateX(60deg);
}
.outer:after {
/*Triangle Background*/
content: "";
position: absolute;
width: 0;
left: 10px;
bottom: 10px;
border-top: 0;
border-left: 90px solid transparent;
border-right: 90px solid transparent;
border-bottom: 150px solid blue;
}
.inner {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
}
.inner:before {
content: "";
position: absolute;
height: 10%;
width: 90%;
left: -17%;
top: 50%;
background: lightblue;
/*Left border colour here*/
transform: rotate(121deg) perspective(100px) rotateX(60deg);
}
.inner:after {
content: "";
position: absolute;
height: 10%;
width: 90%;
right: -18%;
top: 50%;
background: rgb(0, 0, 220);
/*right border colour here*/
transform: rotate(-120deg) perspective(100px) rotateX(60deg);
}
/*demo only*/
.outer:hover:before { background: darkred;}
.outer:hover:after { border-bottom-color: red;}
.outer:hover .inner:before { background: tomato;}
.outer:hover .inner:after { background: rgb(220, 0, 0);}
<div class="outer">
<div class="inner"></div>
</div>
one element and responsive solution:
.box {
width: 200px;
display: inline-flex;
background:
conic-gradient(at 50% 20px, red 150deg, #0000 0 210deg, green 0)
blue;
clip-path: polygon(50% 0, 100% 100%, 0 100%);
}
.box::before {
content: "";
padding-top: calc(86.6% - 10px);
width: 100%;
box-sizing: border-box;
border:solid transparent;
border-bottom-color: gold;
border-width: 0 18px 10px 18px;
}
<div class="box"></div>
<div class="box" style="width:150px;"></div>
<div class="box" style="width:50px;"></div>

How to get a partial circle border around an image?

I want to design the following for displaying profile picture. I tried using border-style: dashed, but that's not what I want; I want only three lines (dashes) in the border. How can I accomplish this?
Here's what I tried:
#circle {
border-radius: 100%;
width: 100px;
height: 100px;
border: 5px dashed;
background-color: yellow;
}
<!DOCTYPE html>
<html>
<body>
<div id="circle"></div>
</body>
</html>
The effect I desire:
Here is an idea with multiple background:
#circle {
border-radius: 100%;
width: 100px;
height: 100px;
border: 5px solid transparent; /* Control the thickness*/
background:
url(https://picsum.photos/id/100/200/200) center/cover content-box,
linear-gradient(blue,blue) top /100% 20% border-box,
linear-gradient(blue,blue) bottom left /35% 50% border-box,
linear-gradient(blue,blue) bottom right/35% 50% border-box;
background-repeat:no-repeat;
}
<div id="circle"></div>
If you want space between image and border add an extra layer:
#circle {
border-radius: 100%;
width: 100px;
height: 100px;
border: 5px solid transparent; /*Control the thickness*/
padding:3px; /*control the space*/
background:
url(https://picsum.photos/id/100/200/200) center/cover content-box,
linear-gradient(white,white) padding-box,
linear-gradient(blue,blue) top /100% 20% border-box,
linear-gradient(blue,blue) bottom left /35% 50% border-box,
linear-gradient(blue,blue) bottom right/35% 50% border-box;
background-repeat:no-repeat;
}
<div id="circle"></div>
I tried something like that, not sure if entirely fit your needs..but give it a try, maybe it's a good starting point for you. Play with the numbers from css file and maybe you got exactly what you need.
Codesandbox here: https://codesandbox.io/s/vibrant-glade-uo7bg
.circle {
width: 80px;
height: 80px;
border-radius: 50%;
background-color: gray;
position: relative;
}
#shadow-1 {
position: absolute;
top: -1px;
left: -1px;
width: 85px;
height: 85px;
transform: rotate(-20deg);
border-radius: 50%;
box-shadow: 5px 5px 0 -4px blue;
}
#shadow-2 {
position: absolute;
top: -5px;
left: -2.5px;
transform: rotate(-40deg);
width: 85px;
height: 85px;
border-radius: 50%;
box-shadow: 5px -5px 0 -4px blue;
}
#shadow-3 {
position: absolute;
top: -1px;
left: -4px;
width: 85px;
height: 85px;
transform: rotate(20deg);
border-radius: 50%;
box-shadow: -5px 5px 0 -4px blue;
}
<h1>Hello Circle!</h1>
<div>
<div class="circle">
<div id="shadow-1"></div>
<div id="shadow-2"></div>
<div id="shadow-3"></div>
</div>
</div>

Dynamically aligning pseudo element according to parent height

I am trying to create an arrow label, using css :after
.one-line {
font-size: 2em;
width: 150px;
min-height: 50px;
height: auto;
background: blue;
margin: 5px;
position: relative;
color: #fff;
}
.one-line:after {
content: '';
display: block;
position: absolute;
top: 0;
left: 100%;
width: 0;
height: 0;
border-top: 25px solid transparent;
border-bottom: 25px solid transparent;
border-left: 25px solid red;
}
<div class="one-line">text<br>text<br></div>
I want the after element to take the same height which is of parent, how can I do this by either css or js?
Note: The text inside the label is dynamically populating. [Max length of text: 2 lines]
It might not be possible, as I am thinking, to adjust it any height of parent. Currently I am trying it to adjust for both one and two lines of text.
Here is a solution using clip-path. The idea is to use % values in the polygon to only show the needed shape and it will always work whatever the height is:
.one-line {
font-size: 2em;
width: 150px;
min-height: 50px;
height: auto;
background: blue;
margin: 5px;
position: relative;
color: #fff;
}
.one-line:after {
content: '';
display: block;
position: absolute;
top: 0;
bottom: 0;
width: 25px;
right: -25px;
background: red;
-webkit-clip-path: polygon(100% 50%, 0 0, 0 100%);
clip-path: polygon(100% 50%, 0 0, 0 100%);
}
<div class="one-line">text<br>text<br></div>
<div class="one-line">text<br>text<br>text<br></div>
<div class="one-line">text</div>
<div class="one-line">text<br>text<br>text<br>text<br>text<br>text<br>text<br></div>
Here is another solution that rely on both pseudo elements and some skew transformation to create the arrow. You will notice that this one will keep ratio of the arrow.
.one-line {
font-size: 2em;
width: 150px;
min-height: 50px;
height: auto;
background: blue;
margin: 5px;
position: relative;
color: #fff;
}
.one-line:after {
content: '';
display: block;
position: absolute;
top: 0;
height: 50%;
width: 50%;
right: -25px;
background: red;
transform: skewX(20deg) translateX(-33%);
transform-origin: top;
z-index: -1;
}
.one-line:before {
content: '';
display: block;
position: absolute;
bottom: 0;
height: 50%;
width: 50%;
right: -25px;
background: red;
transform: skewX(-20deg) translateX(-33%);
transform-origin: bottom;
z-index: -1;
}
<div class="one-line">text<br>text<br></div>
<div class="one-line">text<br>text<br>text<br></div>
<div class="one-line">text</div>
<div class="one-line">text<br>text<br>text<br>text<br>text<br>text<br>text<br></div>
Another way with only one pseudo element and linear-gradient.
.one-line {
font-size: 2em;
width: 150px;
min-height: 50px;
height: auto;
background: blue;
margin: 5px;
position: relative;
color: #fff;
}
.one-line:after {
content: '';
display: block;
position: absolute;
top: 0;
height: 100%;
width: 50px;
right: -50px;
background:
linear-gradient(to bottom left, transparent 49.4%, red 50%) top,
linear-gradient(to top left, transparent 49.4%, red 50%) bottom;
background-size:100% 50.2%;
background-repeat:no-repeat;
}
<div class="one-line">text<br>text<br></div>
<div class="one-line">text<br>text<br>text<br></div>
<div class="one-line">text</div>
<div class="one-line">text<br>text<br>text<br>text<br>text<br>text<br>text<br></div>
And finally without any pseudo element and only background on the main element:
.one-line {
font-size: 2em;
width: 200px;
padding-left:50px;
min-height: 50px;
height: auto;
background:
linear-gradient(blue,blue) left/calc(100% - 50px) 100%,
linear-gradient(to bottom left, transparent 49.4%, red 50%) top right/50px 50.2%,
linear-gradient(to top left, transparent 49.4%, red 50%) bottom right/50px 50.2%;
background-repeat:no-repeat;
margin: 5px;
position: relative;
color: #fff;
}
<div class="one-line">text<br>text<br></div>
<div class="one-line">text<br>text<br>text<br></div>
<div class="one-line">text</div>
<div class="one-line">text<br>text<br>text<br>text<br>text<br>text<br>text<br></div>
Well, you could opt to keep the arrow the same size and align it in the middle by changing top to top: 50%; and adding transform: translateY(-50%);
.one-line{
width: 150px;
min-height: 50px;
height: auto;
background: blue;
margin: 5px;
position: relative;
color: #fff;
}
.one-line:after{
content: '';
display: block;
position: absolute;
left: 100%;
width: 0;
height: 0;
border-top: 25px solid transparent;
border-bottom: 25px solid transparent;
border-left: 25px solid red;
top: 50%;
transform: translateY(-50%);
}
<div class="one-line">text<br>text<br>text<br>text</div>
<div class="one-line">text<br>text<br>text<br>text<br>text<br>text<br>text<br>text<br>text<br>text<br>text</div>
using an svg path as a background-image, you could stretch the background-size property to 100% 100%. Just make sure the svg has preserveAspectRatio="none"
.one-line:after {
background-image: url('data:image/svg+xml;charset=UTF-8,<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" preserveAspectRatio="none" viewBox="0 0 25.1 50" style="enable-background:new 0 0 25.1 50;" xml:space="preserve"><polygon class="st0" points="0,50 0,50 25,25 0,0" fill="#ff0000"/></svg>');
position: absolute;
top: 0;
left:100%;
height: 100%;
width: 25px;
background-size: 100% 100%;
background-repeat:no-repeat;
display: block;
content:'';
}
https://jsfiddle.net/7jm54u6L/

Required pentagon shape with right direction CSS and HTML

How do i make this type of pentagone without -webkit-clip-path because its doesn't work most of the browser like Firefox, IE9.
My code: http://codepen.io/anon/pen/MYbKrQ
div {
width: 150px;
height: 150px;
background: #1e90ff;
-webkit-clip-path: polygon(0% 0%, 75% 0%, 100% 50%, 75% 100%, 0% 100%);
clip-path: polygon(0% 0%, 75% 0%, 100% 50%, 75% 100%, 0% 100%);
}
/* Center the demo */
html, body {
height: 100%;
}
body {
display: flex;
justify-content: center;
align-items: center;
}
<div></div>
You could directly use svg.
<svg width="150" height="150">
<path d="M0,0 h125 l25,75 l-25,75 h-125z" fill="#4275FF" />
</svg>
You could make use of svg's clipPath and foreignObject to import the div into svg element and apply inline clipPath for cross-browser support.
Browser Support for this approach
div {
width: 150px;
height: 150px;
background: #4275FF;
}
<svg width="150" height="150">
<defs>
<clipPath id="shape">
<path d="M0,0 h125 l25,75 l-25,75 h-125z" />
</clipPath>
</defs>
<foreignObject clip-path="url(#shape)" width="100%" height="100%">
<div></div>
</foreignObject>
</svg>
Using an image instead of a solid color.
<svg width="150" height="150">
<defs>
<clipPath id="shape">
<path d="M0,0 h125 l25,75 l-25,75 h-125z" />
</clipPath>
</defs>
<image clip-path="url(#shape)" xlink:href="http://www.lorempixel.com/150/150/" width="100%" height="100%" />
</svg>
Alternatively, you could use a triangle on :after :pseudo-element.
div {
position: relative;
width: 125px;
height: 150px;
background: #4275FF;
}
div:after {
content: '';
position: absolute;
width: 0;
height: 0;
border-top: 75px solid transparent;
border-bottom: 75px solid transparent;
border-left: 25px solid #4275FF;
right: -25px;
}
<div></div>
Adding an image instead of a solid color using CSS.
#main-container {
width: 150px;
height: 150px;
overflow: hidden;
}
#container,
#shape {
position: relative;
width: 200px;
height: 195px;
transform: rotate(-20deg) translate(-46px, -40px);
overflow: hidden;
-webkit-backface-visibility: hidden;
}
#shape {
position: relative;
height: 500px;
transform: rotate(40deg) translateY(-50%);
left: -219px;
top: 112px;
}
#shape:after {
position: absolute;
content: '';
width: 150px;
height: 150px;
background: url(http://lorempixel.com/150/150);
transform: rotate(-20deg);
margin: 70px 0 0 52px;
}
<div id="main-container">
<div id="container">
<div id="shape">
</div>
</div>
</div>
UPDATE
You can use currentcolor to hack the background-image.
*{
box-sizing: border-box;
padding: 0;
margin: 0
}
:root{
background: red
}
div{
margin: 20px auto;
background: url(http://i.imgur.com/mI2OFTB.jpg);
background-size: cover;
width: 300px;
height: 200px;
position:relative;
color: red
}
div:before,div:after{
content: "";
position: absolute;
color: currentcolor;
right: 0;
border-left: 100px solid transparent
}
div:before{
border-bottom: 100px solid currentcolor;
bottom: 0
}
div:after{
border-top: 100px solid currentcolor
}
<div></div>
You can use Pseudo-elements - CSS
div{
width: 200px;
height: 200px;
background: green;
position: relative
}
div:before{
content: '';
position: absolute;
top: 0;
left: 100%; /*We put it 100% far from left so that it start at the eage of the right border*/
border-top: 100px solid transparent;
border-bottom: 100px solid transparent;
border-left: 50px solid green; /*set the width of your triangle and border-left beause we want the triangle to point in the right direction */
}
<div><div/>
You can always check the compatibility tables for support of HTML5, CSS3, SVG and other technologies in various browsers on caniuse.com
<div id="pentagon"></div>
<style>
#pentagon {
margin-top:45px;
position: relative;
width: 54px;
border-width: 50px 24px 0px 0px;
border-style: solid;
border-color: red transparent;
}
#pentagon:before {
content: "";
position: absolute;
height: 0;
width: 54px;
top: -85px;
border-width: 0px 24px 35px 0px;
border-style: solid;
border-color: transparent transparent red;
}
</style>
You can use this approach :
Rotate the main element by 45deg. Add overflow: hidden; to it.
Add a pseudo-element and un-transform it. Position it correctly within the main element.
Hover over the image to see how this works :
FIDDLE and snippet:
body {
background: url(http://lorempixel.com/640/480);
}
div {
height: 200px;
width: 200px;
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
transform: rotate(-45deg);
position: relative;
overflow: hidden;
top: 50px;
left: 50px;
}
div:before {
content: "";
position: absolute;
left: 100px;
height: 141px;
width: 212px;
display: block;
background: url(http://i.imgur.com/mI2OFTB.jpg);
background-size: 100%;
transform-origin: 0% 0%;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
transform: rotate(45deg);
}
/*Just for demonstration of working*/
div:hover {
overflow: visible;
background: rgba(25, 50, 75, 0.6);
}
<div></div>
Output :