Question

I created a cross shape with css. Now I'd like to put a picture in it, the problem is that, the cross contains before: and after: div so its not possible to put a picture in it.

Here is my jsbin: http://jsbin.com/iYogaCE/1/edit

How could I manage that? Or is there another solution to create a shape like that?

Thanks in advance!

Was it helpful?

Solution

Add background-position:center; in #cross:before, #cross:after

#cross {
   width: 100px;
   height: 100px;
   position: relative;
}

#cross:before, #cross:after {
  content: "";
  position: absolute;
  z-index: -1;
  background-size:100px 100px;
  background-image:url('http://www.gm-consult.de/uploads/pics/homer-simpson_20.jpg');
  background-position:center;
}

#cross:before {
  left: 50%;
  width: 30%;
  margin-left: -15%;
  height: 100%;
  -webkit-transform: rotate(45deg); 
  -moz-transform: rotate(45deg);
}

#cross:after {
  top: 50%;
  height: 30%;
  margin-top: -15%;
  width: 100%;
  -webkit-transform: rotate(45deg); 
  -moz-transform: rotate(45deg);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top