8.1. CSS and the <img> TagThe venerable <img> tag has been the workhorse of photo-heavy Web sites since the beginning of the World Wide Web. Even sites without photos use it to add logos, navigation buttons , and illustrations. While CSS doesn't have any properties specifically aimed at formatting images, you can take advantage of the CSS properties you've already learned to enhance your site's graphics. For example, the border property's a quick and simple way to frame an image or unify the look of a gallery of photos. Here's a rundown of the CSS properties most commonly used with images:
In most cases, you won't create a style for the < img> tag itself. Formatting this tag's too broad a brush, since it formats all images on your pageeven those with very different functions such as the logo, navigation buttons, photos, and even graphic ads. You wouldn't, after all, want the same black frame around all of those images. Instead, you should use a class style, such as .galleryImage , or .logo to apply the style selectively. Another approach is to use a descendent selector (Section 3.1) to target images grouped together in one section of a page. If you have a gallery of photos, you can place all of the photos inside a <div> tag with an ID name of gallery , and then create a style for just the images inside that <div>, like this: #gallery img . |