DIV background-image overflow

2019-05-12 17: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!

3条回答
唯我独甜
2楼-- · 2019-05-12 17:19

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.

查看更多
劳资没心,怎么记你
3楼-- · 2019-05-12 17:25

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

查看更多
Anthone
4楼-- · 2019-05-12 17:33

You can do it in alternative way:

#box {
    margin:-50px 0 0;
    padding:50px 0 0 0;
    background:url(/images/image.png) no-repeat;
}
查看更多
登录 后发表回答