| You are here: | About>Computing & Technology>Web Design / HTML> CSS> CSS3> How Do you Stretch a Background Image in a Web Page |
![]() | Web Design / HTML |
HTML References / Web Design ReferencesCSS 1 and CSS 2 PropertiesHTML 4.01 Tags / XHTML 1.0 ElementsHTML Codes HTML Tutorials / Web Design Tutorials / CSS TutorialsHTML 4.01 Tutorial / XHTML 1.0 TutorialCSS 1 and CSS 2 TutorialXML Tutorial Q. How Do you Stretch a Background Image in a Web PageI got the following question from Neo: I am trying since months but I can't find a way to stretch background images in a web page.... What is the reason that it seems impossible to do? How to do it? A. The best way to do this is to use the CSS 3 property, background-size: body { Unfortunately, no browsers support this property at this time. As you can see from this example of the background-size property. Faking a Stretched BackgroundUntil CSS 3 is accepted as a recommendation and user-agents catch up, in order to get a background image to stretch, we have to fake it. The easiest way to fake a stretched background image is to stretch it across the entire page. Then you don't end up with extra space or have to worry that your text fits in the stretched area. Here's how to do it:
Faking a Stretched Background Image Over a Smaller SpaceYou can use a similar technique to fake a stretched background image across a div or other element on your Web page. This is a bit trickier as you have to either use absolute positioning or have strange spacing issues for other parts of your page.
Be sure to test this in as many browsers as you can. And if your content changes size, you'll need to change the size of your container and background image, otherwise you'll end up with strange results. HTML References / Web Design ReferencesCSS 1 and CSS 2 PropertiesHTML 4.01 Tags / XHTML 1.0 ElementsHTML Codes HTML Tutorials / Web Design Tutorials / CSS TutorialsHTML 4.01 Tutorial / XHTML 1.0 TutorialCSS 1 and CSS 2 TutorialXML Tutorial |
Las Vegas on a BudgetFind a BargainHotel DealsCheap EatsFree AttractionsEntertainment for Less |
All Topics | Email Article | | | ![]() |
| Advertising Info | News & Events | Work at About | SiteMap | Reprints | Help | Our Story | Be a Guide |
| User Agreement | Ethics Policy | Patent Info. | Privacy Policy | ©2008 About, Inc., A part of The New York Times Company. All rights reserved. |


