<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CSS Tutorial &#187; background image with CSS</title>
	<atom:link href="http://www.csstutorial.net/tag/background-image-with-css/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.csstutorial.net</link>
	<description>CSS Tutorial</description>
	<lastBuildDate>Mon, 30 Jan 2012 06:00:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>How to Add a Background Image with CSS</title>
		<link>http://www.csstutorial.net/2010/03/adding-a-background-image-with-css/</link>
		<comments>http://www.csstutorial.net/2010/03/adding-a-background-image-with-css/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 11:47:16 +0000</pubDate>
		<dc:creator>Andrea Barnett</dc:creator>
				<category><![CDATA[CSS Basics]]></category>
		<category><![CDATA[CSS Misc]]></category>
		<category><![CDATA[CSS Page Layouts]]></category>
		<category><![CDATA[Killer CSS Tips and Tricks]]></category>
		<category><![CDATA[background image with CSS]]></category>

		<guid isPermaLink="false">http://www.csstutorial.net/?p=511</guid>
		<description><![CDATA[Background images, just as the name implies, are part of the BACKGROUND of a website, not part of the actual content.  The most common place to add a background image to, is the entire canvas - aka the body tag.]]></description>
			<content:encoded><![CDATA[<p>Background images, just as the name implies, are part of the BACKGROUND of a website, not part of the actual content.  The most common place to add a background image to, is the entire canvas &#8211; aka the body tag.</p>
<p>The CSS to add an image to a body tag is simple:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">body <span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">bgimage.jpg</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>I&#8217;m just using a random image for demonstration purposes, and <a href='http://www.csstutorial.net/wp-content/uploads/2010/03/background01.html'>THIS</a> this is what we get. And we can note the following:</p>
<ol>
<li>It&#8217;s a very beautiful flower (grew in my house)</li>
<li>It repeats itself and covers the entire background &#8211; that is called &#8217;tiling&#8217; (think bathroom)</li>
<li>It pretty much makes it impossible to read the actual page content</li>
</ol>
<p>There are also special background images that are designed to tile unnoticeable -for example this one:<br />
<a href="http://www.csstutorial.net/wp-content/uploads/2010/03/bgimage01.jpg"><img src="http://www.csstutorial.net/wp-content/uploads/2010/03/bgimage01.jpg" alt="Background Image optimized to tile unnoticeable " title="Tiling Background Image" width="150" height="150" class="aligncenter size-full wp-image-519" /></a> which will create <a href='http://www.csstutorial.net/wp-content/uploads/2010/03/background02.html'>THIS</a>.</p>
<p>CSS also gives us the tools to direct our background image how we want it.  The default, as you can see, is that it repeats itself horizontally AND vertically to fill the entire background, regardless of size.  Sometimes we might want the image appear only horizontally or vertically &#8211; and maybe not directly on the edge of the viewing area. </p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">body <span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">bgimage.jpg</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">repeat-x</span> <span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>creates a background that is <a href='http://www.csstutorial.net/wp-content/uploads/2010/03/background03.html'>repeated vertically at the bottom of the content</a>, and this background image <a href='http://www.csstutorial.net/wp-content/uploads/2010/03/background04.html'>repeated horizontally on the right</a> is created by this CSS:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">body <span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">bgimage.jpg</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">repeat-y</span> <span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>There are many more ways for us to control our background.  In addition to the above, we could:</p>
<ul>
<li>Add a background color (background: url(image.jpg) #555555;)</li>
<li>Display the image only one time (no-repeat)</li>
<li>Position it more specifically (options are: top, bottom, left, right, center, x-15px, or y-20% (measurements and units are optional))</li>
<li>Keep it from scrolling (background: url(image.jpg) fixed;)</li>
<li>Any combination of any of the above</li>
</ul>
<p>A wise combination of all these techniques might actually allow us to create a decorative background that does NOT interfere with the actual content. <a href='http://www.csstutorial.net/wp-content/uploads/2010/03/background05.html'>Like This</a>.  The following CSS created this page &#8211; and please note that I also added some padding to keep the content off the image, which makes things soooo much easier to read:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">body <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">bgimage.jpg</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #cc00cc;">#f6f1b9</span> <span style="color: #993333;">fixed</span> <span style="color: #000000; font-weight: bold;">top</span> <span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding-right</span><span style="color: #00AA00;">:</span> <span style="color: #933;">250px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Background images can be added to pretty much any tag.  They can be added to divisions, used to create fancy navigation menus, spruce up a list, decorate h tags,&#8230;. It&#8217;s so exciting!!!!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.csstutorial.net/2010/03/adding-a-background-image-with-css/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

