Can a background image be larger than the div itself?

I have a footer with 100% width. This is approximately 50 pixels depending on its content.

Is it possible to give this #footer a background image that overflows this div?

The image is about 800x600px, and I want it to be located in the lower left corner of the footer. It should look like a background image for my site, but I already set the background image on my body. I need another image located in the lower left corner of my site, and the #footer div is perfect for this.

#footer { clear: both; width: 100%; margin: 0; padding: 30px 0 0; background:#eee url(images/bodybgbottomleft.png) no-repeat left bottom fixed; } 

The image is set to the footer, however it does not overflow the div. Is it possible to do this?

overflow:visible does not do the job!

+53
css image background
Nov 25 '10 at 21:13
source share
8 answers

I do not believe that you can make the background image overflow with your div. Images placed in image tags can overflow their parent div, but background images are limited to the div for which they are the background.

+35
Nov 25 '10 at 21:16
source share

There is a very simple trick. Set the registration of this div to a positive number and the margin to negativ

 #wrapper { background: url(xxx.jpeg); padding-left: 10px; margin-left: -10px; } 
+111
Jul 19 '13 at 22:18
source share

You can use the css3 psuedo element as shown in this article

https://www.exratione.com/2011/09/how-to-overflow-a-background-image-using-css3/

+10
Aug 08 '13 at 4:09 on
source share

No, you can’t.

But as a lasting solution, I would suggest classifying this first div as position:relative and using div::before to create the base element containing your image. It is classified as position:absolute , you can move it anywhere relative to your starting div.

Remember to add content to this new element. Here is an example:

 div { position: relative; } div::before { content: ""; /* empty but necessary */ position: absolute; background: ... } 

Note. If you want it to be β€œon top” of the parent div, use div::after instead.

+7
Apr 26 '15 at 18:48
source share

You already mention the background image on the body .

You can set this background image to html and the new one to body . This, of course, will depend on your layout, but you will not need to use its footer.

+4
Nov 25 '10 at 10:50
source share

Not really - the background image is limited to the element to which it is applied, and overflow properties apply only to the content (for example, markup) inside the element.

You can add another div to the footer div and apply a background image to it, but instead an overflow.

+2
Nov 25 2018-10-21
source share

It might help . This requires that the height of the footer be a fixed number. Basically, you have a div inside the footer with its normal content, position: absolute , and then an image with position: relative , a negative z-index , so it stays β€œbelow” everything and a negative value of top footer height minus image height ( in my example, 50px - 600px = -550px ). Tested on Chrome 8, FireFox 3.6, and IE 9.

+2
Nov 25 2018-10-21T00:
source share

Using a background cover for me worked.

 #footer { background-color: #eee; background-image: url(images/bodybgbottomleft.png); background-repeat: no-repeat; background-size: cover; clear: both; width: 100%; margin: 0; padding: 30px 0 0; } 

Obviously, you need to know about support issues, check if I can use: http://caniuse.com/#search=background-size

+2
May 19 '15 at 10:25
source share



All Articles