I want to make the following design:
I tried with :after
and :before
but it does not work. Here’s my current code:
.design {
background: #ea053a;
display: inline-block;
height: 155px;
margin-left: 33px;
margin-right: 40px;
position: relative;
width: 228px;
}
.design:before {
border-top: 43px solid #ea053a;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
margin-right: 40px;
content: "";
height: 0;
left: 0;
position: absolute;
top: 55px;
margin-top: 100px;
width: 128px;
}
<div class="design"></div>
(fiddle)
How could I leave it the same as the original design and with the following two properties?:
box-shadow: 0 1px 10px 0 rgba(0, 0, 0, 0.2);
background-image: linear-gradient(to bottom, #ea053a, #d0021b);
Here is my solution to add shadow and gradient to the shape
You can use clip-path as I did. Here is my solution.
Here is an idea with skew transformation and
drop-shadow
filter. You simply need some extra element to correctly have the gradient. The trick is to invert the skew to keep the gradient direction correct (not needed if we deal with solid color)Here is how we can do with a left or right gradient. In this case we don't need extra elements because the skew will not affect the direction:
And here is with an arbitrary gradient:
Since each element is taking
50%
of the width we make the background to be200%
to have its size as the main container then we adjust the position to create the illusion of one background. It's like each element will show half of the main background.An optimized version using
mask
Or
clip-path
Change to (only changed lines listed, keep everything else as-is):
If you change your CSS to the following minor changes, then you can achieve the result that you have expected:
Here is the working of the above CSS:
Hope this was helpful.
My Fiddle