Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a responsive image using pseudo-elements

I try to add a box shadow and a gradient border using images and css pseudo-elements.

I tried that code:

.box:before {
    content: url('box-shadow.png');
    position: absolute;
    width: auto;
    height: auto;
    max-width: 100%;
    z-index: -1;
    bottom: -9px;
    line-height: 0;
}
.box:after {
    content: url('box-border.png');
    position: absolute;
    width: auto;
    height: auto;
    max-width: 100%;
    bottom: -5px;
    right: 0px;
}

But the added images don't resize when the parent div resizes, whereas it works by adding the image manually.

See that fiddle http://jsfiddle.net/5TG3E/2/

like image 728
Laurent Avatar asked Feb 21 '23 15:02

Laurent


1 Answers

I try from my side may be that's help you. Write like this:

.box:after {
    content:'';
    position: absolute;
    z-index: -1;
    bottom: -9px;
    margin: 0 auto;
    top:0;
    left:0;
    right:0;
    background:url('http://dl.dropbox.com/u/4812171/box-shadow.png') no-repeat bottom center;
    -moz-background-size:100% 9px;
    background-size:100% 9px;
}
.box:before {
    content:'';
    position: absolute;
    bottom: 0px;
    right: 0px;
    left:0;
    top:0;
    background:url('http://dl.dropbox.com/u/4812171/box-border.png') no-repeat bottom right;
}

Check this http://jsfiddle.net/5TG3E/6/

like image 135
sandeep Avatar answered Feb 28 '23 15:02

sandeep