I'm not sure what is specific name for this shape but can I just called it "half Parallelogram" ? I want make this shape purely using CSS/CSS3. Any help? or tutorial?
-
2for the below image, a `div` or `span` with `border-top-right-radius` and `border-bottom-left-radius` check this fiddle http://jsfiddle.net/q0b94u8g/1/ – Praveen Aug 18 '14 at 05:02
-
@Praveen yep the below image using border radius but my question is there a way to make it straight line? like above image. – skycrew Aug 18 '14 at 05:05
-
Yup there is a way check this out http://css-tricks.com/examples/ShapesOfCSS/ – Praveen Aug 18 '14 at 05:07
-
1similar question : http://stackoverflow.com/questions/12030835/div-with-cut-out-edges-border-and-transparent-background/24787904#24787904 – web-tiki Aug 18 '14 at 08:38
6 Answers
You can do it using pseudo-elements like below. The approach is to cut out a triangle shape from the left-bottom and top-right of the box. This method can be used with either a solid color an image inside the shape as long as the body background is a solid color. When the body background is a non-solid color this approach will not work because the border hack needs a solid color background.
The advantage of this method is that it can support cuts of different angles at each side (like in the question where the hypotenuse of the triangular cut on either side are not parallel to each other).
div {
background: red;
width: 200px;
height: 100px;
position: relative;
}
div:before {
position: absolute;
height: 0;
width: 0;
content: ' ';
border: 20px solid white;
border-color: transparent transparent white white;
border-width: 20px 0px 0px 15px;
left: 0;
top: 80px;
}
div:after {
position: absolute;
height: 0;
width: 0;
content: ' ';
border: 20px solid white;
border-color: white white transparent transparent;
left: 170px;
top: 0px;
}
.with-img {
background: url(http://lorempixel.com/100/100);
}
<div></div>
<br>
<div class="with-img"></div>
Sample 2: You can also achieve a similar effect using gradients. Just 1 gradient is enough to produce a cut of similar angle on both sides. If different angles are required then two gradients should be used. However the multiple gradient approach mentioned here will not work when the body background is a non-solid color.
div {
width: 200px;
height: 100px;
position: relative;
}
.with-single-gradient {
background: linear-gradient(45deg, transparent 5%, yellowgreen 5%, yellowgreen 90%, transparent 90.5%);
}
.with-single-gradient.image {
background: linear-gradient(45deg, white 5%, transparent 5%, transparent 90%, white 90.5%), url(http://lorempixel.com/100/100);
}
.with-multiple-gradient.image {
background: linear-gradient(45deg, transparent 0%, transparent 90%, white 90%), linear-gradient(60deg, white 10%, transparent 5%, transparent 100%), url(http://lorempixel.com/100/100);
}
<div class='with-single-gradient'></div>
<br>
<div class='with-single-gradient image'></div>
<br>
<div class='with-multiple-gradient image'></div>
Sample 3: This can also be created using SVG and is the best method yet. All that it requires is just a single path
element which creates the required shape.
<svg viewBox='0 0 100 60' width='200px' height='120px'>
<path d='M0,0 80,0 100,16 100,60 10,60 0,54z' fill='yellowgreen' />
</svg>
Tested on Chrome v24, Firefox v19, Safari v5.1.7 (on Windows) and IE v10. They are older versions but should work in the latest versions also.
Note: IE versions less than 10 do not support gradients as mentioned in this SO thread.
-
1Thanks man! I think I go with the second options :- background: -webkit-linear-gradient(45deg, white 5%, red 5%, red 90%, white 90%); background: -o-linear-gradient(45deg, white 5%, red 5%, red 90%, white 90%); background: -moz-linear-gradient(45deg, white 5%, red 5%, red 90%, white 90%); background: linear-gradient(45deg, white 5%, red 5%, red 90%, white 90%); easier to handle responsive design. – skycrew Aug 18 '14 at 05:21
-
1@skycrew: Yes, I prefer that option too and exactly for the same reason :) – Harry Aug 18 '14 at 05:21
-
-
@skycrew: Border can be added mate but that would always be for the whole box (rectangle). – Harry Aug 18 '14 at 07:23
-
let say I want a top border (including top right) and bottom border (including bottom left) so I need to use the first option? – skycrew Aug 18 '14 at 07:25
-
Yes, if you want borders then using pseudo elements would be the better option. – Harry Aug 18 '14 at 07:28
-
Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/59490/discussion-between-skycrew-and-harry). – skycrew Aug 18 '14 at 08:00
there's no thing as straight radius, but here you have some tutorials. For weird shapes, you need to use a combination of shape and negative space, basically using figures with the same color of the background . The good news is you could use "transparent" as color, so you can "fake" this figures in an easy way. See tutorials Shapes of CSS or yuo can use a generator like CSS Shape Generator or CSS Shape Generator 2 but they will highly depend on your needs. Personally, I'd use a BG image and be a happy camper

- 7,690
- 6
- 39
- 54
to make this shape you have to use pseudo class. and i hope it will help you
div { display: inline-block; margin: 20px; float: left; }
shape {
width: 208px; height: 130px; background: red; position: relative; }
shape:before {
content: ""; position: absolute; top: 0; left: 0; border-bottom: 29px solid red; border-right: 29px solid #fff; width: 179px; height: 0; }
shape:after {
content: ""; position: absolute; bottom: 0; left: 0; border-top: 29px solid red; border-left: 29px solid #fff; width: 42px; height: 0; }

- 1
- 1

- 7,074
- 5
- 38
- 53
2 gradients and background-size can be used too :
div {
width: 1440px;
height: 590px;
background:
linear-gradient(45deg, transparent 80px, #FF0000 80px) left no-repeat,
linear-gradient(-135deg, transparent 160px, #FF0000 160px) top right no-repeat;
background-size: 50% 100%;
}
<div>
</div>
1 gradients and calc()
can be used too :
div {
width: 1440px;
height: 590px;
background:
linear-gradient(45deg, transparent 80px, #FF0000 80px, #FF0000 calc( 100% - 160px), transparent calc( 100% - 160px) );
}
<div>
</div>
Related to duplicate question https://stackoverflow.com/questions/36932294/how-can-i-create-the-object-in-picture-below-using-css-border-radius :
div {
width:980px;
height:460px;
background:linear-gradient(140deg,transparent 200px, #FFCB05 200px) left no-repeat,
linear-gradient(-40deg,transparent 80px, #FFCB05 80px) top right no-repeat;
background-size:50% 100% ;
}
<div>
div shape
</div>
image
<img src="https://i.stack.imgur.com/M48zP.png" />

- 1
- 1

- 101,410
- 14
- 105
- 129
For the second shape use this:
border-bottom-left-radius:50px;
border-top-right-radius:50px;
Edit: Question is edited and second shape has been removed.

- 4,833
- 2
- 24
- 34
You can add an element with
overflow: hidden;
skew
transform the parent by desired angle. Unskew thepseudoelement
by the negative of that angle.
Using this approach, you can also add images to background.
div {
height: 100px;
width: 220px;
overflow: hidden;
position: relative;
-webkit-transform: skewX(45deg);
-moz-transform: skewX(45deg);
transform: skewX(45deg);
}
div:before {
content: '';
position: absolute;
left: 10px;
height: 100px;
width: 200px;
background: red;
-webkit-transform: skewX(-45deg);
-moz-transform: skewX(-45deg);
transform: skewX(-45deg);
}
<div></div>

- 5,379
- 27
- 44