DIV background-image overflow

大兔子大兔子 提交于 2019-12-22 08:11:02

问题


I have a DIV element with a background-image, and I want it to overflow outside the dimensions of the DIV (it now cuts off the image because the image is bigger than the DIV).

Is this possible? overflow:visible doesn't work!


回答1:


You can do it in alternative way:

#box {
    margin:-50px 0 0;
    padding:50px 0 0 0;
    background:url(/images/image.png) no-repeat;
}



回答2:


Put the background on a larger <div> that contains your <div>.




回答3:


It is very possible with CSS3. I stumbled on this post while attempting this myself and discovered I could do it.

Here's the code I used:

    #page
{
    width:1024px;
    height:662px;
    padding:0 58px 105px 58px;
    background-image:url(../images/milk_splash.png), url(../images/content_back.png);
    background-size: 1082px 767px, 1024px 662px;
    background-origin:padding-box, content-box;
    background-repeat:no-repeat, no-repeat;
    background-position:top left, top left;
}

Your images will layer down in the order you put them in. Your padding is the offset difference in size from your div.

I discovered this and just had to share it. Will not work in IE <9.



来源:https://stackoverflow.com/questions/5530141/div-background-image-overflow

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