How to subtract background from an image?

How to add background image to css?

  • Yea, i need to figure out a way to add a background image to my css but the code from w3schools isn't working: (Which is, background-image:url (link); ) I'll post my code, YES, i am very new to programming, but please tell me where or why this code isn't working when i provide a direct link, thanks! Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml… <html> <head> <style> body { margin:0; padding:0; color:#000; background:#a7a09a; #wrap { width:750px; margin:0 auto; background:#99c; } #header { padding:5px 10px; background:#ddd; } #nav { padding:5px 10px; background:#c99;} #main { float:left; width:480px; padding:10px; background:#9c9; } #sidebar { float:right; width:230px; padding:10px; background:#99c; } #footer { clear:both; padding:5px 10px; background:#cc9; } #nav ul { margin:0; padding:0; list-style:none; } #nav li { display:inline; margin:0; padding:0; } h1 { margin:0; } h2 { margin:0 0 1em; } #footer p { margin:0; } * html #footer { height:1px; } </style> <body> <div id="wrap"> <div id="header"><h1>Document Heading</h1></div> <div id="nav"> <ul> <li><a href="#">Option 1</a></li> <li><a href="#">Option 2</a></li> ... </ul> </div> <div id="main"> <h2>Column 1</h2> <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit...</p> </div> <div id="sidebar"> <h2>Column 2</h2> <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit...</p> <ul> <li><a href="#">Link 1</a></li> <li><a href="#">Link 2</a></li> ... </ul> </div> <div id="footer"> <p>Footer</p> </div> </div> </body>

  • Answer:

    Background Image Code: For the body tag example: body { width: XXXpx; height: YYYpx; /* optional */ margin: 0 auto; /* centers page */ background: #fff url(image_name.jpg) no-repeat center scroll; } That is the proper CSS code for a non-tiled image where the contents scroll with the background image. Change "#fff" to preferred bg color. Change "scroll" to "fixed" if you want page contents to scroll over bg image. Be sure to set proper width/height to provide minimum page size to display bg image. Put the CSS on an external CSS file. If using embedded CSS, then place CSS between the style tags and place those style tags between the head tags of the page. For a tiled image, change to: body { width: XXpx; height: YYpx; margin: 0 auto; background: #fff url(image_name.jpg) repeat top left scroll; } Put that CSS on an external CSS file if you have more than one page. Put the CSS between the style tags and place them between the head tags if using it on one page. Style another tag other than the body tag if you are using a div wrap container. Should you want the contents of page to scroll over the background image, change "scroll" to "fixed". Inline CSS example: <body style="width: 960px; margin: 0 auto; background: url(image.gif) no-repeat center fixed;"> Inline CSS example: <body style="width: 960px; margin: 0 auto; background: url(image.jpg) no-repeat center scroll;"> Ron

Yoo Mayne at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

Background images are a little funny with css sometimes try either of these: background: url(PATH); background: url('PATH'); /*Notice the single quotes*/ background-image: url(PATH); background-image: url('PATH'); /*Notice the single quotes*/ I personally use the first example and it has yet to lead me astray.

Kira

small mistake bro: background-image:url (link); should be background-image:url ('link'); the path needs to be in single quotes.

Matt

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.