-1

I have images coded like this in order to get the padding/shadow styling:

 <div class="slick-shadow"><img src="/images/image.jpg" alt="image"></div>

I tried applying the class slick-shadow directly to the images but the shadow part wasn't showing up, just the padding. Is there a way I could change the CSS to work directly on the image and achieve the same visual look?

Here is the CSS:

.slick-shadow {
    position: relative;
    background: #fff;
    padding:5px;
}
.slick-shadow:before, 
.slick-shadow:after {
    z-index: -1; 
    position: absolute; 
    content: "";
    bottom: 15px;
    left: 10px;
    width: 44%; 
    top: 80%;
    max-width:300px;
    background: rgba(0, 0, 0, 0.5); 
    -webkit-box-shadow: 0 16px 10px rgba(0,0,0, 0.4);   
    -moz-box-shadow: 0 16px 10px rgba(0, 0, 0, 0.4);
    box-shadow: 0 16px 10px rgba(0, 0, 0, 0.4);
    -webkit-transform: rotate(-3deg);    
    -moz-transform: rotate(-3deg);   
    -o-transform: rotate(-3deg);
    -ms-transform: rotate(-3deg);
    transform: rotate(-3deg);
} 
.slick-shadow:after {
    -webkit-transform: rotate(3deg);
    -moz-transform: rotate(3deg);
    -o-transform: rotate(3deg);
    -ms-transform: rotate(3deg);
    transform: rotate(3deg);
    right: 10px;
    left: auto;
}
David Starkey
  • 1,840
  • 3
  • 32
  • 48
jeffusu
  • 135
  • 2
  • 2
  • 7

1 Answers1

0

If you're just looking to avoid going through and wrapping all your images in divs manually you could do something like this:

Working Example

$(function() {
    $('img').wrap('<div class="slick-shadow" />');
});

Most browsers do not support using :after or :before on img tags.
See: https://stackoverflow.com/a/5843078/1947286 For more info.

Community
  • 1
  • 1
apaul
  • 16,092
  • 8
  • 47
  • 82