You can control the size of an image using the width and height properties in CSS, just like you can for any other box. Specifying image sizes helps pages to load more smoothly because the HTML and CSS code will often load before the images, and telling the browser how much space to leave for an image allows it to render the rest of the page without waiting for the image to download.
Rather than using the
element’s align attribute, web
page authors are increasingly
using the float property to align
images. There are two ways that
this is commonly achieved:
By default, images are inline elements. This means that they flow within the surrounding text. In order to center an image, it should be turned into a blocklevel element using the display property with a value of block. Once it has been made into a block-level element, there are two common ways in which you can horizontally center an image:
img.align-center {
display: block;
margin: 0px auto;}
img.medium {
width: 250px;
height: 250px;}
The background-image property allows you to place an image behind any HTML element. This could be the entire page or just part of the page. By default, a background image will repeat to fill the entire box.
The background-repeat property can have four values:
repeat The background image is repeated both horizontally and vertically (the default way it is shown if the backgroundrepeat property isn’t used).
Using CSS, it is possible to create a link or button that changes to a second style when a user moves their mouse over it (known as a rollover) and a third style when they click on it.
This is achieved by setting a background image for the link or button that has three different styles of the same button (but only allows enough space to show one of them at a time).