Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a background image be larger than the div itself?

I have a footer div with 100% width. It's about 50px high, depending on its content.

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

The image is about 800x600px, and I want it to be positioned in the left bottom corner of the footer. It should work sort of like a background image for my website, but I've already set a background image on my body. I need another image positioned at the bottom left corner of my website and the #footer div would be perfect for that.

#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 doesn't overflow the div. Is it possible to make that happen?

overflow:visible doesn't do the job!

like image 526
matt Avatar asked Nov 25 '10 21:11

matt


People also ask

Can you put a background image in a div?

Say you want to put an image or two on a webpage. One way is to use the background-image CSS property. This property applies one or more background images to an element, like a <div> , as the documentation explains.

What scale the background image as large as possible?

Correct Option: B. The contain keyword scales the background image to be as large as possible but both its width and its height must fit inside the content area.

How do I stretch a background image in CSS to fit the screen?

When you work with background images, you may want an image to stretch to fit the page despite the wide range of devices and screen sizes. The best way to stretch an image to fit the background of an element is to use the CSS3 property, for background-size, and set it equal to cover.


3 Answers

There is a very easy trick. Set padding of that div to a positive number and margin to negative

#wrapper {
    background: url(xxx.jpeg);
    padding-left: 10px;
    margin-left: -10px;
}
like image 155
transGLUKator Avatar answered Sep 28 '22 01:09

transGLUKator


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

like image 23
Daniel Bingham Avatar answered Sep 28 '22 00:09

Daniel Bingham


You can use a css3 psuedo element (:before and/or :after) as shown in this article

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

Good Luck...

like image 25
Josh Sells Avatar answered Sep 28 '22 00:09

Josh Sells