CSS Background Images
Here's an issue that comes up frequently. CSS best practices dictate that inline images (those applied with the <img> tag) should only be used in cases where the image is relevant to the text of the webpage; otherwise you should use CSS background images. This means an image of a manatee should appear as an inline image on a page about manatee biology, or on a page with news story about a manatee tangled in local fishermen's nets. Depending on the context it could be used on general webpages for a site that is generally dedicated to manatees. However in all other cases, the image does not serve the content, but is merely decorative, and it should be applied as a background image in the CSS.
Further, any images that are on the page template for the site or even one section are much nastier to maintain if you have inline images written into the XHTML of every page. This is another reason why I'm pretty hard on inline images. It's so much easier to tie a CSS background image into a particular element that's in the page template; then it's only defined one time... in the stylesheet. So if you need to make changes to the images, you no longer have to update references on every page of the website; you just fix one reference in the stylesheet. That's why I don't use inline images for the page template unless each page wouldn't make sense without an inline image. Strictly speaking, that's probably too high a bar for semantics; it's certainly not the same criteria I use for custom content in the main content area of the webpage. However, the advantages are so key that I do it for the maintainability anyway.
Therefore, many cases arise where you need to apply an image to the page using CSS background images. In each case, create a div element with an id attribute to display the image. In some cases you may be able apply the CSS to the id of a convenient block element which already exists on your page, and that's preferable. However, if not, simply drop a div element with an id specified, and then create a style rule for that id. Then declare the image in the background property as shown, and specify the height and width of the element in pixels to match the image dimensions.
Customizable CSS
#siteId {
background: url(../Images/Logo4.jpg) top left no-repeat;
height: 150px;
width: 150px;
}
Customizable XHTML
<div id="siteId"></div>
Background Image Rollover Link
Here's a useful adaptation of the CSS background image code. Inserting images into link text has been a common need, and the same effect is easily accomplished with background images. Note that as with any image rollover, you need images of the same dimensions to prevent awkward side effects. In order to create a rollover link, we already have an XHTML element to apply the background image to, the link itself. The default image is applied as a standard background image, and the rollover is applied with a hover pseudo-class.
Customizable CSS
#siteId a {
background: url(../Images/Logo4.jpg) top left no-repeat;
display: block;
height: 150px;
width: 150px;
}
#siteId a:hover {
background: url(../Images/LogoRollover03.jpg) top left no-repeat;
}
Customizable XHTML
<div id="siteId"><a href="PageToLinkTo.aspx">Here is the Text for the link. (if any)</a></div>