How to set form in div

I would like to set the form tag div. Everything works fine, but when I set the tag imginside this form, it does not display well.

My CSS code is:

#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 form ( chevron) as a background, and the inner elements should be above it.

http://jsfiddle.net/45tyb219/2/

+1
source share
2 answers

Simply add position: relative;and z-index: 1;your .img- alternatively you can also add z-index: -1;in #chevron:after.

#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); }

img {
    position: relative;
    z-index: 1;
}
<div id="chevron">
  <img  src="http://i.stack.imgur.com/HtYUn.jpg" style="margin-left: 100px;width:120px;height:120px"/>
</div>
Run codeHide result
+3
source

You can achieve this with CSS, but SVG simplifies it:

svg{width:50%;display:block;margin:0 auto;}
<svg viewbox="0 0 100 50">
  <defs>
    <pattern id="img" patternUnits="userSpaceOnUse" width="100" height="50">
      <image xlink:href="http://i.imgur.com/5NK0H1e.jpg" x="0" y="0" height="50" width="100" />
    </pattern>
  </defs>
  <path fill="url(#img)" d="M5 0 H95 Q100 0 100 5 V45 L50 50 L0 45 V5 Q0 0 5 0z" />
</svg>
Run codeHide result

<pattern> , <path />.

+3

All Articles