css3 - Is it possible to cut out a triangle section from a div using CSS? -
is possible cut triangle <div>
in picture below?
the background not colour, in case blurred picture, can’t cover green <div>
brown triangle image. there other css way achieve effect? thanks.
the illusion of possible: http://jsfiddle.net/2hcrw/4/
tested with: ie 9, 10, firefox, chrome, safari on pc , ipad.
::before
,::after
pseudo elements skewed provide side of triangle each.- wrapper used clipping skewed pseudo elements. may able avoid using outer container wrapper.
- elements can still styled borders, shadows, etc.
- anything underneath show through properly.
demo borders , drop shadow: http://jsfiddle.net/2hcrw/8/
this demo adds tweak ipad retina prevent gap between element , pseudo elements (either caused drop shadow bleed or sub-pixel rendering behavior).
<div id="wrapper"> <div id="test">test</div> </div> #wrapper { overflow: hidden; height: 116px; } #test { height: 100px; background-color: #ccc; position: relative; } #test::before { content:""; position: absolute; left: -8px; width: 50%; height: 16px; top: 100px; background-color: #ccc; -webkit-transform: skew(-40deg); -moz-transform: skew(-40deg); -o-transform: skew(-40deg); -ms-transform: skew(-40deg); transform: skew(-40deg); } #test::after { content:""; position: absolute; right: -8px; width: 50%; height: 16px; top: 100px; background-color: #ccc; -webkit-transform: skew(40deg); -moz-transform: skew(40deg); -o-transform: skew(40deg); -ms-transform: skew(40deg); transform: skew(40deg); }
as alternative, can use transparent image , "extend" element above pseudo elements. have answered similar question regarding circle cut element , show support options down ie7 (as future options true clipping/masking in css).
Comments
Post a Comment