3D effect with image as a background of another image

懵懂的女人 提交于 2019-12-13 02:14:05

问题


I'm trying to add a 3D effect to an image, the final result should look like the following: (illustrated in Photoshop)

I've tried playing with the css3 property box-shadow but it doesn't provide a real 3D effect, as you can see in the following image: (I know I can set blur to 0 and change sides, but as you can see - there's a difference in the corners between what I'm trying to achieve to the box-shadow result)

After not finding a only-CSS solution - I've created the following image and set it as a background of the image itself.

JSFIDDLE * Please notice - I'm using the bootstrap framework.

HTML

<img src="" class="img-responsive framed">

CSS

.framed{
background-image: url('URL-OF-THE-FRAME');
padding-left: 5px; //The thickness of the "line"
padding-bottom: 5px; //The thickness of the "line"
background-size: cover;
}

.img-responsive{
display: block;
max-width: 100%;
height: auto;
}

Which gives the result I was looking for - but, if you re-size the window (try enlarging the result's window in the jsfiddle) a distance between the image and the frame is being created.

Should I try another tactic or am I missing here something?


回答1:


You need to use percent padding so it addapts to the size of the image/container when window is resized.

DEMO

CSS :

.framed{
    background-image: url('http://www.6pix.co/images/shadow-3.png');  
    padding-left: 2.9%;  
    padding-bottom: 2.9%;  
    background-size: cover;  
}


来源:https://stackoverflow.com/questions/24060222/3d-effect-with-image-as-a-background-of-another-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!