10.07.2015 Views

Building the User Interface by Using HTML5: Text, Graphics ... - server

Building the User Interface by Using HTML5: Text, Graphics ... - server

Building the User Interface by Using HTML5: Text, Graphics ... - server

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Building</strong> <strong>the</strong> <strong>User</strong> <strong>Interface</strong> <strong>by</strong> <strong>Using</strong> <strong>HTML5</strong>: <strong>Text</strong>, <strong>Graphics</strong>, and Media | 35You can display different kinds of images on a Web page, most of which fall into two main categories:raster (or bitmap) and vector. A raster image is made up of pixels, whereas a vector imageis made up of lines and curves based on ma<strong>the</strong>matical expressions. A photograph is a type of rasterimage and is most often in JPG format. O<strong>the</strong>r raster file formats that work well on Web pagesare PNG, GIF, and BMP. A vector image is an illustration, such as a line drawing. Developersoften convert vector file formats from programs like Adobe Illustrator or CorelDRAW, whicharen’t supported <strong>by</strong> Web browers, into PNG or GIF for Web display. An important differencebetween <strong>the</strong> two types of files is that raster images lose quality (<strong>the</strong>y become pixelated) as youenlarge <strong>the</strong>m, but vector images maintain quality even when enlarged.The primary way to add images to an HTML document is with <strong>the</strong> img element. Like <strong>the</strong>anchor tag, <strong>the</strong> img tag does nothing <strong>by</strong> itself and requires attributes and values that specify<strong>the</strong> image <strong>the</strong> Web browser should display.For example, to insert an image named redball.jpg that’s in a subfolder called images, typethis element:LICENSED PRODUCT NOT FOR RESALECERTIFICATION READYWhat markup do you useto display an externalimage on a Web page?2.2The image will display as long as <strong>the</strong> images subfolder is accessible. Both <strong>the</strong> src attributeand <strong>the</strong> alt attribute are required to be fully valid. The value of <strong>the</strong> alt attribute (short foralternate text) displays when a user hovers <strong>the</strong> mouse pointer over <strong>the</strong> image; in this case, <strong>the</strong>phrase “Red ball graphic” would display. The W3C requires <strong>the</strong> alt attribute for accessibility<strong>by</strong> people with disabilities. People with limited vision may use a screen reader, which readsaloud <strong>the</strong> alternate text for each image. Search engines also use <strong>the</strong> alt attribute to identifytypes of images and what’s in <strong>the</strong>m, since search engines can’t “see” pixels in images.As ano<strong>the</strong>r example, to insert an image named bluelogo.png that’s accessible from ano<strong>the</strong>rWeb site, type <strong>the</strong> following element:The img element uses several attributes, which are described in Table 2-3.Table 2-3img element attributes ATTRIBUTE VALUE DESCRIPTIONsrc URL Specifies <strong>the</strong> image’s location, such as a path or URLalt <strong>Text</strong> Specifies alternate text for <strong>the</strong> image, which displays when<strong>the</strong> user hovers <strong>the</strong> mouse pointer or o<strong>the</strong>r pointing deviceover <strong>the</strong> imageheight pixels Specifies <strong>the</strong> height of an imagewidth pixels Specifies <strong>the</strong> width of an imageismap ismap Specifies an image as a <strong>server</strong>-side image mapusemap #mapname Specifies an image as a client-side image map (which is apicture with defined areas that are clickable links)<strong>Using</strong> <strong>the</strong> figure and figcaption ElementsTwo new graphics-related elements introduced in <strong>HTML5</strong> are <strong>the</strong> figure andfigcaption elements. The figure element specifies <strong>the</strong> type of figure you wantto use in an HTML document, such as an illustration or photo. The figcaptionelement provides a caption for <strong>the</strong> figure.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!