I would like to set a shape to a div
tag. Everything works fine, but when I set an img
tag inside that shape, it does not show well.
My CSS code :
#chevron{
width: 350px;
height: 100px;
background: #337AB7;
border-radius: 10px 10px 0 0;
position: relative;
}
#chevron:before {
content: '';
position: absolute;
top: 20px;
left: 0;
height: 100%;
width: 51%;
background: #337AB7;
-webkit-transform: skew(0deg, 6deg); -moz-transform: skew(0deg, 6deg);
-ms-transform: skew(0deg, 6deg);
-o-transform: skew(0deg, 6deg);
transform: skew(0deg, 6deg); }
#chevron:after {
content: '';
position: absolute;
top: 20px;
right: 0;
height: 100%;
width: 50%;
background: #337AB7;
-webkit-transform: skew(0deg, -6deg); -moz-transform: skew(0deg, -6deg); -ms-transform: skew(0deg, -6deg); -o-transform: skew(0deg, -6deg); transform: skew(0deg, -6deg); }
My html file :
<div id="chevron">
<img src="http://i.stack.imgur.com/HtYUn.jpg" style="width:120px;height:120px"/>
</div>
I want to set my shape (chevron
) as a background and the inner elements should be over it.
Just add
position: relative;
andz-index: 1;
to your.img
- alternatively you can also addz-index: -1;
to the#chevron:after
.You can achieve this with CSS but SVG makes it much easier :
In this demo, the image is set in the
<pattern>
element and used to fill the shape defined with the<path />
element.