Adding Background Colour to a website

Hey there,

My site is here:

Right now, as a temp solution, I am just using a border: 20px solid #92B14A;

I’m trying to figure out how to wrap everything in a <div> and give it a margin, then just change the background colour to #92B14A (while keeping the grey colour for the rest).

Does this make any sense? The border method just kind of shrinks the page.


You could wrap everything from #page-wrap down in a #wrapper div, and move the body bg image to that wrapper div. Then change the body styles to just a background color of green, and put a margin on the #wrapper:

body {
    background: #92B14A;
#wrapper {
    background: #E7E9EB url("images/header_bg.jpg") no-repeat center top;
    margin: 20px;

I just wanted to point out that some tutorials may suggest using the bgcolor=“” in your tags, but that is outdated and I recommend not doing so.

For example to make the background colour of your entire website red, it would suggest that you do

<!Doctype HTML>
<html lang="en">
<body bgcolor="#ff0000;">

However using css is the more approbate method.
Remember to style elements or refer to them in css"
/*styling goes here */
/*styling goes here */


/*styling goes here */

Or you can use hybrid of these such as:

/*styling goes here */

The above styles Only tags of the type specified with the class.



would only set the background-colour of the website to red if the body tag had a class of redHome. Such as:
<body class=“redHome”></body>

This works better when there is more than one tag used in the page. In html documents; however, there is only one body tag that is used.

Also something that may help is that
with the background property, one can put and image and colour in that tag so that the latter one can be a fallback for the earlier, as in:
background:#ff000 url(images/red.jpg);

Where as background-color only accepts colours and background-image only excepts a url path to an image.

Hope that helped,
Team 1504 :slight_smile:

Thanks guys

I thought I followed the instructions, but I’m losing my formatting. I added the

#wrapper {
background: #E7E9EB url(“images/header_bg.jpg”) no-repeat center top;
margin: 20px;

And a <div id="wrapper> above #page-wrap and </div> at the very bottom.

Here’s the before/after

Where am I going wrong?

The link you posted aove doesn’t have the wrapper in place, so I can’t check what you’ve done. Without seeing the code, the only thing I notice is this:

Notice that id="wrapper is missing the closing quotes. That would cause it to fail, so if that was what you used, try it again with <div id=“wrapper”>.

Ok code is in place now. thx

At the moment your page-wrap div doesn’t wrap around all of the content, only just the top bit, so see if you can fix that. (There may be a closing div somewhere there shouldn’t be, but I can’t quite tell from Firebug.)

Validating the page might help find the error:

Here’s the code I’m using. Sorry, I’m a total noob at this stuff. Taking a CSS course right now. The site validator has too many errors for me to know where to start :confused:

<body<?php if (is_front_page()) echo(’ id=“home”'); ?>>

<div id=“wrapper”>

&lt;div id="page-wrap"&gt;
	&lt;div id="header"&gt;
		&lt;!-- Start Logo --&gt;
			&lt;a href="&lt;?php bloginfo('url'); ?&gt;"&gt;&lt;img src="&lt;?php bloginfo('stylesheet_directory'); ?&gt;/images/logo.png" alt="Vancouver Mortgage Broker" id="logo" /&gt;&lt;/a&gt;
		&lt;!-- End Logo --&gt;
		&lt;!-- Start Searchbox --&gt;
			&lt;div id="search-form"&gt;
				&lt;form method="get" id="searchform1" action="&lt;?php bloginfo('url'); ?&gt;/"&gt;
					&lt;input type="text" value="&lt;?php _e('search this site...','Minimal'); ?&gt;" name="s" id="searchinput" /&gt;
		&lt;!-- End Searchbox --&gt;
			&lt;div class="clear"&gt;&lt;/div&gt;
			&lt;ul class="superfish nav clearfix"&gt;
				&lt;?php if (get_option('minimal_home_link') == 'on') { ?&gt;
					&lt;li &lt;?php if (is_front_page()) echo('class="current_page_item"') ?&gt;&gt;&lt;a href="&lt;?php bloginfo('url'); ?&gt;"&gt;&lt;?php _e('Home','Minimal'); ?&gt;&lt;/a&gt;&lt;/li&gt;
				&lt;?php }; ?&gt;

				&lt;?php if ($category_menu &lt;&gt; '&lt;li&gt;No categories&lt;/li&gt;') echo($category_menu); ?&gt;

				&lt;?php echo $page_menu; ?&gt;
			&lt;/ul&gt; &lt;!-- end ul.nav --&gt;
								&lt;?php if(!is_home() && !is_front_page()) include(TEMPLATEPATH. '/includes/breadcrumb.php'); ?&gt;		
	&lt;/div&gt; &lt;!-- end #header --&gt;


Ah, right, I should have taken into account that this is a WordPress site, so the bits and pieces are spread across files. Hmm. Well, one thing I could suggest is to find where the closing div for the page-wrap div is and add an extra closing div after it. (It’s not in what you posted below … you might find it in footer.php … but I’m so rusty with WP now that I can’t remember where everthing is. But in your theme folder you should be able to look at the various bits that make up the template. Somewhere there will be a </div> that closes off the page-wrap div, and you need another one there for the #wrpeer div.

Once you find that, we’ll have to tweak the css a little more.

It was in the footer, thanks a lot. Seems like it did the trick.

Great! Glad it was that easy.

One further thing I recommend is to add an extra line to your css. At the moment, on narrow screens (or if you narrow down the browser width) the inner bits blow out of the wrapper. So add the following line in red:

#wrapper {
    background: #E7E9EB url("images/header_bg.jpg") no-repeat center top;
    margin: 20px;
    [COLOR="Red"]min-width: 960px;[/COLOR]