Guest User

Untitled

a guest
Sep 26th, 2015
1,872
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 480.13 KB | None | 0 0
  1.  
  2.  
  3. HTML & CSS
  4. Design and Build Websites
  5. Jon Duckett
  6. John Wiley & Sons, Inc.
  7. Published by
  8. John Wiley & Sons, Inc.
  9. 10475 Crosspoint Boulevard
  10. Indianapolis, IN 46256
  11. www.wiley.com
  12. ©2011 by John Wiley & Sons, Inc., Indianapolis, Indiana
  13. ISBN: 978-1-118-00818-8
  14. Manufactured in the United States of America
  15. Published simultaneously in Canada
  16. 10 9 8 7 6 5 4 3 2 1
  17. No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical,
  18. photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act,
  19. without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the
  20. Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for
  21. permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-
  22. 6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions.
  23. Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the
  24. accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation warranties of
  25. fitness for a particular purpose. No warranty may be created or extended by sales or promotional materials. The advice and strategies
  26. contained herein may not be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in
  27. rendering legal, accounting, or other professional services. If professional assistance is required, the services of a competent professional
  28. person should be sought. Neither the publisher nor the author shall be liable for damages arising herefrom. The fact that an organization
  29. or Web site is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the
  30. publisher endorses the information the organization or website may provide or recommendations it may make. Further, readers should be
  31. aware that Internet websites listed in this work may have changed or disappeared between when this work was written and when it is read.
  32. For general information on our other products and services please contact our Customer Care Department within the United States at (877)
  33. 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.
  34. Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books.
  35. Library of Congress Control Number: 2011932082
  36. Trademarks: Wiley and the Wiley logo are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its
  37. affiliates, in the United States and other countries, and may not be used without written permission. All other trademarks are
  38. the property of their respective owners. John Wiley & Sons, Inc. is not associated with any product or vendor mentioned in
  39. this book.
  40. HTML & CSS
  41. Design and build Websites
  42. For John Wiley & Sons, Inc.
  43. Executive Editor
  44. Carol Long
  45. Marketing Manager
  46. Ashley Zurcher
  47. Production Manager
  48. Tim Tate
  49. PRODUCTION EDITOR
  50. Daniel Scribner
  51. Vice President and
  52. Executive Group Publisher
  53. Richard Swadley
  54. Vice President and
  55. Executive Publisher
  56. Barry Pruett
  57. Associate Publisher
  58. Jim Minatel
  59. Production Coordinator,
  60. Cover
  61. Katie Crocker
  62. Author
  63. Jon Duckett
  64. Cover Designer
  65. Emme Stone
  66. Design and Layout
  67. Jon Duckett
  68. Emme Stone
  69. Technical Editor
  70. Chris Mills
  71. TECHNICAL REVIEWERS
  72. Andy Stone
  73. Angela Shimell
  74. Donna Watson
  75. Martin Callanan
  76. Rob Jacoby
  77. Tony Berry
  78. Photography
  79. John Stewardson
  80. johnstewardson.com
  81. Additional Photography
  82. Hesperian
  83. Joe Robertson
  84. flickr.com/photos/mindfire
  85. Jules Clancy
  86. thestonesoup.com
  87. Kylie Gusset
  88. gusset.net
  89. Michael Stillwell
  90. beebo.org
  91. Credits
  92. Try out and download all of the code for this book online at:
  93. http://www.htmlandcssbook.com/code/
  94. Introduction
  95. Chapter 1: Structure
  96. Chapter 2: Text
  97. Chapter 3: Lists
  98. Chapter 4: Links
  99. Chapter 5: Images
  100. Chapter 6: Tables
  101. Chapter 7: Forms
  102. Chapter 8: Extra Markup
  103. Chapter 9: Flash, Video & Audio
  104. Chapter 10: Introducing CSS
  105. Chapter 11: Color
  106. Chapter 12: Text
  107. Chapter 13: Boxes
  108. Chapter 14: Lists, Tables & Forms
  109. Chapter 15: Layout
  110. Chapter 16: Images
  111. Chapter 17: HTML5 Layout
  112. Chapter 18: Process & Design
  113. Chapter 19: Practical Information
  114. Index
  115. Contents
  116. 2
  117. 12
  118. 40
  119. 62
  120. 74
  121. 94
  122. 126
  123. 144
  124. 176
  125. 200
  126. 226
  127. 246
  128. 264
  129. 300
  130. 330
  131. 358
  132. 406
  133. 428
  134. 452
  135. 476
  136. 493
  137.  
  138. X About this book
  139. X How the web works
  140. X Learning from other pages
  141. Introduction
  142. 3 INTRODUCTION
  143. Firstly, thank you for picking up this
  144. book. It has been written with two very
  145. different types of people in mind:
  146. ● Those who want to learn how to design and build websites
  147. from scratch
  148. ● Anyone who has a website (that may be built using a
  149. content management system, blogging software, or an
  150. e-commerce platform) and wants more control over the
  151. appearance of their pages
  152. The only things you need in order to use this book are a
  153. computer with a web browser and a text editor (such as
  154. Notepad, which comes with Windows, or TextEdit, which
  155. comes with Macs).
  156. INTRODUCTION 4
  157. Introduction pages come at the beginning of each
  158. chapter. They introduce the key topics you will learn
  159. about.
  160. Reference pages introduce key pieces of HTML &
  161. CSS code. The HTML code is shown in blue and CSS
  162. code is shown in pink.
  163. Background pages appear on white; they explain the
  164. context of the topics covered that are discussed in
  165. each chapter.
  166. Diagram and infographics pages are shown on a
  167. dark background. They provide a simple, visual
  168. reference to topics discussed.
  169. Example pages put together the topics you have
  170. learned and demonstrate how they can be applied
  171. in each.
  172. Summary pages come at the end of each chapter.
  173. They remind you of the key topics that were covered
  174. in each chapter.
  175. 5 INTRODUCTION
  176. At work, when people look
  177. at my screen and see it full of
  178. code, it's not unusual to get a
  179. comment about it looking very
  180. complicated or how clever I must
  181. be to understand it. The truth
  182. is, it's not that hard to learn how
  183. to write web pages and read
  184. the code used to create them;
  185. you certainly don't have to be a
  186. "programmer."
  187. Understanding HTML and CSS
  188. can help anyone who works
  189. with the web; designers can
  190. create more attractive and
  191. usable sites, website editors can
  192. create better content, marketers
  193. can communicate with their
  194. audience more effectively, and
  195. managers can commission
  196. better sites and get the best out
  197. of their teams.
  198. I've focussed on the code you
  199. need to use 90% of the time
  200. and omitted the code that you
  201. would rarely see even if writing
  202. websites is your full time job. By
  203. the end of the book, if you come
  204. across the other 10% you will be
  205. able to Google it to find out what
  206. it means quickly and easily.
  207. I have also added practical
  208. information on topics I am
  209. commonly asked about, such as
  210. how to prepare images, audio
  211. and video for the web, how to
  212. approach the design and build
  213. of a new site, how to improve
  214. your rankings in search engines
  215. (SEO), and how to use Google
  216. Analytics to learn about visitors
  217. to your site.
  218. Many books that teach HTML and CSS
  219. resemble dull manuals. To make it easier for
  220. you to learn, we threw away the traditional
  221. template used by publishers and redesigned
  222. this book from scratch.
  223. Is it hard to Learn?
  224. INTRODUCTION 6
  225. 1: HTML
  226. We will spend the first chapter
  227. looking at how HTML is used to
  228. create web pages. You will see
  229. that you start by writing down
  230. the words you want to appear
  231. on your page. You then add tags
  232. or elements to the words so
  233. that the browser knows what is
  234. a heading, where a paragraph
  235. begins and ends, and so on.
  236. The rest of this section
  237. introduces the tags you have
  238. at your disposal to create web
  239. pages, grouped into chapters on:
  240. text, lists, links, images, tables,
  241. forms, video audio and flash, and
  242. miscellaneous elements.
  243. I should warn you that the
  244. examples in the first nine
  245. chapters are not exciting to look
  246. at, yet they are the foundation of
  247. every web page. The following
  248. chapters on CSS will show you
  249. how to make your pages look a
  250. lot more interesting.
  251. 2: CSS
  252. We start this section with a
  253. chapter that explains how CSS
  254. uses rules to enable you to
  255. control the styling and layout
  256. of web pages. We then go on to
  257. look at the wide variety of CSS
  258. properties you can use in your
  259. CSS rules. These properties
  260. generally fall into one of two
  261. categories:
  262. Presentation: How to control
  263. things like the color of text, the
  264. fonts you want to use and the
  265. size of those fonts, how to add
  266. background colors to pages (or
  267. parts of a page), and how to add
  268. background images.
  269. Layout: How to control where
  270. the different elements are
  271. positioned on the screen. You
  272. will also learn several techniques
  273. that professionals use to make
  274. their pages more attractive.
  275. 3: Practical
  276. We end up with some helpful
  277. information that will assist you in
  278. building better websites.
  279. We look at some new tags that
  280. will be introduced in HTML5 to
  281. help describe the structure of
  282. your pages. HTML5 is the latest
  283. version of HTML (still under
  284. development at the time of
  285. writing). Before learning about
  286. these elements, you need a good
  287. grasp of how CSS is used to
  288. control the design of web pages.
  289. There is a chapter that talks you
  290. through a design process that
  291. you might like to follow when
  292. creating a new website.
  293. Finally, we end up looking at
  294. topics that will help you once
  295. you have built your site, such
  296. as putting it on the web, search
  297. engine optimisation (SEO) and
  298. using analytics software to track
  299. who comes to your site and what
  300. they are looking at.
  301. In order to teach you about creating web pages,
  302. this book is divided into three sections:
  303. The Structure of
  304. This Book
  305. 7 INTRODUCTION
  306. Browsers
  307. People access websites using
  308. software called a web browser.
  309. Popular examples include
  310. Firefox, Internet Explorer, Safari,
  311. Chrome, and Opera.
  312. In order to view a web page,
  313. users might type a web address
  314. into their browser, follow a
  315. link from another site, or use a
  316. bookmark.
  317. Software manufacturers
  318. regularly release new versions
  319. of browsers with new features
  320. and supporting new additions
  321. to languages. It is important,
  322. however, to remember that
  323. many computer owners will not
  324. be running the latest versions
  325. of these browsers. Therefore
  326. you cannot rely on all visitors to
  327. your site being able to use the
  328. latest functionality offered in all
  329. browsers.
  330. You will learn how to tell which
  331. browsers visitors use to access
  332. your website in Chapter 19.
  333. Web Servers
  334. When you ask your browser for
  335. a web page, the request is sent
  336. across the Internet to a special
  337. computer known as a web
  338. server which hosts the website.
  339. Web servers are special
  340. computers that are constantly
  341. connected to the Internet, and
  342. are optimized to send web pages
  343. out to people who request them.
  344. Some big companies run their
  345. own web servers, but it is more
  346. common to use the services of
  347. a web hosting company who
  348. charge a fee to host your site.
  349. Devices
  350. People are accessing websites
  351. on an increasing range of devices
  352. including desktop computers,
  353. laptops, tablets, and mobile
  354. phones. It is important to
  355. remember that various devices
  356. have different screen sizes and
  357. some have faster connections to
  358. the web than others.
  359. Screen readers
  360. Screen readers are programs
  361. that read out the contents of a
  362. computer screen to a user. They
  363. are commonly used by people
  364. with visual impairments.
  365. In the same way that many
  366. countries have legislations
  367. that require public buildings
  368. to be accessible to those with
  369. disabilities, many laws have
  370. also been passed that require
  371. websites be accessible to those
  372. with disabilities.
  373. Throughout this book you will
  374. see several references to screen
  375. readers. These notes will help
  376. ensure that the sites you create
  377. are accessible to people who use
  378. such software.
  379. It is interesting to note that
  380. technologies similar to those
  381. employed by screen readers are
  382. also being used in other areas
  383. where people are unable read a
  384. screen, such as when they are
  385. driving or jogging.
  386. Before we look at the code used to build
  387. websites it is important to consider the
  388. different ways in which people access the web
  389. and clarify some terminology.
  390. How People
  391. Access the Web
  392. INTRODUCTION 8
  393. What you see
  394. When you are looking at a
  395. website, it is most likely that
  396. your browser will be receiving
  397. HTML and CSS from the web
  398. server that hosts the site. The
  399. web browser interprets the
  400. HTML and CSS code to create
  401. the page that you see.
  402. Most web pages also include
  403. extra content such as images,
  404. audio, video, or animations and
  405. this book will teach you how to
  406. prepare them for use on the web
  407. and then how to insert them into
  408. your web pages.
  409. Some sites also send JavaScript
  410. or Flash to your browser, and you
  411. will see how to add JavaScript
  412. and Flash in your web pages.
  413. Both of these technologies are
  414. advanced topics that you can go
  415. on to learn more about once you
  416. have mastered HTML and CSS, if
  417. you want to.
  418. How it is Created
  419. Small websites are often written
  420. just using HTML and CSS.
  421. Larger websites — in particular
  422. those that are updated regularly
  423. and use a content management
  424. system (CMS), blogging tools, or
  425. e-commerce software — often
  426. make use of more complex
  427. technologies on the web server,
  428. but these technologies are
  429. actually used to produce HTML
  430. and CSS that is then sent to the
  431. browser. So, if your site uses
  432. these technologies, you will be
  433. able to use your new HTML and
  434. CSS knowledge to take more
  435. control over how your site looks.
  436. Larger, more complex sites like
  437. these may use a database to
  438. store data, and programming
  439. languages such as PHP, ASP.Net,
  440. Java, or Ruby on the web server,
  441. but you do not need to know
  442. these technologies to improve
  443. what the user sees. The skills
  444. you'll learn in this book should be
  445. enough to help you on that road.
  446. HTML5 & CSS3
  447. Since the web was first created
  448. there have been several versions
  449. of HTML and CSS — each
  450. intended to be an improvement
  451. on the previous version.
  452. At the time of writing this
  453. book, HTML5 & CSS3 were
  454. still being developed. Although
  455. they had not been finalized,
  456. many browsers were already
  457. supporting some features of
  458. these languages and a lot of
  459. people were using the latest
  460. code on their websites. I have
  461. therefore chosen to teach you
  462. these latest versions.
  463. Because HTML5 and CSS3
  464. build on previous versions of
  465. these languages, learning these
  466. means you will also be able to
  467. understand the earlier versions
  468. of them. I have added clear notes
  469. when the code is new and also
  470. when it might not work in older
  471. browsers.
  472. All websites use HTML and CSS, but content
  473. management systems, blogging software, and
  474. e-commerce platforms often add a few more
  475. technologies into the mix.
  476. How Websites
  477. Are Created
  478. 9 INTRODUCTION
  479. On this page you can see
  480. examples that demonstrate
  481. how the web server that hosts
  482. the website you are visiting can
  483. be anywhere in the world. It is
  484. the DNS servers that tell your
  485. browser how to find the website.
  486. ● A user in Barcelona visits
  487. sony.jp in Tokyo
  488. ● A user in New York visits
  489. google.com in San Francisco
  490. ● A user in Stockholm visits
  491. qantas.com.au in Sydney
  492. ● A user in Vancouver visits
  493. airindia.in in Bangalore
  494. On the right you can see what
  495. happens when a web user in
  496. England wants to view the
  497. website of the Louvre art gallery
  498. in France which is located at
  499. www.louvre.fr. Firstly, the
  500. browser in Cambridge contacts
  501. a DNS server in London. The
  502. DNS server then tells the
  503. browser the location of the web
  504. server hosting the site in Paris.
  505. When you visit a website, the web server
  506. hosting that site could be anywhere in the
  507. world. In order for you to find the location of
  508. the web server, your browser will first connect
  509. to a Domain Name System (DNS) server.
  510. How the Web Works
  511. PARIS
  512. LONDON
  513. Cambridge
  514. The unique number that the
  515. DNS server returns to your
  516. computer allows your browser
  517. to contact the web server
  518. that hosts the website you
  519. requested. A web server is a
  520. computer that is constantly
  521. connected to the web, and is set
  522. up especially to send web pages
  523. to users.
  524. The web server then sends the
  525. page you requested back to your
  526. web browser.
  527. When you connect to the web,
  528. you do so via an Internet Service
  529. Provider (ISP). You type a
  530. domain name or web address
  531. into your browser to visit a site;
  532. for example: google.com,
  533. bbc.co.uk, microsoft.com.
  534. Your computer contacts a
  535. network of servers called
  536. Domain Name System (DNS)
  537. servers. These act like phone
  538. books; they tell your computer
  539. the IP address associated with
  540. the requested domain name.
  541. An IP address is a number
  542. of up to 12 digits separated
  543. by periods / full stops. Every
  544. device connected to the web
  545. has a unique IP address; it is
  546. like the phone number for that
  547. computer.
  548. 1
  549. 4
  550. 2
  551. 3
  552.  
  553. 1
  554. X Understanding structure
  555. X Learning about markup
  556. X Tags and elements
  557. Structure
  558. 13 STRUCTURE
  559. We come across all kinds of documents
  560. every day of our lives. Newspapers,
  561. insurance forms, shop catalogues... the
  562. list goes on.
  563. Many web pages act like electronic versions of these
  564. documents. For example, newspapers show the same stories
  565. in print as they do on websites; you can apply for insurance
  566. over the web; and stores have online catalogs and e-commerce
  567. facilities.
  568. In all kinds of documents, structure is very important in helping
  569. readers to understand the messages you are trying to convey
  570. and to navigate around the document. So, in order to learn how
  571. to write web pages, it is very important to understand how to
  572. structure documents. In this chapter you will:
  573. ● See how HTML describes the structure of a web page
  574. ● Learn how tags or elements are added to your document
  575. ● Write your first web page
  576. STRUCTURE 14
  577. 15 STRUCTURE
  578. Think about the stories you
  579. read in a newspaper: for each
  580. story, there will be a headline,
  581. some text, and possibly some
  582. images. If the article is a long
  583. piece, there may be subheadings
  584. that split the story into separate
  585. sections or quotes from those
  586. involved. Structure helps readers
  587. understand the stories in the
  588. newspaper.
  589. The structure is very similar
  590. when a news story is viewed
  591. online (although it may also
  592. feature audio or video). This is
  593. illustrated on the right with a
  594. copy of a newspaper alongside
  595. the corresponding article on its
  596. website.
  597. Now think about a very different
  598. type of document — an
  599. insurance form. Insurance forms
  600. often have headings for different
  601. sections, and each section
  602. contains a list of questions with
  603. areas for you to fill in details or
  604. checkboxes to tick. Again, the
  605. structure is very similar online.
  606. How Pages Use
  607. Structure
  608. STRUCTURE 16
  609. 17 STRUCTURE
  610. The use of headings and
  611. subheadings in any document
  612. often reflects a hierarchy of
  613. information. For example, a
  614. document might start with
  615. a large heading, followed by
  616. an introduction or the most
  617. important information.
  618. This might be expanded upon
  619. under subheadings lower down
  620. on the page. When using a word
  621. processor to create a document,
  622. we separate out the text to give
  623. it structure. Each topic might
  624. have a new paragraph, and each
  625. section can have a heading to
  626. describe what it covers.
  627. On the right, you can see a
  628. simple document in Microsoft
  629. Word. The different styles for
  630. the document, such as different
  631. levels of heading, are shown
  632. in the drop down box. If you
  633. regularly use Word, you might
  634. have also used the formatting
  635. toolbar or palette to do this.
  636. Structuring Word
  637. Documents
  638. STRUCTURE 18
  639. 19 STRUCTURE
  640. On the previous page you saw
  641. how structure was added to
  642. a Word document to make it
  643. easier to understand. We use
  644. structure in the same way when
  645. writing web pages.
  646. STRUCTURE 20
  647. In the browser window you can see a web page that features exactly
  648. the same content as the Word document you met on the page 18. To
  649. describe the structure of a web page, we add code to the words we want
  650. to appear on the page.
  651. You can see the HTML code for this page below. Don't worry about what
  652. the code means yet. We start to look at it in more detail on the next
  653. page. Note that the HTML code is in blue, and the text you see on screen
  654. is in black.
  655. <html>
  656. <body>
  657. <h1>This is the Main Heading</h1>
  658. <p>This text might be an introduction to the rest of
  659. the page. And if the page is a long one it might
  660. be split up into several sub-headings.<p>
  661. <h2>This is a Sub-Heading</h2>
  662. <p>Many long articles have sub-headings so to help
  663. you follow the structure of what is being written.
  664. There may even be sub-sub-headings (or lower-level
  665. headings).</p>
  666. <h2>Another Sub-Heading</h2>
  667. <p>Here you can see another sub-heading.</p>
  668. </body>
  669. </html>
  670. The HTML code (in blue) is made up of characters that live inside angled
  671. brackets — these are called HTML elements. Elements are usually
  672. made up of two tags: an opening tag and a closing tag. (The closing tag
  673. has an extra forward slash in it.) Each HTML element tells the browser
  674. something about the information that sits between its opening and
  675. closing tags.
  676. HTML Describes
  677. the Structure
  678. of Pages
  679. 21 STRUCTURE
  680. Let's look closer at the code from the last page.
  681. There are several different elements. Each
  682. element has an opening tag and a closing tag.
  683. Code
  684. HTML Uses Elements
  685. to Describe the
  686. Structure of Pages
  687. <html>
  688. <body>
  689. <h1>This is the Main Heading</h1>
  690. <p>This text might be an introduction to the rest of
  691. the page. And if the page is a long one it might
  692. be split up into several sub-headings.<p>
  693. <h2>This is a Sub-Heading</h2>
  694. <p>Many long articles have sub-headings so to help
  695. you follow the structure of what is being written.
  696. There may even be sub-sub-headings (or lower-level
  697. headings).</p>
  698. <h2>Another Sub-Heading</h2>
  699. <p>Here you can see another sub-heading.</p>
  700. </body>
  701. </html>
  702. STRUCTURE 22
  703. Tags act like containers. They tell you
  704. something about the information that lies
  705. between their opening and closing tags.
  706. Description
  707. The opening <html> tag indicates that anything between it and a closing </html> tag is HTML code.
  708. The <body> tag indicates that anything between it and the closing
  709. </body> tag should be shown inside the main browser window.
  710. Words between <h1> and </h1> are a main heading.
  711. A paragraph of text appears between these <p> and </p> tags.
  712. Words between <h2> and </h2> form a sub-heading.
  713. Here is another paragraph between opening <p> and closing </p> tags.
  714. Another sub-heading inside <h2> and </h2> tags.
  715. Another paragraph inside <p> and </p> tags.
  716. The closing </body> tag indicates the end of what should appear in the main browser window.
  717. The closing </html> tag indicates that it is the end of the HTML code.
  718. 23 STRUCTURE
  719. The characters in the brackets
  720. indicate the tag's purpose.
  721. For example, in the tags above
  722. the p stands for paragraph.
  723. The closing tag has a forward
  724. slash after the the < symbol.
  725. A Closer Look at Tags
  726. <p>
  727. left-angle bracket
  728. (less-than sign)
  729. RIGHT-angle bracket
  730. (MORE-than sign)
  731. Character
  732. Opening Tag
  733. STRUCTURE 24
  734. The terms "tag" and "element"
  735. are often used interchangeably.
  736. Strictly speaking, however, an
  737. element comprises the opening
  738. tag and the closing tag and any
  739. content that lies between them.
  740. </p>
  741. left-angle bracket
  742. (less-than sign)
  743. RIGHT-angle bracket
  744. (MORE-than sign)
  745. Forward Slash
  746. Character
  747. Closing Tag
  748. 25 STRUCTURE
  749. The attribute name indicates
  750. what kind of extra information
  751. you are supplying about the
  752. element's content. It should be
  753. written in lowercase.
  754. The value is the information
  755. or setting for the attribute. It
  756. should be placed in double
  757. quotes. Different attributes can
  758. have different values.
  759. Here an attribute called lang is
  760. used to indicate the language
  761. used in this element. The value
  762. of this attribute on this page
  763. specifies it is in US English.
  764. Attributes provide additional information
  765. about the contents of an element. They appear
  766. on the opening tag of the element and are
  767. made up of two parts: a name and a value,
  768. separated by an equals sign.
  769. Attributes Tell Us
  770. More About Elements
  771. <p lang="en-us">Paragraph in English</p>
  772. Attribute
  773. Name
  774. Attribute
  775. Value
  776. STRUCTURE 26
  777. The majority of attributes can
  778. only be used on certain
  779. elements, although a few
  780. attributes (such as lang)
  781. can appear on any element.
  782. Most attribute values are
  783. either pre-defined or follow a
  784. stipulated format. We will look
  785. at the permitted values as we
  786. introduce each new attribute.
  787. The value of the lang attribute
  788. is an abbreviated way of
  789. specifying which language is
  790. used inside the element that
  791. all browsers understand.
  792. HTML5 allows you to use
  793. uppercase attribute names and
  794. omit the quotemarks, but this is
  795. not recommended.
  796. <p lang="fr">Paragraphe en Français</p>
  797. Attribute
  798. Name
  799. Attribute
  800. Value
  801. 27 STRUCTURE
  802. <html>
  803. <head>
  804. <title>This is the Title of the Page</title>
  805. </head>
  806. <body>
  807. <h1>This is the Body of the Page</h1>
  808. <p>Anything within the body of a web page is
  809. displayed in the main browser window.</p>
  810. </body>
  811. </html>
  812. /chapter-01/body-head-title.html HTML
  813. Result
  814. <body>
  815. You met the <body> element
  816. in the first example we created.
  817. Everything inside this element is
  818. shown inside the main browser
  819. window.
  820. <head>
  821. Before the <body> element you
  822. will often see a <head> element.
  823. This contains information
  824. about the page (rather than
  825. information that is shown within
  826. the main part of the browser
  827. window that is highlighted in
  828. blue on the opposite page).
  829. You will usually find a <title>
  830. element inside the <head>
  831. element.
  832. <title>
  833. The contents of the <title>
  834. element are either shown in the
  835. top of the browser, above where
  836. you usually type in the URL of
  837. the page you want to visit, or
  838. on the tab for that page (if your
  839. browser uses tabs to allow you
  840. to view multiple pages at the
  841. same time).
  842. Body, Head & Title
  843. STRUCTURE 28
  844. You may know that HTML
  845. stands for HyperText Markup
  846. Language. The HyperText part
  847. refers to the fact that HTML
  848. allows you to create links that
  849. allow visitors to move from one
  850. page to another quickly and
  851. easily. A markup language allows
  852. you to annotate text, and these
  853. annotations provide additional
  854. meaning to the contents of a
  855. document. If you think of a web
  856. page, we add code around the
  857. original text we want to display
  858. and the browser then uses
  859. the code to display the page
  860. correctly. So the tags we add are
  861. the markup.
  862. Anything written between the
  863. <title> tags will appear in the
  864. title bar (or tabs) at the top of
  865. the browser window, highlighted
  866. in orange here.
  867. Anything written between
  868. the <body> tags will appear
  869. in the main browser window,
  870. highlighted in blue here.
  871. 29 STRUCTURE
  872. 1
  873. 2
  874. Type the code shown on the
  875. right.
  876. To create your first web page on
  877. a PC, start up Notepad. You can
  878. find this by going to:
  879. Start
  880. All Programs (or Programs)
  881. Accessories
  882. Notepad
  883. You might also like to download
  884. a free editor called Notepad++
  885. from notepad-plus-plus.org.
  886. Creating a Web Page
  887. on a PC
  888. 1
  889. 2
  890. Article
  891. STRUCTURE 30
  892. 3
  893. 4
  894. Start your web browser. Go to
  895. the File menu and select Open.
  896. Browse to the file that you just
  897. created, select it and click on the
  898. Open button. The result should
  899. look something like the screen
  900. shot to the left.
  901. If it doesn't look like this, find
  902. the file you just created on your
  903. computer and make sure that it
  904. has the file extension .html (if
  905. it is .txt then you need to go
  906. back to Notepad and save the
  907. file again, but this time put quote
  908. marks around the name "firsttest.html").
  909. Go to the File menu and select
  910. Save as... You will need to save
  911. the file somewhere you can
  912. remember. If you like, you could
  913. create a folder for any examples
  914. that you try out from this book.
  915. Save this file as first-test.
  916. html. Make sure that the Save
  917. as type drop down has All Files
  918. selected.
  919. 3
  920. 4
  921. 31 STRUCTURE
  922. 1
  923. 2
  924. Type the code shown on the
  925. right.
  926. To create your first web page on
  927. a Mac, start up TextEdit. This
  928. should be in your Applications
  929. folder.
  930. You might also like to download
  931. a free text editor for creating
  932. web pages called TextWrangler
  933. which is available from
  934. barebones.com.
  935. Creating a Web Page
  936. on a Mac
  937. 1
  938. 2
  939. Article
  940. STRUCTURE 32
  941. 3
  942. 4
  943. Next, start your web browser,
  944. go to the File menu, and select
  945. Open. You should browse to the
  946. file that you just created, select
  947. it and click on the Open button.
  948. The result should look like the
  949. screen shot to the left.
  950. If it doesn't look like this, you
  951. might need to change one of
  952. the settings in TextEdit. Go to
  953. the TextEdit menu and select
  954. Preferences. Then on the
  955. preferences for Open and Save,
  956. tick the box that says Ignore rich
  957. text commands in HTML files.
  958. Now try to save the file again.
  959. Now go to the File menu and
  960. select Save as... You will need to
  961. save the file somewhere you can
  962. remember.
  963. If you like, you could create a
  964. folder for any examples that you
  965. try out from this book. Save this
  966. file as first-test.html. You
  967. will probably see a window like
  968. the screen shot to the left.
  969. You want to select the Use .html
  970. button.
  971. 3
  972. 4
  973. 33 STRUCTURE
  974. If you are working with a content
  975. management system, blogging
  976. platform, or e-commerce
  977. application, you will probably
  978. log into a special administration
  979. section of the website to control
  980. it. The tools provided in the
  981. administration sections of these
  982. sites usually allow you to edit
  983. parts of the page rather than
  984. the entire page, which means
  985. you will rarely see the <html>,
  986. <head>, or <body> elements.
  987. Looking at the content
  988. management system on the
  989. opposite page, you have a box
  990. that allows you to enter a title
  991. for the page, another box for the
  992. main article, a way to enter a
  993. publication date, and something
  994. to indicate which section of the
  995. site this page belongs in.
  996. For an e-commerce store, you
  997. might have boxes that allow you
  998. to enter a title for the product,
  999. a description of the product, its
  1000. price, and the quantity available.
  1001. That is because they use a single
  1002. 'template' to control all of the
  1003. pages for a section of the site.
  1004. (For example, an e-commerce
  1005. system might use the same
  1006. template to show all of their
  1007. products.) The information
  1008. you supply is placed into the
  1009. templates.
  1010. The advantage of this approach
  1011. is that people who do not know
  1012. how to write web pages can
  1013. add information to a website
  1014. and it is also possible to change
  1015. the presentation of something
  1016. in the template, and it will
  1017. automatically update every page
  1018. that uses that template. If you
  1019. imagine an e-commerce store
  1020. with 1,000 items for sale, just
  1021. Code in a Content
  1022. Management System
  1023. STRUCTURE 34
  1024. altering one template is a lot
  1025. easier than changing the page
  1026. for each individual product.
  1027. In systems like this, when
  1028. you have a large block of text
  1029. that you can edit, such as a
  1030. news article, blog entry or the
  1031. description of a product in an
  1032. e-commerce store, you will often
  1033. see a text editor displayed.
  1034. Text editors usually have
  1035. controls a little like those on
  1036. your word processor, giving
  1037. you different options to style
  1038. text, add links or insert images.
  1039. Behind the scenes these editors
  1040. are adding HTML code to your
  1041. text, just like the code you have
  1042. seen earlier in this chapter.
  1043. Many of these editors will have
  1044. an option that allows you to see
  1045. (and edit) the code that they
  1046. produce.
  1047. Once you know how to read and
  1048. edit this code, you can take more
  1049. control over these sections of
  1050. your website.
  1051. In the example above, you can
  1052. see that the text editor has a tab
  1053. for Visual / HTML views of what
  1054. the user enters. Other systems
  1055. might have a button (which
  1056. often shows angle brackets) to
  1057. indicate how to access the code.
  1058. Some content management
  1059. systems offer tools that also
  1060. allow you to edit the template
  1061. files. If you do try to edit
  1062. template files you need to check
  1063. the documentation for your CMS
  1064. as they all differ from each other.
  1065. You need to be careful when
  1066. editing template files because
  1067. if you delete the wrong piece of
  1068. code or add something in the
  1069. wrong place the site may stop
  1070. working entirely.
  1071. 35 STRUCTURE
  1072. When the web was first taking
  1073. off, one of the most common
  1074. ways to learn about HTML and
  1075. discover new tips and techniques
  1076. was to look at the source code
  1077. that made up web pages.
  1078. These days there are many
  1079. more books and online tutorials
  1080. that teach HTML, but you can
  1081. still look at the code that a web
  1082. server sends to you. To try this
  1083. out for yourself, simply go to the
  1084. sample code for this chapter, at
  1085. www.htmlandcssbook.com/
  1086. code/ and click on the link called
  1087. "View Source."
  1088. Once you have opened this
  1089. page, you can look for the View
  1090. menu in your browser, and select
  1091. the option that says Source or
  1092. View source. (The title changes
  1093. depending on what browser you
  1094. are using.)
  1095. You should see a new window
  1096. appear, and it will contain the
  1097. source code that was used to
  1098. create this page.
  1099. You can see this result in the
  1100. photograph on the right. The
  1101. page you see is the window at
  1102. the top; the code is below.
  1103. At first this code might look
  1104. complicated but don't be
  1105. discouraged. By the time you
  1106. have finished the next chapter
  1107. of this book, you will be able to
  1108. understand it.
  1109. All of the examples for this book
  1110. are on the website, and you can
  1111. use this simple technique on any
  1112. of the example pages to see how
  1113. they work.
  1114. You can also download all of
  1115. the code for this book from the
  1116. same website by clicking on the
  1117. "Download" link.
  1118. Looking at How Other
  1119. sites are Built
  1120. STRUCTURE 36
  1121.  
  1122. Summary
  1123. STRUCTURE
  1124. X HTML pages are text documents.
  1125. X HTML uses tags (characters that sit inside angled
  1126. brackets) to give the information they surround special
  1127. meaning.
  1128. X Tags are often referred to as elements.
  1129. X Tags usually come in pairs. The opening tag denotes
  1130. the start of a piece of content; the closing tag denotes
  1131. the end.
  1132. X Opening tags can carry attributes, which tell us more
  1133. about the content of that element.
  1134. X Attributes require a name and a value.
  1135. X To learn HTML you need to know what tags are
  1136. available for you to use, what they do, and where they
  1137. can go.
  1138.  
  1139. X Headings and paragraphs
  1140. X Bold, italic, emphasis
  1141. X Structural and semantic markup
  1142. Text
  1143. 2
  1144. 41 TEXT
  1145. When creating a web page, you add tags
  1146. (known as markup) to the contents of the
  1147. page. These tags provide extra meaning
  1148. and allow browsers to show users the
  1149. appropriate structure for the page.
  1150. In this chapter we focus on how to add markup to the text that
  1151. appears on your pages. You will learn about:
  1152. ● Structural markup: the elements that you can use to
  1153. describe both headings and paragraphs
  1154. ● Semantic markup: which provides extra information; such
  1155. as where emphasis is placed in a sentence, that something
  1156. you have written is a quotation (and who said it), the
  1157. meaning of acronyms, and so on
  1158. TEXT 42
  1159. 43 TEXT
  1160. R esult
  1161. <h1>This is a Main Heading</h1>
  1162. <h2>This is a Level 2 Heading</h2>
  1163. <h3>This is a Level 3 Heading</h3>
  1164. <h4>This is a Level 4 Heading</h4>
  1165. <h5>This is a Level 5 Heading</h5>
  1166. <h6>This is a Level 6 Heading</h6>
  1167. chapter-02/headings.html HTML
  1168. Headings
  1169. <h1>
  1170. <h2>
  1171. <h3>
  1172. <h4>
  1173. <h5>
  1174. <h6>
  1175. HTML has six "levels" of
  1176. headings:
  1177. <h1> is used for main headings
  1178. <h2> is used for subheadings
  1179. If there are further sections
  1180. under the subheadings then the
  1181. <h3> element is used, and so
  1182. on...
  1183. Browsers display the contents of
  1184. headings at different sizes. The
  1185. contents of an <h1> element is
  1186. the largest, and the contents of
  1187. an <h6> element is the smallest.
  1188. The exact size at which each
  1189. browser shows the headings
  1190. can vary slightly. Users can also
  1191. adjust the size of text in their
  1192. browser. You will see how to
  1193. control the size of text, its color,
  1194. and the fonts used when we
  1195. come to look at CSS.
  1196. Article
  1197. TEXT 44
  1198. R esult
  1199. <html>
  1200. HTML chapter-02/paragraphs.html <p>
  1201. To create a paragraph, surround
  1202. the words that make up the
  1203. paragraph with an opening <p>
  1204. tag and closing </p> tag.
  1205. By default, a browser will show
  1206. each paragraph on a new line
  1207. with some space between it and
  1208. any subsequent paragraphs.
  1209. Paragraphs
  1210. <p>A paragraph consists of one or more sentences
  1211. that form a self-contained unit of discourse. The
  1212. start of a paragraph is indicated by a new
  1213. line.</p>
  1214. <p>Text is easier to understand when it is split up
  1215. into units of text. For example, a book may have
  1216. chapters. Chapters can have subheadings. Under
  1217. each heading there will be one or more
  1218. paragraphs.</p>
  1219. HTML
  1220. 45 TEXT
  1221. <p>This is how we make a word appear <i>italic</i>.
  1222. </p>
  1223. <p>It's a potato <i>Solanum teberosum</i>.</p>
  1224. <p>Captain Cook sailed to Australia on the
  1225. <i>Endeavour</i>.</p>
  1226. chapter-02/italic.html HTML
  1227. R esult
  1228. <p>This is how we make a word appear <b>bold.</b>
  1229. </p>
  1230. <p>Inside a product description you might see some
  1231. <b>key features</b> in bold.</p>
  1232. chapter-02/bold.html HTML
  1233. R esult
  1234. <i>
  1235. By enclosing words in the tags
  1236. <i> and </i> we can make
  1237. characters appear italic.
  1238. The <i> element also represents
  1239. a section of text that would be
  1240. said in a different way from
  1241. surrounding content — such as
  1242. technical terms, names of ships,
  1243. foreign words, thoughts, or other
  1244. terms that would usually be
  1245. italicized.
  1246. <b>
  1247. By enclosing words in the tags
  1248. <b> and </b> we can make
  1249. characters appear bold.
  1250. The <b> element also represents
  1251. a section of text that would be
  1252. presented in a visually different
  1253. way (for example key words in a
  1254. paragraph) although the use of
  1255. the <b> element does not imply
  1256. any additional meaning.
  1257. Bold & Italic
  1258. Article
  1259. TEXT 46
  1260. R esult
  1261. <p>On the 4<sup>th</sup> of September you will learn
  1262. about E=MC<sup>2</sup>.</p>
  1263. <p>The amount of CO<sub>2</sub> in the atmosphere
  1264. grew by 2ppm in 2009<sub>1</sub>.</p>
  1265. HTML chapter-02/superscript-and-subscript.html <sup>
  1266. The <sup> element is used
  1267. to contain characters that
  1268. should be superscript such
  1269. as the suffixes of dates or
  1270. mathematical concepts like
  1271. raising a number to a power such
  1272. as 22
  1273. .
  1274. <sub>
  1275. The <sub> element is used to
  1276. contain characters that should
  1277. be subscript. It is commonly
  1278. used with foot notes or chemical
  1279. formulas such as H2
  1280. 0.
  1281. Superscript &
  1282. Subscript
  1283. 47 TEXT
  1284. R esult
  1285. <p>The moon is drifting away from Earth.</p>
  1286. <p>The moon is drifting away from Earth.</p>
  1287. <p>The moon is drifting away from
  1288. Earth.</p>
  1289. chapter-02/white-space.html HTML
  1290. In order to make code easier to
  1291. read, web page authors often
  1292. add extra spaces or start some
  1293. elements on new lines.
  1294. When the browser comes across
  1295. two or more spaces next to each
  1296. other, it only displays one space.
  1297. Similarly if it comes across a line
  1298. break, it treats that as a single
  1299. space too. This is known as
  1300. white space collapsing.
  1301. You will often see that web page
  1302. authors take advantage of white
  1303. space collapsing to indent their
  1304. code in order to make it easier
  1305. to follow.
  1306. White Space
  1307. Article
  1308. TEXT 48
  1309. <p>Venus is the only planet that rotates
  1310. clockwise.</p>
  1311. <hr />
  1312. <p>Jupiter is bigger than all the other planets
  1313. combined.</p>
  1314. HTML chapter-02/horizontal-rules.html
  1315. R esult
  1316. <p>The Earth<br />gets one hundred tons heavier
  1317. every day<br />due to falling space dust.</p>
  1318. HTML chapter-02/line-breaks.html
  1319. R esult
  1320. <hr />
  1321. To create a break between
  1322. themes — such as a change of
  1323. topic in a book or a new scene
  1324. in a play — you can add a
  1325. horizontal rule between sections
  1326. using the <hr /> tag.
  1327. There are a few elements that
  1328. do not have any words between
  1329. an opening and closing tag. They
  1330. are known as empty elements
  1331. and they are written differently.
  1332. An empty element usually
  1333. has only one tag. Before the
  1334. closing angled bracket of an
  1335. empty element there will often
  1336. be a space and a forward slash
  1337. character. Some web page
  1338. authors miss this out but it is a
  1339. good habit to get into.
  1340. <br />
  1341. As you have already seen, the
  1342. browser will automatically show
  1343. each new paragraph or heading
  1344. on a new line. But if you wanted
  1345. to add a line break inside the
  1346. middle of a paragraph you can
  1347. use the line break tag <br />.
  1348. Line Breaks &
  1349. Horizontal Rules
  1350. 49 TEXT
  1351. Visual editors often resemble
  1352. word processors. Although
  1353. each editor will differ slightly,
  1354. there are some features that
  1355. are common to most editors
  1356. that allow you to control the
  1357. presentation of text.
  1358. ● Headings are created by
  1359. highlighting text then using
  1360. a drop-down box to select a
  1361. heading.
  1362. ● Bold and italic text are
  1363. created by highlighting some
  1364. text and pressing a b or i
  1365. button.
  1366. ● New paragraphs are created
  1367. using the return or the enter
  1368. key.
  1369. ● Line breaks are created by
  1370. pressing the shift key and the
  1371. return key at the same time.
  1372. ● Horizontal rules are created
  1373. using a button with a straight
  1374. line on it.
  1375. If you copy and paste text from
  1376. a program that allows you to
  1377. format text (such as Word) into
  1378. a visual editor, it may add extra
  1379. markup. To prevent this copy
  1380. the text into a plain text editor
  1381. first (such as Notepad on a PC
  1382. or TextEdit on a Mac) and then
  1383. copy it from that program and
  1384. paste it into the visual editor.
  1385. Code views show you the code
  1386. created by the visual editor so
  1387. you can manually edit it, or so
  1388. you can just enter new code
  1389. yourself. It is often activated
  1390. using a button with an icon
  1391. that says HTML or has angled
  1392. brackets. White space may be
  1393. added to the code by the editor
  1394. to make the code easier to read.
  1395. Content management systems and HTML editors such as Dreamweaver
  1396. usually have two views of the page you are creating: a visual editor and a
  1397. code view.
  1398. Visual Editors &
  1399. Their Code views
  1400. 50TEXT
  1401. In the rest of the chapter you
  1402. will meet some more elements
  1403. that will help you when you are
  1404. adding text to web pages. For
  1405. example, you are going to meet
  1406. the <em> element that allows
  1407. you to indicate where emphasis
  1408. should be placed on selected
  1409. words and the <blockquote>
  1410. element which indicates that a
  1411. block of text is a quotation.
  1412. Browsers often display the
  1413. contents of these elements in
  1414. a different way. For example,
  1415. the content of the <em>
  1416. element is shown in italics,
  1417. and a <blockquote> is usually
  1418. indented. But you should not
  1419. use them to change the way that
  1420. your text looks; their purpose is
  1421. to describe the content of your
  1422. web pages more accurately.
  1423. The reason for using these
  1424. elements is that other programs,
  1425. such as screen readers or search
  1426. engines, can use this extra
  1427. information. For example, the
  1428. voice of a screen reader may add
  1429. emphasis to the words inside
  1430. the <em> element, or a search
  1431. engine might register that your
  1432. page features a quote if you use
  1433. the <blockquote> element.
  1434. There are some text elements that are not intended to affect the
  1435. structure of your web pages, but they do add extra information to the
  1436. pages — they are known as semantic markup.
  1437. Semantic Markup
  1438. 51 TEXT
  1439. <p>I <em>think</em> Ivy was the first.</p>
  1440. <p>I think <em>Ivy</em> was the first.</p>
  1441. <p>I think Ivy was the <em>first</em>.</p>
  1442. chapter-02/emphasis.html HTML
  1443. R esult
  1444. <p><strong>Beware:</strong> Pickpockets operate in
  1445. this area.</p>
  1446. <p>This toy has many small pieces and is <strong>not
  1447. suitable for children under five years old.
  1448. </strong></p>
  1449. chapter-02/strong.html HTML
  1450. R esult
  1451. <em>
  1452. The <em> element indicates
  1453. emphasis that subtly changes
  1454. the meaning of a sentence.
  1455. By default browsers will show
  1456. the contents of an <em> element
  1457. in italic.
  1458. <strong>
  1459. The use of the <strong>
  1460. element indicates that its
  1461. content has strong importance.
  1462. For example, the words
  1463. contained in this element might
  1464. be said with strong emphasis.
  1465. By default, browsers will show
  1466. the contents of a <strong>
  1467. element in bold.
  1468. Strong & Emphasis
  1469. Article
  1470. TEXT 52
  1471. R esult
  1472. <blockquote cite="http://en.wikipedia.org/wiki/
  1473. Winnie-the-Pooh">
  1474. <p>Did you ever stop to think, and forget to start
  1475. again?</p>
  1476. </blockquote>
  1477. <p>As A.A. Milne said, <q>Some people talk to
  1478. animals. Not many listen though. That's the
  1479. problem.</q></p>
  1480. HTML chapter-02/quotations.html
  1481. There are two elements
  1482. commonly used for marking up
  1483. quotations:
  1484. <blockquote>
  1485. The <blockquote> element is
  1486. used for longer quotes that take
  1487. up an entire paragraph. Note
  1488. how the <p> element is still
  1489. used inside the <blockquote>
  1490. element.
  1491. Browsers tend to indent the
  1492. contents of the <blockquote>
  1493. element, however you should not
  1494. use this element just to indent a
  1495. piece of text — rather you should
  1496. achieve this effect using CSS.
  1497. <q>
  1498. The <q> element is used for
  1499. shorter quotes that sit within
  1500. a paragraph. Browsers are
  1501. supposed to put quotes around
  1502. the <q> element, however
  1503. Internet Explorer does not —
  1504. therefore many people avoid
  1505. using the <q> element.
  1506. Both elements may use the cite
  1507. attribute to indicate where the
  1508. quote is from. Its value should
  1509. be a URL that will have more
  1510. information about the source of
  1511. the quotation.
  1512. Quotations
  1513. 53 TEXT
  1514. R esult
  1515. <p><abbr title="Professor">Prof</abbr> Stephen
  1516. Hawking is a theoretical physicist and
  1517. cosmologist.</p>
  1518. <p><acronym title="National Aeronautics and Space
  1519. Administration">NASA</acronym> do some crazy
  1520. space stuff.</p>
  1521. <abbr> chapter-02/abbreviations.html HTML
  1522. If you use an abbreviation or
  1523. an acronym, then the <abbr>
  1524. element can be used. A title
  1525. attribute on the opening tag is
  1526. used to specify the full term.
  1527. In HTML 4 there was a separate
  1528. <acronym> element for
  1529. acronyms. To spell out the full
  1530. form of the acronym, the title
  1531. attribute was used (as with the
  1532. <abbr> element above). HTML5
  1533. just uses the <abbr> element
  1534. for both abbreviations and
  1535. acronyms.
  1536. Abbreviations &
  1537. Acronyms
  1538. Article
  1539. TEXT 54
  1540. <p>A <dfn>black hole</dfn> is a region of space from
  1541. which nothing, not even light, can escape.</p>
  1542. HTML chapter-02/definitions.html
  1543. R esult
  1544. <p><cite>A Brief History of Time</cite> by Stephen
  1545. Hawking has sold over ten million copies
  1546. worldwide.</p>
  1547. HTML chapter-02/citations.html
  1548. R esult
  1549. <dfn>
  1550. The first time you explain some
  1551. new terminology (perhaps an
  1552. academic concept or some
  1553. jargon) in a document, it is
  1554. known as the defining instance
  1555. of it.
  1556. The <dfn> element is used to
  1557. indicate the defining instance of
  1558. a new term.
  1559. Some browsers show the
  1560. content of the <dfn> element in
  1561. italics. Safari and Chrome do not
  1562. change its appearance.
  1563. <cite>
  1564. When you are referencing a
  1565. piece of work such as a book,
  1566. film or research paper, the
  1567. <cite> element can be used
  1568. to indicate where the citation is
  1569. from.
  1570. In HTML5, <cite> should not
  1571. really be used for a person's
  1572. name — but it was allowed in
  1573. HTML 4, so most people are
  1574. likely to continue to use it.
  1575. Browsers will render the content
  1576. of a <cite> element in italics.
  1577. Citations &
  1578. Definitions
  1579. 55 TEXT
  1580. R esult
  1581. <address>
  1582. <p><a href="mailto:homer@example.org">
  1583. homer@example.org</a></p>
  1584. <p>742 Evergreen Terrace, Springfield.</p>
  1585. </address>
  1586. <address> chapter-02/address.html HTML
  1587. The <address> element has
  1588. quite a specific use: to contain
  1589. contact details for the author of
  1590. the page.
  1591. It can contain a physical address,
  1592. but it does not have to. For
  1593. example, it may also contain a
  1594. phone number or email address.
  1595. Browsers often display the
  1596. content of the <address>
  1597. element in italics.
  1598. You may also be interested in
  1599. something called the hCard
  1600. microformat for adding physical
  1601. address information to your
  1602. markup.
  1603. Online extra:
  1604. You can find out more about
  1605. hCards on the website
  1606. accompanying this book.
  1607. Author Details
  1608. Article
  1609. TEXT 56
  1610. <p>Laptop computer:</p>
  1611. <p><s>Was $995</s></p>
  1612. <p>Now only $375</p>
  1613. HTML chapter-02/strikethrough.html
  1614. R esult
  1615. <p>It was the <del>worst</del> <ins>best</ins> idea
  1616. she had ever had.</p>
  1617. HTML chapter-02/insert-and-delete.html
  1618. R esult
  1619. <s>
  1620. The <s> element indicates
  1621. something that is no longer
  1622. accurate or relevant (but that
  1623. should not be deleted).
  1624. Visually the content of an <s>
  1625. element will usually be displayed
  1626. with a line through the center.
  1627. Older versions of HTML had a
  1628. <u> element for content that
  1629. was underlined, but this is being
  1630. phased out.
  1631. <ins>
  1632. <del>
  1633. The <ins> element can be used
  1634. to show content that has been
  1635. inserted into a document, while
  1636. the <del> element can show text
  1637. that has been deleted from it.
  1638. The content of a <ins> element
  1639. is usually underlined, while the
  1640. content of a <del> element
  1641. usually has a line through it.
  1642. Changes to Content
  1643. 57 TEXT
  1644. Example
  1645. TEXT
  1646. TEXT 58
  1647. This is a very simple HTML page that
  1648. demonstrates text markup.
  1649. Structural markup includes elements such as <h1>, <h2>, and <p>.
  1650. Semantic information is carried in elements such as <cite> and <em>.
  1651. <html>
  1652. <head>
  1653. <title>Text</title>
  1654. </head>
  1655. <body>
  1656. <h1>The Story in the Book</h1>
  1657. <h2>Chapter 1</h2>
  1658. <p>Molly had been staring out of her window for about
  1659. an hour now. On her desk, lying between the copies
  1660. of <i>Nature</i>, <i>New Scientist</i>, and all
  1661. the other scientific journals her work had
  1662. appeared in, was a well thumbed copy of <cite>On
  1663. The Road</cite>. It had been Molly's favorite book
  1664. since college, and the longer she spent in these
  1665. four walls the more she felt she needed to be
  1666. free.</p>
  1667. <p>She had spent the last ten years in this room,
  1668. sitting under a poster with an Oscar Wilde quote
  1669. proclaiming that <q>Work is the refuge of
  1670. people who have nothing better to do</q>. Although
  1671. many considered her pioneering work, unraveling
  1672. the secrets of the llama <abbr
  1673. title="Deoxyribonucleic acid">DNA</abbr>, to be an
  1674. outstanding achievement, Molly <em>did</em> think
  1675. she had something better to do.</p>
  1676. </body>
  1677. </html>
  1678.  
  1679. Summary
  1680. TEXT
  1681. X HTML elements are used to describe the structure of
  1682. the page (e.g. headings, subheadings, paragraphs).
  1683. X They also provide semantic information (e.g. where
  1684. emphasis should be placed, the definition of any
  1685. acronyms used, when given text is a quotation).
  1686.  
  1687. X Numbered lists
  1688. X Bullet lists
  1689. X Definition lists
  1690. Lists
  1691. 3
  1692. 63 LISTS
  1693. There are lots of occasions when we
  1694. need to use lists. HTML provides us with
  1695. three different types:
  1696. ● Ordered lists are lists where each item in the list is
  1697. numbered. For example, the list might be a set of steps for
  1698. a recipe that must be performed in order, or a legal contract
  1699. where each point needs to be identified by a section
  1700. number.
  1701. ● Unordered lists are lists that begin with a bullet point
  1702. (rather than characters that indicate order).
  1703. ● Definition lists are made up of a set of terms along with the
  1704. definitions for each of those terms.
  1705. LISTS 64
  1706. 65 LISTS
  1707. Result
  1708. <ol>
  1709. The ordered list is created with
  1710. the <ol> element.
  1711. <li>
  1712. Each item in the list is placed
  1713. between an opening <li> tag
  1714. and a closing </li> tag. (The li
  1715. stands for list item.)
  1716. Browsers indent lists by default.
  1717. Sometimes you may see a type
  1718. attribute used with the <ol>
  1719. element to specify the type of
  1720. numbering (numbers, letters,
  1721. roman numerals and so on). It
  1722. is better to use the CSS liststyle-type
  1723. property covered
  1724. on pages 333-335.
  1725. <ol>
  1726. <li>Chop potatoes into quarters</li>
  1727. <li>Simmer in salted water for 15-20
  1728. minutes until tender</li>
  1729. <li>Heat milk, butter and nutmeg</li>
  1730. <li>Drain potatoes and mash</li>
  1731. <li>Mix in the milk mixture</li>
  1732. </ol>
  1733. chapter-03/ordered-lists.html HTML
  1734. Ordered Lists
  1735. Article
  1736. LISTS 66
  1737. Result
  1738. <ul>
  1739. <li>1kg King Edward potatoes</li>
  1740. <li>100ml milk</li>
  1741. <li>50g salted butter</li>
  1742. <li>Freshly grated nutmeg</li>
  1743. <li>Salt and pepper to taste</li>
  1744. </ul>
  1745. HTML chapter-03/unordered-lists.html
  1746. Unordered Lists
  1747. <ul>
  1748. The unordered list is created
  1749. with the <ul> element.
  1750. <li>
  1751. Each item in the list is placed
  1752. between an opening <li> tag
  1753. and a closing </li> tag. (The li
  1754. stands for list item.)
  1755. Browsers indent lists by default.
  1756. Sometimes you may see a type
  1757. attribute used with the <ul>
  1758. element to specify the type of
  1759. bullet point (circles, squares,
  1760. diamonds and so on). It is better
  1761. to use the CSS list-styletype
  1762. property covered on pages
  1763. 333-335.
  1764. 67 LISTS
  1765. <dl>
  1766. The definition list is created with
  1767. the <dl> element and usually
  1768. consists of a series of terms and
  1769. their definitions.
  1770. Inside the <dl> element you will
  1771. usually see pairs of <dt> and
  1772. <dd> elements.
  1773. <dt>
  1774. This is used to contain the term
  1775. being defined (the definition
  1776. term).
  1777. <dd>
  1778. This is used to contain the
  1779. definition.
  1780. Sometimes you might see a list
  1781. where there are two terms used
  1782. for the same definition or two
  1783. different definitions for the same
  1784. term.
  1785. Result
  1786. <dl>
  1787. <dt>Sashimi</dt>
  1788. <dd>Sliced raw fish that is served with
  1789. condiments such as shredded daikon radish or
  1790. ginger root, wasabi and soy sauce</dd>
  1791. <dt>Scale</dt>
  1792. <dd>A device used to accurately measure the
  1793. weight of ingredients</dd>
  1794. <dd>A technique by which the scales are removed
  1795. from the skin of a fish</dd>
  1796. <dt>Scamorze</dt>
  1797. <dt>Scamorzo</dt>
  1798. <dd>An Italian cheese usually made from whole
  1799. cow's milk (although it was traditionally made
  1800. from buffalo milk)</dd>
  1801. </dl>
  1802. chapter-03/definition-lists.html HTML
  1803. Definition Lists
  1804. Article
  1805. LISTS 68
  1806. You can put a second list inside
  1807. an <li> element to create a sublist
  1808. or nested list.
  1809. Browsers display nested lists
  1810. indented further than the parent
  1811. list. In nested unordered lists,
  1812. the browser will usually change
  1813. the style of the bullet point too.
  1814. Result
  1815. <ul>
  1816. <li>Mousses</li>
  1817. <li>Pastries
  1818. <ul>
  1819. <li>Croissant</li>
  1820. <li>Mille-feuille</li>
  1821. <li>Palmier</li>
  1822. <li>Profiterole</li>
  1823. </ul>
  1824. </li>
  1825. <li>Tarts</li>
  1826. </ul>
  1827. HTML chapter-03/nested-lists.html
  1828. Nested Lists
  1829. 69 LISTS
  1830. Example
  1831. LISTS
  1832. LISTS 70
  1833. <html>
  1834. <head>
  1835. <title>Lists</title>
  1836. </head>
  1837. <body>
  1838. <h1>Scrambled Eggs</h1>
  1839. <p>Eggs are one of my favourite foods. Here is a
  1840. recipe for deliciously rich scrambled eggs.</p>
  1841. <h2>Ingredients</h2>
  1842. <ul>
  1843. <li>2 eggs</li>
  1844. <li>1tbs butter</li>
  1845. <li>2tbs cream</li>
  1846. </ul>
  1847. <h2>Method</h2>
  1848. <ol>
  1849. <li>Melt butter in a frying pan over a medium
  1850. heat</li>
  1851. <li>Gently mix the eggs and cream in a bowl</li>
  1852. <li>Once butter has melted add cream and eggs</li>
  1853. <li>Using a spatula fold the eggs from the edge of
  1854. the pan to the center every 20 seconds (as if
  1855. you are making an omelette)</li>
  1856. <li>When the eggs are still moist remove from the
  1857. heat (it will continue to cook on the plate
  1858. until served)</li>
  1859. </ol>
  1860. </body>
  1861. </html>
  1862. Here you can see a main heading followed by
  1863. an introductory paragraph. An unordered list is
  1864. used to outline the ingredients and an ordered
  1865. list is used to describe the steps.
  1866.  
  1867. Summary
  1868. LISTS
  1869. X There are three types of HTML lists: ordered,
  1870. unordered, and definition.
  1871. X Ordered lists use numbers.
  1872. X Unordered lists use bullets.
  1873. X Definition lists are used to define terminology.
  1874. X Lists can be nested inside one another.
  1875.  
  1876. X Creating links between pages
  1877. X Linking to other sites
  1878. X Email links
  1879. Links
  1880. 4
  1881. 75 LINKS
  1882. Links are the defining feature of the web
  1883. because they allow you to move from
  1884. one web page to another — enabling the
  1885. very idea of browsing or surfing.
  1886. You will commonly come across the following types of links:
  1887. ● Links from one website to another
  1888. ● Links from one page to another on the same website
  1889. ● Links from one part of a web page to another part of the
  1890. same page
  1891. ● Links that open in a new browser window
  1892. ● Links that start up your email program and address a new
  1893. email to someone
  1894. LINKS 76
  1895. 77 LINKS
  1896. Links are created using the <a> element. Users can click on anything
  1897. between the opening <a> tag and the closing </a> tag. You specify
  1898. which page you want to link to using the href attribute.
  1899. Writing Links
  1900. <a href="http://www.imdb.com">IMDB</a>
  1901. This is the page the
  1902. link takes you to
  1903. Opening link tag
  1904. This is the text the
  1905. user clicks on
  1906. Closing
  1907. link tag
  1908. LINKS 78
  1909. The text between the opening
  1910. <a> tag and closing </a> tag
  1911. is known as link text. Where
  1912. possible, your link text should
  1913. explain where visitors will be
  1914. taken if they click on it (rather
  1915. than just saying "click here").
  1916. Below you can see the link to
  1917. IMDB that was created on the
  1918. previous page.
  1919. Many people navigate websites
  1920. by scanning the text for links.
  1921. Clear link text can help visitors
  1922. find what they want. This
  1923. will give them a more positive
  1924. impression of your site and may
  1925. encourage them to visit it for
  1926. longer. (It also helps people
  1927. using screen reader software.)
  1928. To write good link text, you can
  1929. think of words people might
  1930. use when searching for the
  1931. page that you are linking to.
  1932. (For example, rather than write
  1933. "places to stay" you could use
  1934. something more specific such as
  1935. "hotels in New York.")
  1936. 79 LINKS
  1937. Result
  1938. <p>Movie Reviews:
  1939. <ul>
  1940. <li><a href="http://www.empireonline.com">
  1941. Empire</a></li>
  1942. <li><a href="http://www.metacritic.com">
  1943. Metacritic</a></li>
  1944. <li><a href="http://www.rottentomatoes.com">
  1945. Rotten Tomatoes</a></li>
  1946. <li><a href="http://www.variety.com">
  1947. Variety</a></li>
  1948. </ul>
  1949. </p>
  1950. <a> chapter-04/linking-to-other-sites.html HTML
  1951. Links are created using the <a>
  1952. element which has an attribute
  1953. called href. The value of the
  1954. href attribute is the page that
  1955. you want people to go to when
  1956. they click on the link.
  1957. Users can click on anything that
  1958. appears between the opening
  1959. <a> tag and the closing </a>
  1960. tag and will be taken to the page
  1961. specified in the href attribute.
  1962. When you link to a different
  1963. website, the value of the href
  1964. attribute will be the full web
  1965. address for the site, which is
  1966. known as an absolute URL.
  1967. Browsers show links in blue with
  1968. an underline by default.
  1969. Linking to Other Sites
  1970. URL stands for Uniform
  1971. Resource Locator. Every web
  1972. page has its own URL. This is the
  1973. web address that you would type
  1974. into a browser if you wanted to
  1975. visit that specific page.
  1976. An absolute URL starts with
  1977. the domain name for that site,
  1978. and can be followed by the path
  1979. to a specific page. If no page is
  1980. specified, the site will display the
  1981. homepage.
  1982. Absolute URLs
  1983. Article
  1984. LINKS 80
  1985. Result
  1986. <a>
  1987. When you are linking to other
  1988. pages within the same site,
  1989. you do not need to specify the
  1990. domain name in the URL. You
  1991. can use a shorthand known as a
  1992. relative URL.
  1993. If all the pages of the site are in
  1994. the same folder, then the value
  1995. of the href attribute is just the
  1996. name of the file.
  1997. If you have different pages of a
  1998. site in different folders, then you
  1999. can use a slightly more complex
  2000. syntax to indicate where the
  2001. page is in relation to the current
  2002. page. You will learn more about
  2003. these on the pages 81-84.
  2004. If you look at the download
  2005. code for each chapter, you will
  2006. see that the index.html file
  2007. contains links that use relative
  2008. URLs.
  2009. Relative URLs help when building
  2010. a site on your computer because
  2011. you can create links between
  2012. pages without having to set up
  2013. your domain name or hosting.
  2014. <p>
  2015. <ul>
  2016. <li><a href="index.html">Home</a></li>
  2017. <li><a href="about-us.html">About</a></li>
  2018. <li><a href="movies.html">Movies</a></li>
  2019. <li><a href="contact.html">Contact</a></li>
  2020. </ul>
  2021. </p>
  2022. HTML chapter-04/linking-to-other-pages.html
  2023. Linking to Other Pages
  2024. on the Same Site
  2025. When linking to other pages
  2026. within the same site, you can
  2027. use relative URLs. These are like
  2028. a shorthand version of absolute
  2029. URLs because you do not need
  2030. to specify the domain name.
  2031. We will take a closer look at
  2032. relative URLs on pages 83-84
  2033. as there are several helpful
  2034. shortcuts you can use to write
  2035. links to other pages on your own
  2036. website.
  2037. Relative URLs
  2038. 81 LINKS
  2039. Structure
  2040. The diagram on the right shows
  2041. the directory structure for a
  2042. fictional entertainment listings
  2043. website called ExampleArts.
  2044. The top-level folder is known
  2045. as the root folder. (In this
  2046. example, the root folder is called
  2047. examplearts.) The root folder
  2048. contains all of the other files and
  2049. folders for a website.
  2050. Each section of the site is placed
  2051. in a separate folder; this helps
  2052. organize the files.
  2053. Relationships
  2054. The relationship between
  2055. files and folders on a website
  2056. is described using the same
  2057. terminology as a family tree.
  2058. In the diagram on the right, you
  2059. can see some relationships have
  2060. been drawn in.
  2061. The examplearts folder is a
  2062. parent of the movies, music
  2063. and theater folders. And the
  2064. the movies, music and theater
  2065. folders are children of the
  2066. examplearts folder.
  2067. Homepages
  2068. The main homepage of a site
  2069. written in HTML (and the
  2070. homepages of each section in a
  2071. child folder) is called index.html.
  2072. Web servers are usually set up
  2073. to return the index.html file if no
  2074. file name is specified.
  2075. Therefore, if you enter
  2076. examplearts.com it will return
  2077. examplearts.com/index
  2078. .html, and examplearts.com/
  2079. music will return examplearts
  2080. .com/music/index.html.
  2081. On larger websites it's a good idea to organize your code by placing the
  2082. pages for each different section of the site into a new folder. Folders on a
  2083. website are sometimes referred to as directories.
  2084. Directory Structure
  2085. If you are working with a content
  2086. management system, blogging
  2087. software, or an e-commerce
  2088. system, you might not have
  2089. individual files for each page of
  2090. the website.
  2091. Instead, these systems often
  2092. use one template file for each
  2093. different type of page (such as
  2094. news articles, blog posts, or
  2095. products).
  2096. Editing the template file would
  2097. change all of the pages that use
  2098. that template. Do not change
  2099. any code that is not HTML or
  2100. you may break the page.
  2101. LINKS 82
  2102. Every page and every image on
  2103. a website has a URL (or Uniform
  2104. Resource Locator). The URL is
  2105. made up of the domain name
  2106. followed by the path to that page
  2107. or image.
  2108. The path to the homepage of this
  2109. site is www.examplearts
  2110. .com/index.html. The path
  2111. to the logo for the site is
  2112. examplearts.com/images/
  2113. logo.gif.
  2114. You use URLs when linking
  2115. to other web pages and when
  2116. including images in your own
  2117. site. On the next page, you will
  2118. meet a shorthand way to link to
  2119. files on your own site.
  2120. The root folder contains:
  2121. ● A file called index.html which
  2122. is the homepage for the
  2123. entire site
  2124. ● Individual folders for the
  2125. movies, music and theatre
  2126. sections of the site
  2127. Each sub-directory contains:
  2128. ● A file called index.html which
  2129. is the homepage for that
  2130. section
  2131. ● A reviews page called reviews
  2132. .html
  2133. ● A listings page called listings
  2134. .html (except for the DVD
  2135. section)
  2136. The movies section contains:
  2137. ● A folder called cinema
  2138. ● A folder called DVD.
  2139. Grandparent
  2140. The examplearts folder is a
  2141. grandparent of the dvd folder.
  2142. Parent
  2143. The examplearts folder is a
  2144. parent of the music folder.
  2145. examplearts
  2146. index.html
  2147. images
  2148. logo.gif
  2149. movies
  2150. cinema
  2151. index.html
  2152. listings.html
  2153. reviews.html
  2154. dvd
  2155. index.html
  2156. reviews.html
  2157. index.html
  2158. music
  2159. index.html
  2160. listings.html
  2161. reviews.html
  2162. theater
  2163. index.html
  2164. listings.html
  2165. reviews.html
  2166. Child
  2167. The music folder is a child
  2168. of the examplearts folder.
  2169. Grandchild
  2170. The dvd folder is a grandchild
  2171. of the examplearts folder.
  2172. 83 LINKS
  2173. When you are linking to a page
  2174. on your own website, you do
  2175. not need to specify the domain
  2176. name. You can use relative URLs
  2177. which are a shorthand way to tell
  2178. the browser where a page is in
  2179. relation to the current page.
  2180. This is especially helpful when
  2181. creating a new website or
  2182. learning about HTML because
  2183. you can create links between
  2184. pages when they are only on
  2185. your personal computer (before
  2186. you have got a domain name and
  2187. uploaded them to the web).
  2188. Because you do not need to
  2189. repeat the domain name in each
  2190. link, they are also quicker to
  2191. write.
  2192. If all of the files in your site are
  2193. in one folder, you simply use the
  2194. file name for that page.
  2195. If your site is organized into
  2196. separate folders (or directories),
  2197. you need to tell the browser
  2198. how to get from the page it is
  2199. currently on to the page that you
  2200. are linking to.
  2201. If you link to the same page from
  2202. two different pages you might,
  2203. therefore, need to write two
  2204. different relative URLs.
  2205. These links make use of the
  2206. same terminology (borrowed
  2207. from that of family trees) you
  2208. met on the previous page which
  2209. introduces directory structure.
  2210. Relative URLs can be used when linking to pages within your own
  2211. website. They provide a shorthand way of telling the browser where to
  2212. find your files.
  2213. Relative URLs
  2214. LINKS 84
  2215. When a website is live (that
  2216. is, uploaded to a web server)
  2217. you may see a couple of other
  2218. techniques used that do not
  2219. work when the files are on your
  2220. local computer.
  2221. For example, you may see the
  2222. name of a child folder without
  2223. the name of a file. In this case
  2224. the web server will usually try
  2225. to show the homepage for that
  2226. section.
  2227. A forward slash will return the
  2228. homepage for the entire site,
  2229. and a forward slash followed
  2230. by a file name will return that
  2231. file providing it is in the root
  2232. directory.
  2233. Relative Link Type
  2234. Same Folder
  2235. To link to a file in the same folder, just use the file
  2236. name. (Nothing else is needed.)
  2237. Child Folder
  2238. For a child folder, use the name of the child folder,
  2239. followed by a forward slash, then the file name.
  2240. Grandchild Folder
  2241. Use the name of the child folder, followed by a
  2242. forward slash, then the name of the grandchild
  2243. folder, followed by another forward slash, then the
  2244. file name.
  2245. Parent Folder
  2246. Use ../ to indicate the folder above the current one,
  2247. then follow it with the file name.
  2248. GrandParent Folder
  2249. Repeat the ../ to indicate that you want to go up
  2250. two folders (rather than one), then follow it with the
  2251. file name.
  2252. example (from diagram on previous page)
  2253. To link to music reviews from the music homepage:
  2254. <a href="reviews.html">Reviews</a>
  2255. To link to music listings from the homepage:
  2256. <a href="music/listings.html">Listings</a>
  2257. To link to DVD reviews from the homepage:
  2258. <a href="movies/dvd/reviews.html">
  2259. Reviews</a>
  2260. To link to the homepage from the music reviews:
  2261. <a href="../index.html">Home</a>
  2262. To link to the homepage from the DVD reviews:
  2263. <a href="../../index.html">Home</a>
  2264. 85 LINKS
  2265. Result
  2266. <a href="mailto:jon@example.org">Email Jon</a>
  2267. mailto: chapter-04/email-links.html HTML
  2268. To create a link that starts up
  2269. the user's email program and
  2270. addresses an email to a specified
  2271. email address, you use the <a>
  2272. element. However, this time the
  2273. value of the href attribute starts
  2274. with mailto: and is followed by
  2275. the email address you want the
  2276. email to be sent to.
  2277. On the right you can see that
  2278. an email link looks just like any
  2279. other link but, when it is clicked
  2280. on, the user's email program
  2281. will open a new email message
  2282. and address it to the person
  2283. specified in the link.
  2284. Email Links
  2285. Article
  2286. LINKS 86
  2287. Result
  2288. <a href="http://www.imdb.com" target="_blank">
  2289. Internet Movie Database</a> (opens in new window)
  2290. HTML chapter-04/opening-links-in-a-new-window.html target
  2291. If you want a link to open in a
  2292. new window, you can use the
  2293. target attribute on the opening
  2294. <a> tag. The value of this
  2295. attribute should be _blank.
  2296. One of the most common
  2297. reasons a web page author
  2298. might want a link to be opened
  2299. in a new window is if it points to
  2300. another website. In such cases,
  2301. they hope the user will return
  2302. to the window containing their
  2303. site after finishing looking at the
  2304. other one.
  2305. Generally you should avoid
  2306. opening links in a new window,
  2307. but if you do, it is considered
  2308. good practice to inform users
  2309. that the link will open a new
  2310. window before they click on it.
  2311. Opening Links in
  2312. a New Window
  2313. 87 LINKS
  2314. <h1 id="top">Film-Making Terms</h1>
  2315. <a href="#arc_shot">Arc Shot</a><br />
  2316. <a href="#interlude">Interlude</a><br />
  2317. <a href="#prologue">Prologue</a><br /><br />
  2318. <h2 id="arc_shot">Arc Shot</h2>
  2319. <p>A shot in which the subject is photographed by an
  2320. encircling or moving camera</p>
  2321. <h2 id="interlude">Interlude</h2>
  2322. <p>A brief, intervening film scene or sequence, not
  2323. specifically tied to the plot, that appears
  2324. within a film</p>
  2325. <h2 id="prologue">Prologue</h2>
  2326. <p>A speech, preface, introduction, or brief scene
  2327. preceding the the main action or plot of a film;
  2328. contrast to epilogue</p>
  2329. <p><a href="#top">Top</a></p>
  2330. chapter-05/linking-to-a-specific-part.html HTML At the top of a long page
  2331. you might want to add a list
  2332. of contents that links to the
  2333. corresponding sections lower
  2334. down. Or you might want to add
  2335. a link from part way down the
  2336. page back to the top of it to save
  2337. users from having to scroll back
  2338. to the top.
  2339. Before you can link to a specific
  2340. part of a page, you need to
  2341. identify the points in the page
  2342. that the link will go to. You do
  2343. this using the id attribute (which
  2344. can be used on every HTML
  2345. element). You can see that the
  2346. <h1> and <h2> elements in this
  2347. example have been given id
  2348. attributes that identify those
  2349. sections of the page.
  2350. The value of the id attribute
  2351. should start with a letter or an
  2352. underscore (not a number or
  2353. any other character) and, on a
  2354. single page, no two id attributes
  2355. should have the same value.
  2356. To link to an element that uses
  2357. an id attribute you use the <a>
  2358. element again, but the value of
  2359. the href attribute starts with
  2360. the # symbol, followed by the
  2361. value of the id attribute of the
  2362. element you want to link to. In
  2363. this example, <a href="#top">
  2364. links to the <h1> element at
  2365. the top of the page whose id
  2366. attribute has a value of top.
  2367. Linking to a Specific
  2368. Part of the Same Page
  2369. Article
  2370. LINKS 88
  2371. Result If you want to link to a specific
  2372. part of a different page (whether
  2373. on your own site or a different
  2374. website) you can use a similar
  2375. technique.
  2376. As long as the page you are
  2377. linking to has id attributes that
  2378. identify specific parts of the
  2379. page, you can simply add the
  2380. same syntax to the end of the
  2381. link for that page.
  2382. Therefore, the href attribute
  2383. will contain the address for the
  2384. page (either an absolute URL or
  2385. a relative URL), followed by the
  2386. # symbol, followed by the value
  2387. of the id attribute that is used on
  2388. the element you are linking to.
  2389. For example, to link to the
  2390. bottom of the homepage of the
  2391. website that accompanies this
  2392. book, you would write:
  2393. <a href="http:/www.
  2394. htmlandcssbookcom/
  2395. #bottom">
  2396. Linking to a Specific
  2397. Part of Another Page
  2398. 89 LINKS
  2399. Example
  2400. LINKS
  2401. LINKS 90
  2402. This example is of a web page about film.
  2403. The <h1> element is used with an id attribute at the top of the page so
  2404. that a link can be added to take readers from the bottom of the page to
  2405. the top. There is an email link to allow readers to contact the author of
  2406. the web page. There are also a number of links to qualified URLs. These
  2407. link to various film festivals. Below this list is a link to a relative URL
  2408. which is an "about" page that lives in the same directory.
  2409. <html>
  2410. <head>
  2411. <title>Links</title>
  2412. </head>
  2413. <body>
  2414. <h1 id="top">Film Folk</h1>
  2415. <h2>Festival Diary</h2>
  2416. <p>Here are some of the film festivals we
  2417. will be attending this year.<br />Please
  2418. <a href="mailto:filmfolk@example.org">
  2419. contact us</a> if you would like more
  2420. information.</p>
  2421. <h3>January</h3>
  2422. <p><a href="http://www.sundance.org">
  2423. Sundance Film Festival</a><br />
  2424. Park City, Utah, USA<br />
  2425. 20 - 30 January 2011</p>
  2426. <h3>February</h3>
  2427. <p><a href="http://www.tropfest.com">
  2428. Tropfest</a><br />
  2429. Sydney, Australia<br />
  2430. 20 February 2011</p>
  2431. <!-- additional content -->
  2432. <p><a href="about.html">About Film Folk</a></p>
  2433. <p><a href="#top">Top of page</a></p>
  2434. </body>
  2435. </html>
  2436.  
  2437. Summary
  2438. LINKS
  2439. X Links are created using the <a> element.
  2440. X The <a> element uses the href attribute to indicate
  2441. the page you are linking to.
  2442. X If you are linking to a page within your own site, it is
  2443. best to use relative links rather than qualified URLs.
  2444. X You can create links to open email programs with an
  2445. email address in the "to" field.
  2446. X You can use the id attribute to target elements within
  2447. a page that can be linked to.
  2448.  
  2449. X How to add images to pages
  2450. X Choosing the right format
  2451. X Optimizing images for the web
  2452. Images
  2453. 5
  2454. 95 IMAGES
  2455. There are many reasons why you might
  2456. want to add an image to a web page: you
  2457. might want to include a logo, photograph,
  2458. illustration, diagram, or chart.
  2459. There are several things to consider when selecting and
  2460. preparing images for your site, but taking time to get them
  2461. right will make it look more attractive and professional.
  2462. In this chapter you will learn how to:
  2463. ● Include an image in your web pages using HTML
  2464. ● Pick which image format to use
  2465. ● Show an image at the right size
  2466. ● Optimize an image for use on the web to make pages
  2467. load faster
  2468. You can also use CSS to include images in your pages using the
  2469. background-image property, which you will meet on pages
  2470. 413-420.
  2471. IMAGES 96
  2472. 97 IMAGES
  2473. Images can be used to set the
  2474. tone for a site in less time than
  2475. it takes to read a description. If
  2476. you do not have photographs
  2477. to use on your website, there
  2478. are companies who sell stock
  2479. images; these are images you
  2480. pay to use (there is a list of stock
  2481. photography websites below).
  2482. Remember that all images are
  2483. subject to copyright, and you
  2484. can get in trouble for simply
  2485. taking photographs from
  2486. another website.
  2487. If you have a page that shows
  2488. several images (such as product
  2489. photographs or members of a
  2490. team) then putting them on a
  2491. simple, consistent background
  2492. helps them look better as
  2493. a group.
  2494. A picture can say a thousand words, and great
  2495. images help make the difference between an
  2496. average-looking site and a really engaging one.
  2497. Choosing Images for
  2498. Your Site
  2499. Images should...
  2500. Be relevant
  2501. Convey information
  2502. Convey the right mood
  2503. Be instantly recognisable
  2504. Fit the color palette
  2505. Stock photos
  2506. www.istockphoto.com
  2507. www.gettyimages.com
  2508. www.veer.com
  2509. www.sxc.hu
  2510. www.fotolia.com
  2511. Online extra
  2512. We have provided an online
  2513. gallery that helps you choose the
  2514. right image for your website. You
  2515. can find it in the tools section of
  2516. the site accompanying this book.
  2517. IMAGES 98
  2518. If you are building a site from scratch, it is good
  2519. practice to create a folder for all of the images
  2520. the site uses.
  2521. As a website grows, keeping
  2522. images in a separate folder
  2523. helps you understand how the
  2524. site is organized. Here you can
  2525. see an example of the files for
  2526. a website; all of the images are
  2527. stored in a folder called images.
  2528. On a big site you might like to
  2529. add subfolders inside the images
  2530. folder. For example, images such
  2531. as logos and buttons might sit in
  2532. a folder called interface, product
  2533. photographs might sit in a page
  2534. called products, and images
  2535. related to news might live in a
  2536. folder called news.
  2537. If you are using a content
  2538. management system or blogging
  2539. platform, there are usually tools
  2540. built into the admin site that
  2541. allow you to upload images,
  2542. and the program will probably
  2543. already have a separate folder
  2544. for image files and any
  2545. other uploads.
  2546. Storing Images on
  2547. Your Site
  2548. 99 IMAGES
  2549. Result
  2550. <img src="images/quokka.jpg" alt="A family of
  2551. quokka" title="The quokka is an Australian
  2552. marsupial that is similar in size to the
  2553. domestic cat." />
  2554. <img> chapter-05/adding-images.html HTML
  2555. To add an image into the page
  2556. you need to use an <img>
  2557. element. This is an empty
  2558. element (which means there is
  2559. no closing tag). It must carry the
  2560. following two attributes:
  2561. src
  2562. This tells the browser where
  2563. it can find the image file. This
  2564. will usually be a relative URL
  2565. pointing to an image on your
  2566. own site. (Here you can see that
  2567. the images are in a child folder
  2568. called images — relative URLs
  2569. were covered on pages 83-84).
  2570. alt
  2571. This provides a text description
  2572. of the image which describes the
  2573. image if you cannot see it.
  2574. title
  2575. You can also use the title
  2576. attribute with the <img> element
  2577. to provide additional information
  2578. about the image. Most browsers
  2579. will display the content of this
  2580. attribute in a tootip when the
  2581. user hovers over the image.
  2582. Adding Images
  2583. The text used in the alt attribute
  2584. is often referred to as alt text.
  2585. It should give an accurate
  2586. description of the image content
  2587. so it can be understood by
  2588. screen reader software (used by
  2589. people with visual impairments)
  2590. and search engines.
  2591. If the image is just to make a
  2592. page look more attractive (and
  2593. it has no meaning, such as a
  2594. graphic dividing line), then the
  2595. alt attribute should still be used
  2596. but the quotes should be left
  2597. empty.
  2598. Article
  2599. IMAGES 100
  2600. Result
  2601. You will also often see an <img>
  2602. element use two other attributes
  2603. that specify its size:
  2604. height
  2605. This specifies the height of the
  2606. image in pixels.
  2607. width
  2608. This specifies the width of the
  2609. image in pixels.
  2610. Images often take longer to
  2611. load than the HTML code that
  2612. makes up the rest of the page.
  2613. It is, therefore, a good idea to
  2614. specify the size of the image
  2615. so that the browser can render
  2616. the rest of the text on the page
  2617. while leaving the right amount of
  2618. space for the image that is still
  2619. loading.
  2620. The size of images is increasingly
  2621. being specified using CSS rather
  2622. than HTML — see pages 409-
  2623. 410 for more information about
  2624. this.
  2625. <img src="images/quokka.jpg" alt="A family of
  2626. quokka" width="600" height="450" />
  2627. HTML chapter-05/height-and-width-of-images.html
  2628. Height & Width
  2629. of Images
  2630. 101 IMAGES
  2631. <img src="images/bird.gif" alt="Bird" width="100"
  2632. height="100" />
  2633. <p>There are around 10,000 living species of birds
  2634. that inhabit different ecosystems from the
  2635. Arctic to the Antarctic. Many species undertake
  2636. long distance annual migrations, and many more
  2637. perform shorter irregular journeys.</p>
  2638. <hr />
  2639. <p><img src="images/bird.gif" alt="Bird" width="100"
  2640. height="100" />There are around 10,000 living
  2641. species of birds that inhabit different
  2642. ecosystems from the Arctic to the Antarctic. Many
  2643. species undertake long distance annual
  2644. migrations, and many more perform shorter
  2645. irregular journeys.</p>
  2646. <hr />
  2647. <p>There are around 10,000 living species of birds
  2648. that inhabit different ecosystems from the
  2649. Arctic to the Antarctic.<img
  2650. src="images/bird.gif" alt="Bird" width="100"
  2651. height="100" />Many species undertake long
  2652. distance annual migrations, and many more perform
  2653. shorter irregular journeys.</p>
  2654. chapter-05/where-to-place-images.html HTML Where an image is placed
  2655. in the code will affect how it
  2656. is displayed. Here are three
  2657. examples of image placement
  2658. that produce different results:
  2659. 1: before a paragraph
  2660. The paragraph starts on a new
  2661. line after the image.
  2662. 2: inside the start of a
  2663. paragraph
  2664. The first row of text aligns with
  2665. the bottom of the image.
  2666. 3: in the middle of a
  2667. paragraph
  2668. The image is placed between the
  2669. words of the paragraph that it
  2670. appears in.
  2671. Where to Place Images
  2672. in Your Code
  2673. Article
  2674. IMAGES 102
  2675. Result Where you place the image in
  2676. the code is important because
  2677. browsers show HTML elements
  2678. in one of two ways:
  2679. Block elements always appear
  2680. on a new line. Examples of block
  2681. elements include the <h1> and
  2682. <p> elements.
  2683. If the <img> is followed by a
  2684. block level element (such as a
  2685. paragraph) then the block level
  2686. element will sit on a new line
  2687. after the imageas shown in the
  2688. first example on this page.
  2689. Inline elements sit within a
  2690. block level element and do not
  2691. start on a new line. Examples of
  2692. inline elements include the <b>,
  2693. <em>, and <img> elements.
  2694. If the <img> element is inside a
  2695. block level element, any text or
  2696. other inline elements will flow
  2697. around the image as shown in
  2698. the second and third examples
  2699. on this page.
  2700. Block and inline elements are
  2701. discussed in greater depth on
  2702. pages 185-186.
  2703. 103 IMAGES
  2704. <p><img src="images/bird.gif" alt="Bird" width="100"
  2705. height="100" align="left" />There are around
  2706. 10,000 living species of birds that inhabit
  2707. different ecosystems from the Arctic to the
  2708. Antarctic. Many species undertake long distance
  2709. annual migrations, and many more perform shorter
  2710. irregular journeys.</p>
  2711. <hr />
  2712. <p><img src="images/bird.gif" alt="Bird" width="100"
  2713. height="100" align="right" />There are around
  2714. 10,000 living species of birds that inhabit
  2715. different ecosystems from the Arctic to the
  2716. Antarctic. Many species undertake long distance
  2717. annual migrations, and many more perform shorter
  2718. irregular journeys.</p>
  2719. align chapter-05/aligning-images-horizontally.html HTML
  2720. The align attribute was
  2721. commonly used to indicate how
  2722. the other parts of a page should
  2723. flow around an image. It has
  2724. been removed from HTML5
  2725. and new websites should use
  2726. CSS to control the alignment of
  2727. images (as you will see on pages
  2728. 411-412).
  2729. I have discussed it here because
  2730. you are likely to come across
  2731. it if you look at older code, and
  2732. because some visual editors still
  2733. insert this attribute when you
  2734. indicate how an image should be
  2735. aligned.
  2736. The align attribute can take
  2737. these horizontal values:
  2738. left
  2739. This aligns the image to the left
  2740. (allowing text to flow around its
  2741. right-hand side).
  2742. right
  2743. This aligns the image to the right
  2744. (allowing text to flow around its
  2745. left-hand side).
  2746. Old Code: Aligning
  2747. Images Horizontally
  2748. Article
  2749. IMAGES 104
  2750. Result
  2751. This looks a lot neater than
  2752. having one line of text next to
  2753. the image (as shown on the
  2754. previous example).
  2755. When you give the align
  2756. attribute a value of left, the
  2757. image is placed on the left and
  2758. text flows around it.
  2759. When you give the align
  2760. attribute a value of right, the
  2761. image is placed on the right and
  2762. the text flows around it.
  2763. When text flows right up to the
  2764. edge of an image it can make
  2765. it harder to read. You will learn
  2766. how to add a gap between text
  2767. and images on pages 313-314
  2768. using the CSS padding and
  2769. margin properties.
  2770. 105 IMAGES
  2771. <p><img src="images/bird.gif" alt="Bird" width="100"
  2772. height="100" align="top" />There are around
  2773. 10,000 living species of birds that inhabit
  2774. different ecosystems from the Arctic to the
  2775. Antarctic. Many species undertake long distance
  2776. annual migrations, and many more perform shorter
  2777. irregular journeys.</p>
  2778. <hr />
  2779. <p><img src="images/bird.gif" alt="Bird" width="100"
  2780. height="100" align="middle" />There are around
  2781. 10,000 living species of birds that inhabit
  2782. different ecosystems from the Arctic to the
  2783. Antarctic. Many species undertake long distance
  2784. annual migrations, and many more perform shorter
  2785. irregular journeys.</p>
  2786. <hr />
  2787. <p><img src="images/bird.gif" alt="Bird" width="100"
  2788. height="100" align="bottom" />There are around
  2789. 10,000 living species of birds that inhabit
  2790. different ecosystems from the Arctic to the
  2791. Antarctic. Many species undertake long distance
  2792. annual migrations, and many more perform shorter
  2793. irregular journeys.</p>
  2794. chapter-05/aligning-images-vertically.html HTML As you saw on the last page, the
  2795. align attribute is no longer used
  2796. in HTML5, but it is covered here
  2797. because you may see it used in
  2798. older websites and it is still used
  2799. in the code created by some
  2800. visual editors.
  2801. You can see how to use CSS
  2802. to achieve the same effects on
  2803. pages 285-286.
  2804. There are three values that the
  2805. align attribute can take that
  2806. control how the image should
  2807. align vertically with the text that
  2808. surrounds it:
  2809. top
  2810. This aligns the first line of the
  2811. surrounding text with the top of
  2812. the image.
  2813. middle
  2814. This aligns the first line of the
  2815. surrounding text with the middle
  2816. of the image.
  2817. bottom
  2818. This aligns the first line of the
  2819. surrounding text with the bottom
  2820. of the image.
  2821. Old Code: Aligning
  2822. Images Vertically
  2823. Article
  2824. IMAGES 106
  2825. The value of top places the first
  2826. line of text near the top of the
  2827. image and subsequent lines of
  2828. text appear under the image.
  2829. The value of middle places
  2830. the first line of text near the
  2831. vertical middle of the image and
  2832. subsequent lines of text appear
  2833. under the image.
  2834. The value of bottom places the
  2835. first line of text near the bottom
  2836. of the image and subsequent
  2837. lines of text under the image.
  2838. When text flows right up to the
  2839. edge of an image it can make
  2840. it harder to read. You will learn
  2841. how to add a gap between text
  2842. and images on pages 313-314
  2843. using the CSS padding and
  2844. margin properties.
  2845. If you would like all of the text
  2846. to wrap arond the image (rather
  2847. than just one line of text), you
  2848. should use the CSS float
  2849. property discussed on pages
  2850. 370-372.
  2851. In older code, you may see the
  2852. align attribute used with the
  2853. values left or right to achieve
  2854. the same effect (as described on
  2855. the previous page), although its
  2856. use is no longer recommended.
  2857. Result
  2858. 107 IMAGES
  2859. Three Rules for
  2860. Creating Images
  2861. There are three rules to remember when you
  2862. are creating images for your website which are
  2863. summarized below. We go into greater detail
  2864. on each topic over the next nine pages.
  2865. 1
  2866. Save images in
  2867. the right format
  2868. Websites mainly use images in
  2869. jpeg, gif, or png format. If you
  2870. choose the wrong image
  2871. format then your image might
  2872. not look as sharp as it should
  2873. and can make the web page
  2874. slower to load.
  2875. 2
  2876. Save images at
  2877. the right size
  2878. You should save the image at
  2879. the same width and height it will
  2880. appear on the website. If
  2881. the image is smaller than the
  2882. width or height that you have
  2883. specified, the image can be
  2884. distorted and stretched. If the
  2885. image is larger than the width
  2886. and height if you have specified,
  2887. the image will take longer to
  2888. display on the page.
  2889. 3
  2890. Use the correct
  2891. resolution
  2892. Computer screens are made up
  2893. of dots known as pixels. Images
  2894. used on the web are also made
  2895. up of tiny dots. Resolution refers
  2896. to the number of dots per inch,
  2897. and most computer screens only
  2898. show web pages at 72 pixels
  2899. per inch. So saving images at
  2900. a higher resolution results in
  2901. images that are larger than
  2902. necessary and take longer to
  2903. download.
  2904. IMAGES 108
  2905. Tools to Edit
  2906. & Save Images
  2907. The most popular tool amongst
  2908. web professionals is Adobe
  2909. Photoshop. (In fact, professional
  2910. web designers often use this
  2911. software to design entire sites.)
  2912. The full version of Photoshop is
  2913. expensive, but there is a cheaper
  2914. version called Photoshop
  2915. Elements which would suit the
  2916. needs of most beginners.
  2917. Other Software
  2918. Adobe Fireworks
  2919. Pixelmator
  2920. PaintShop Pro
  2921. Paint.net
  2922. Online Editors
  2923. www.photoshop.com
  2924. www.pixlr.com
  2925. www.splashup.com
  2926. www.ipiccy.com
  2927. Online extra
  2928. Watch videos that demonstrate
  2929. how to resize images and save
  2930. them in the correct format using
  2931. both of these applications.
  2932. There are several tools you can use to edit and
  2933. save images to ensure that they are the right
  2934. size, format, and resolution.
  2935. Whenever you have many different
  2936. colors in a picture you should use a JPEG.
  2937. A photograph that features snow or an
  2938. overcast sky might look like it has large
  2939. areas that are just white or gray, but the
  2940. picture is usually made up of many different
  2941. colors that are subtly different.
  2942. Image Formats: JPEG
  2943.  
  2944. BU
  2945. LI D
  2946. ED GI S N
  2947. CONCEPT
  2948. RESEARCH
  2949. TEST
  2950. Image Formats: GIF
  2951. When a picture has an area that is filled
  2952. with exactly the same color, it is known as
  2953. flat color. Logos, illustrations, and diagrams
  2954. often use flat colors. (Note that photographs
  2955. of snow, sky, or grass are not flat colors,
  2956. they are made up of many subtly different
  2957. shades of the same color and are not as
  2958. suited to GIF or PNG format.)
  2959. Use GIF or PNG format
  2960. when saving images
  2961. with few colors or large
  2962. areas of the same color.
  2963. 113 IMAGES
  2964. For example, if you have
  2965. designed a page to include an
  2966. image that is 300 pixels wide by
  2967. 150 pixels tall, the image you use
  2968. should be 300 x 150 pixels. You
  2969. may need to use image editing
  2970. tools to resize and crop the
  2971. image. When sourcing images, it
  2972. is important to understand how
  2973. you can alter the dimensions of
  2974. an image; imagine that you had
  2975. designed a web page to include
  2976. an image that is 300 pixels wide
  2977. by 150 pixels tall:
  2978. The images you use on your website should be
  2979. saved at the same width and height that you
  2980. want them to appear on the page.
  2981. Image Dimensions
  2982. REDUCING IMAGE SIZE
  2983. You can reduce the size of
  2984. images to create a smaller
  2985. version of the image.
  2986. Example: If your image is 600
  2987. pixels wide and 300 pixels tall,
  2988. you can reduce the size of the
  2989. image by 50%.
  2990. Result: This will create an image
  2991. that is quicker to download.
  2992. INCREASING IMAGE SIZE
  2993. You can't increase the size of
  2994. photos significantly without
  2995. affecting the image quality.
  2996. Example: If your image is only
  2997. 100 pixels wide by 50 pixels tall,
  2998. increasing the size by 300%
  2999. would result in poor quality.
  3000. Result: The image will look
  3001. blurry or blocky.
  3002. CHANGING SHAPE
  3003. Only some images can be
  3004. cropped without losing valuable
  3005. information (see next page).
  3006. Example: If your image is 300
  3007. pixels square, you can remove
  3008. parts of it, but in doing so you
  3009. might lose valuable information.
  3010. Result: Only some images can
  3011. be cropped and still make sense.
  3012. Online extra
  3013. Visit the tools section of the
  3014. website accompanying this
  3015. book to watch a video guide to
  3016. resizing images in Photoshop
  3017. and GIMP.
  3018. IMAGES 114
  3019. When cropping images it is important not to
  3020. lose valuable information. It is best to source
  3021. images that are the correct shape if possible.
  3022. Cropping Images
  3023. Here you can see an illustration
  3024. of an elephant that is best suited
  3025. to appearing in landscape.
  3026. LANDSCAPE PORTRAIT
  3027. If we crop this illustration to
  3028. make it portrait we lose the trunk
  3029. and the hindquarters.
  3030. If we add extra space to the top
  3031. and bottom of the illustration the
  3032. background is not continued.
  3033. PORTRAIT LANDSCAPE
  3034. Here you can see an illustration
  3035. of a giraffe that is best suited to
  3036. appearing in portrait.
  3037. If we crop this illustration to
  3038. make it landscape we lose the
  3039. head and feet.
  3040. If we add extra space to the left
  3041. and right of the illustration the
  3042. background is not continued.
  3043. 115 IMAGES
  3044. Images created for the web should be saved at
  3045. a resolution of 72 ppi. The higher the resolution
  3046. of the image, the larger the size of the file.
  3047. Image Resolution
  3048. JPGs, GIFs, and PNGs belong to
  3049. a type of image format known
  3050. as bitmap. They are made up of
  3051. lots of miniature squares. The
  3052. resolution of an image is the
  3053. number of squares that fit within
  3054. a 1 inch x 1 inch square area.
  3055. Images appearing on computer
  3056. screens are made of tiny squares
  3057. called pixels. A small segment
  3058. of this photograph has been
  3059. magnified to show how it is
  3060. made up of pixels. The web
  3061. browsers on most desktop
  3062. computers display images at a
  3063. resolution of 72 pixels per inch
  3064. (ppi). Images in print materials
  3065. (such as books and magazines)
  3066. are made up of tiny circles called
  3067. dots. These images are usually
  3068. printed at a resolution of 300
  3069. dots per inch (dpi).
  3070. For this image:
  3071. JPEG at 300 dpi = 1,526kb
  3072. JPEG at 72 ppi = 368kb
  3073. Due to the fact that computer
  3074. displays are capped at a
  3075. resolution of 72 ppi, using
  3076. images on the web with a higher
  3077. resolution will not result in better
  3078. image quality — only in larger
  3079. file sizes, which will increase the
  3080. time needed to load them and
  3081. therefore slow down viewing of
  3082. your web pages.
  3083. IMAGES 116
  3084. When an image is a line drawing
  3085. (such as a logo, illustration, or
  3086. diagram), designers will often
  3087. create it in vector format.
  3088. Vector formatted images are
  3089. very different to bitmap images.
  3090. Vector images are created by
  3091. placing points on a grid, and
  3092. drawing lines between those
  3093. points. A color can then be
  3094. added to "fill in" the lines that
  3095. have been created.
  3096. The advantage of creating line
  3097. drawings in vector format is that
  3098. you can increase the dimensions
  3099. of the image without affecting
  3100. the quality of it.
  3101. Vector images differ from bitmap images and
  3102. are resolution-independent. Vector images are
  3103. commonly created in programs such as Adobe
  3104. Illustrator.
  3105. Vector Images
  3106. The current method of using
  3107. vector images for display on
  3108. websites involves saving a
  3109. bitmap version of the original
  3110. vector image and using that.
  3111. Scalable Vector Graphics (SVG)
  3112. are a relatively new format used
  3113. to display vector images directly
  3114. on the web (eliminating the need
  3115. to create bitmap versions of
  3116. them), however its use is not yet
  3117. widespread.
  3118. 117 IMAGES
  3119. Below you can see the individual
  3120. frames that make up an
  3121. animated GIF that shows an
  3122. orange dot revolving around
  3123. a circle — like the kind of
  3124. animation you might see when a
  3125. web page is loading.
  3126. Some image editing applications
  3127. such as Adobe Photoshop allow
  3128. you to create animated GIFs.
  3129. There are several tutorials about
  3130. how to do this on the web. There
  3131. are also several websites that
  3132. allow you to upload the graphics
  3133. for the individual frames and
  3134. create the animated GIF for you.
  3135. It is important to
  3136. remember:
  3137. Each extra frame of the image
  3138. increases the size of the file, and
  3139. can therefore add to the time it
  3140. takes for an image to download
  3141. (and web users do not like
  3142. waiting a long time for images to
  3143. download).
  3144. Because GIFs are not an
  3145. ideal format for displaying
  3146. photographs, animated GIFs are
  3147. really only suitable for simple
  3148. illustrations.
  3149. Some designers frown on
  3150. animated GIFs because they
  3151. remember a lot of amateur web
  3152. designers overusing them in the
  3153. 1990's.
  3154. Animated GIFs show several frames of an
  3155. image in sequence and therefore can be used to
  3156. create simple animations.
  3157. Animated GIFs
  3158. 1 2 3 4 5 6 7 8
  3159. IMAGES 118
  3160. Creating an image that is partially transparent
  3161. (or "see-through") for the web involves
  3162. selecting one of two formats:
  3163. Transparency
  3164. PNG
  3165. If the transparent part of the
  3166. image has diagonal or rounded
  3167. edges or if you want a semiopaque
  3168. transparency or a dropshadow,
  3169. then you will need to
  3170. save it as a PNG.
  3171. Transparent PNGs are not fully
  3172. supported in older browsers,
  3173. most notably Internet Explorer 6
  3174. (IE6). There is some JavaScript
  3175. you can use to get around this
  3176. issue. The details of this script
  3177. can be found in the tools section
  3178. of the website accompanying
  3179. this book.
  3180. Straight Diagonal Round Semi-Opaque Drop-Shadow
  3181. Transparent GIF
  3182. If the transparent part of the
  3183. image has straight edges and
  3184. it is 100% transparent (that is,
  3185. not semi-opaque), you can save
  3186. the image as a GIF (with the
  3187. transparency option selected).
  3188. 119 IMAGES
  3189. Examining Images
  3190. on the Web
  3191. Checking the Size of Images
  3192. If you are updating a website, you might need to check the size of an
  3193. existing image before creating a new one to replace it. This can be
  3194. achieved by right-clicking on the image and making a selection from
  3195. the pop-up menu that appears. (Mac users will need to hold down the
  3196. control key and click rather than right-click.)
  3197. Downloading Images
  3198. If you want to download images from a website, you can do so by
  3199. accessing the same pop-up menu. (Please remember however that all
  3200. images online are subject to copyright and require explicit permission to
  3201. reuse.)
  3202. On the left you can see how to
  3203. check the size of images and
  3204. how to download them using
  3205. Safari. Below is a brief overview
  3206. of what to select in the pop-up
  3207. menu to perform these functions
  3208. in various browsers.
  3209. CHROME
  3210. Size: Open Image in New Tab
  3211. Size appears in new tab
  3212. Download: Save Image As
  3213. FIREFOX
  3214. Size: View Image Info
  3215. Size appears in pop-up window
  3216. Download: Save Image As
  3217. Internet Explorer
  3218. Size: Properties
  3219. Size appears in pop-up window
  3220. Download: Save Image
  3221. SAFARI
  3222. Size: Open Image in New Tab
  3223. Size appears in title bar
  3224. Download: Save Image As
  3225. Article
  3226. IMAGES 120
  3227. Result
  3228. <figure>
  3229. <img src="images/otters.jpg" alt="Photograph of
  3230. two sea otters floating in water">
  3231. <br />
  3232. <figcaption>Sea otters hold hands when they
  3233. sleep so they don't drift away from each
  3234. other.</figcaption>
  3235. </figure>
  3236. HTML chapter-05/figure-and-figure-caption.html <figure>
  3237. Images often come with
  3238. captions. HTML5 has introduced
  3239. a new <figure> element to
  3240. contain images and their caption
  3241. so that the two are associated.
  3242. You can have more than one
  3243. image inside the <figure>
  3244. element as long as they all share
  3245. the same caption.
  3246. <figcaption>
  3247. The <figcaption> element has
  3248. been added to HTML5 in order
  3249. to allow web page authors to add
  3250. a caption to an image.
  3251. Before these elements were
  3252. created there was no way to
  3253. associate an <img> element with
  3254. its caption.
  3255. Older browsers that do not
  3256. understand HTML5 elements
  3257. simply ignore the new elements
  3258. and display the content of them.
  3259. HTML5: Figure and
  3260. Figure Caption
  3261. In this example, the logo is a GIF
  3262. because it uses flat colors, while
  3263. the photographs are JPEGs. The
  3264. main photo is placed inside the
  3265. HTML5 <figure> element and
  3266. has its own caption.
  3267. The alt attribute on each
  3268. image provides a description
  3269. for those using screen readers
  3270. and the title attribute provides
  3271. additional information. (This is
  3272. shown in the tooltip.)
  3273. This example does not
  3274. use the height, width, or
  3275. align attributes as these are
  3276. being phased out and you
  3277. are encouraged to use CSS
  3278. properties instead.
  3279. 121 IMAGES
  3280. Example
  3281. IMAGES
  3282. IMAGES 122
  3283. <html>
  3284. <head>
  3285. <title>Images</title>
  3286. </head>
  3287. <body>
  3288. <h1>
  3289. <img src="images/logo.gif"
  3290. alt="From A to Zucchini" />
  3291. </h1>
  3292. <figure>
  3293. <img src="images/chocolate-islands.jpg"
  3294. alt="Chocolate Islands"
  3295. title="Chocolate Islands Individual Cakes" />
  3296. <p>
  3297. <figcaption>
  3298. This recipe for individual chocolate
  3299. cakes is so simple and so delectable!
  3300. </figcaption>
  3301. </p>
  3302. </figure>
  3303. <h4>More Recipes:</h4>
  3304. <p>
  3305. <img src="images/lemon-posset.jpg"
  3306. alt="Lemon Posset"
  3307. title="Lemon Posset Dessert" />
  3308. <img src="images/roasted-brussel-sprouts.jpg"
  3309. alt="Roasted Brussel Sprouts"
  3310. title="Roasted Brussel Sprouts Side Dish" />
  3311. <img src="images/zucchini-cake.jpg"
  3312. alt="Zucchini Cake"
  3313. title="Zucchini Cake No Frosting" />
  3314. </p>
  3315. </body>
  3316. </html>
  3317.  
  3318. Summary
  3319. IMAGES
  3320. X The <img> element is used to add images to a
  3321. web page.
  3322. X You must always specify a src attribute to indicate the
  3323. source of an image and an alt attribute to describe the
  3324. content of an image.
  3325. X You should save images at the size you will be using
  3326. them on the web page and in the appropriate format.
  3327. X Photographs are best saved as JPEGs; illustrations or
  3328. logos that use flat colors are better saved as GIFs.
  3329.  
  3330. X How to create tables
  3331. X What information suits tables
  3332. X How to represent complex data in tables
  3333. Tables
  3334. 6
  3335. 127 TABLES
  3336. There are several types of information
  3337. that need to be displayed in a grid or
  3338. table. For example: sports results, stock
  3339. reports, train timetables.
  3340. When representing information in a table, you need to think
  3341. in terms of a grid made up of rows and columns (a bit like a
  3342. spreadsheet). In this chapter you will learn how to:
  3343. ● Use the four key elements for creating tables
  3344. ● Represent complex data using tables
  3345. ● Add captions to tables
  3346. TABLES 128
  3347. 129 TABLES
  3348. TABLES 130
  3349. Grids allow us to understand
  3350. complex data by referencing
  3351. information on two axes.
  3352. Each block in the grid is referred
  3353. to as a table cell. In HTML a
  3354. table is written out row by row.
  3355. A table represents information in a grid format.
  3356. Examples of tables include financial reports, TV
  3357. schedules, and sports results.
  3358. What's a Table?
  3359. 131 TABLES
  3360. Result
  3361. <table>
  3362. The <table> element is used
  3363. to create a table. The contents
  3364. of the table are written out row
  3365. by row.
  3366. <tr>
  3367. You indicate the start of each
  3368. row using the opening <tr> tag.
  3369. (The tr stands for table row.)
  3370. It is followed by one or more
  3371. <td> elements (one for each cell
  3372. in that row).
  3373. At the end of the row you use a
  3374. closing </tr> tag.
  3375. <td>
  3376. Each cell of a table is
  3377. represented using a <td>
  3378. element. (The td stands for
  3379. table data.)
  3380. At the end of each cell you use a
  3381. closing </td> tag.
  3382. Some browsers automatically
  3383. draw lines around the table
  3384. and/or the individual cells. You
  3385. will learn how to control the
  3386. borders of tables using CSS on
  3387. pages 309-312 and 337-340.
  3388. <table>
  3389. <tr>
  3390. <td>15</td>
  3391. <td>15</td>
  3392. <td>30</td>
  3393. </tr>
  3394. <tr>
  3395. <td>45</td>
  3396. <td>60</td>
  3397. <td>45</td>
  3398. </tr>
  3399. <tr>
  3400. <td>60</td>
  3401. <td>90</td>
  3402. <td>90</td>
  3403. </tr>
  3404. </table>
  3405. chapter-06/basic-table-structure.html HTML
  3406. Basic Table Structure
  3407. Article
  3408. TABLES 132
  3409. Result
  3410. <th>
  3411. The <th> element is used just
  3412. like the <td> element but its
  3413. purpose is to represent the
  3414. heading for either a column or
  3415. a row. (The th stands for table
  3416. heading.)
  3417. Even if a cell has no content,
  3418. you should still use a <td> or
  3419. <th> element to represent
  3420. the presence of an empty cell
  3421. otherwise the table will not
  3422. render correctly. (The first cell
  3423. in the first row of this example
  3424. shows an empty cell.)
  3425. Using <th> elements for
  3426. headings helps people who
  3427. use screen readers, improves
  3428. the ability for search engines
  3429. to index your pages, and also
  3430. enables you to control the
  3431. appearance of tables better
  3432. when you start to use CSS.
  3433. You can use the scope attribute
  3434. on the <th> element to indicate
  3435. whether it is a heading for a
  3436. column or a row. It can take the
  3437. values: row to indicate a heading
  3438. for a row or col to indicate a
  3439. heading for a column.
  3440. Browsers usually display the
  3441. content of a <th> element in
  3442. bold and in the middle of the cell.
  3443. <table>
  3444. <tr>
  3445. <th></th>
  3446. <th scope="col">Saturday</th>
  3447. <th scope="col">Sunday</th>
  3448. </tr>
  3449. <tr>
  3450. <th scope="row">Tickets sold:</th>
  3451. <td>120</td>
  3452. <td>135</td>
  3453. </tr>
  3454. <tr>
  3455. <th scope="row">Total sales:</th>
  3456. <td>$600</td>
  3457. <td>$675</td>
  3458. </tr>
  3459. </table>
  3460. HTML chapter-06/table-headings.html
  3461. Table Headings
  3462. 133 TABLES
  3463. Sometimes you may need the
  3464. entries in a table to stretch
  3465. across more than one column.
  3466. The colspan attribute can be
  3467. used on a <th> or <td> element
  3468. and indicates how many columns
  3469. that cell should run across.
  3470. In the example on the right
  3471. you can see a timetable with
  3472. five columns; the first column
  3473. contains the heading for that
  3474. row (the day), the remaining four
  3475. represent one hour time slots.
  3476. If you look at the table cell that
  3477. contains the words 'Geography'
  3478. you will see that the value of the
  3479. colspan attribute is 2, which
  3480. indicates that the cell should run
  3481. across two columns. In the third
  3482. row, 'Gym' runs across three
  3483. columns.
  3484. You can see that the second
  3485. and third rows have fewer
  3486. <td> elements than there are
  3487. columns. This is because, when
  3488. a cell extends across more than
  3489. one column, the <td> or <th>
  3490. cells that would have been in the
  3491. place of the wider cells are not
  3492. included in the code.
  3493. I added some CSS styles to this
  3494. example so that you can see how
  3495. the cells span more than one
  3496. column. You will learn how to do
  3497. this on pages 250, 337-340.
  3498. Result
  3499. <table>
  3500. <tr>
  3501. <th></th>
  3502. <th>9am</th>
  3503. <th>10am</th>
  3504. <th>11am</th>
  3505. <th>12am</th>
  3506. </tr>
  3507. <tr>
  3508. <th>Monday</th>
  3509. <td colspan="2">Geography</td>
  3510. <td>Math</td>
  3511. <td>Art</td>
  3512. </tr>
  3513. <tr>
  3514. <th>Tuesday</th>
  3515. <td colspan="3">Gym</td>
  3516. <td>Home Ec</td>
  3517. </tr>
  3518. </table>
  3519. chapter-06/spanning-columns.html HTML
  3520. Spanning ColumnS
  3521. Article
  3522. TABLES 134
  3523. You may also need entries in
  3524. a table to stretch down across
  3525. more than one row.
  3526. The rowspan attribute can be
  3527. used on a <th> or <td> element
  3528. to indicate how many rows a cell
  3529. should span down the table.
  3530. In the example on the left you
  3531. can see that ABC is showing a
  3532. movie from 6pm - 8pm, whereas
  3533. the BBC and CNN channels are
  3534. both showing two programs
  3535. during this time period (each of
  3536. which lasts one hour).
  3537. If you look at the last <tr>
  3538. element, it only contains three
  3539. elements even though there are
  3540. four columns in the result below.
  3541. This is because the movie in the
  3542. <tr> element above it uses the
  3543. rowspan attribute to stretch
  3544. down and take over the cell
  3545. below.
  3546. I have added some CSS styles to
  3547. this example so that you can see
  3548. how the cells span more than
  3549. one row. You will learn how to
  3550. apply these CSS styles to tables
  3551. on pages 250, 337-340.
  3552. Result
  3553. <table>
  3554. <tr>
  3555. <th></th>
  3556. <th>ABC</th>
  3557. <th>BBC</th>
  3558. <th>CNN</th>
  3559. </tr>
  3560. <tr>
  3561. <th>6pm - 7pm</th>
  3562. <td rowspan="2">Movie</td>
  3563. <td>Comedy</td>
  3564. <td>News</td>
  3565. </tr>
  3566. <tr>
  3567. <th>7pm - 8pm</th>
  3568. <td>Sport</td>
  3569. <td>Current Affairs</td>
  3570. </tr>
  3571. </table>
  3572. HTML chapter-06/spanning-rows.html
  3573. Spanning Rows
  3574. 135 TABLES
  3575. There are three elements that
  3576. help distinguish between the
  3577. main content of the table and
  3578. the first and last rows (which can
  3579. contain different content).
  3580. These elements help people
  3581. who use screen readers and also
  3582. allow you to style these sections
  3583. in a different manner than the
  3584. rest of the table (as you will see
  3585. when you learn about CSS).
  3586. <thead>
  3587. The headings of the table should
  3588. sit inside the <thead> element.
  3589. <tbody>
  3590. The body should sit inside the
  3591. <tbody> element.
  3592. <tfoot>
  3593. The footer belongs inside the
  3594. <tfoot> element.
  3595. By default, browsers rarely treat
  3596. the content of these elements
  3597. any differently than other
  3598. elements however designers
  3599. often use CSS styles to change
  3600. their appearance.
  3601. <table>
  3602. <thead>
  3603. <tr>
  3604. <th>Date</th>
  3605. <th>Income</th>
  3606. <th>Expenditure</th>
  3607. </tr>
  3608. </thead>
  3609. <tbody>
  3610. <tr>
  3611. <th>1st January</th>
  3612. <td>250</td>
  3613. <td>36</td>
  3614. </tr>
  3615. <tr>
  3616. <th>2nd January</th>
  3617. <td>285</td>
  3618. <td>48</td>
  3619. </tr>
  3620. <!-- additional rows as above -->
  3621. <tr>
  3622. <th>31st January</th>
  3623. <td>129</td>
  3624. <td>64</td>
  3625. </tr>
  3626. </tbody>
  3627. <tfoot>
  3628. <tr>
  3629. <td></td>
  3630. <td>7824</td>
  3631. <td>1241</td>
  3632. </tr>
  3633. </tfoot>
  3634. </table>
  3635. chapter-06/long-tables.html HTML
  3636. Long Tables
  3637. A
  3638. r
  3639. ticle
  3640. TABLES 136
  3641. Result
  3642. Some of the HTML editors that
  3643. come in content management
  3644. systems offer tools to help
  3645. draw tables. If the first row of
  3646. your table only contains <th>
  3647. elements then you may find that
  3648. the editor inserts a <thead>
  3649. element automatically.
  3650. Part of the reason for having
  3651. separate <thead> and <tfoot>
  3652. elements is so that, if you have
  3653. a table that is taller than the
  3654. screen (or, if printed, longer than
  3655. one page) then the browser
  3656. can keep the header and footer
  3657. visible whilst the contents of
  3658. the table scroll. This is intended
  3659. to make it easier for users to
  3660. see which column the data is in
  3661. (however this functionality is not
  3662. implemented by default in any
  3663. current browser).
  3664. I have added some CSS styles
  3665. to this example so that you can
  3666. see the contents of the <thead>
  3667. and <tfoot> being treated
  3668. differently than the rest of the
  3669. rows. You will learn how to apply
  3670. these CSS styles to tables on
  3671. pages 309-312 and 337-340.
  3672. 137 TABLES
  3673. Result
  3674. There are some outdated
  3675. attributes which you should not
  3676. use on new websites. You may,
  3677. however, come across some
  3678. of them when looking at older
  3679. code, so I will mention them
  3680. here. All of these attributes have
  3681. been replaced by the use of CSS.
  3682. The width attribute was used
  3683. on the opening <table> tag to
  3684. indicate how wide that table
  3685. should be and on some opening
  3686. <th> and <td> tags to specify
  3687. the width of individual cells.
  3688. The value of this attribute is
  3689. the width of the table or cell in
  3690. pixels.
  3691. The columns in a table need to
  3692. form a straight line, so you often
  3693. only see the width attribute on
  3694. the first row (and all subsequent
  3695. rows would use that setting).
  3696. The opening <table> tag could
  3697. also use the cellpadding
  3698. attribute to add space inside
  3699. each cell of the table, and the
  3700. cellspacing attribute to create
  3701. space between each cell of
  3702. the table. The values for these
  3703. attributes were given in pixels.
  3704. I added CSS styles to this
  3705. example so that you can see the
  3706. width of the table cells more
  3707. clearly. If you want to control
  3708. the width or spacing of tables
  3709. and cells you should use CSS as
  3710. shown on pages 303, 337-340.
  3711. <table width="400" cellpadding="10" cellspacing="5">
  3712. <tr>
  3713. <th width="150"></th>
  3714. <th>Withdrawn</th>
  3715. <th>Credit</th>
  3716. <th width="150">Balance</th>
  3717. </tr>
  3718. <tr>
  3719. <th>January</th>
  3720. <td>250.00</td>
  3721. <td>660.50</td>
  3722. <td>410.50</td>
  3723. </tr>
  3724. <tr>
  3725. <th>February</th>
  3726. <td>135.55</td>
  3727. <td>895.20</td>
  3728. <td>1170.15</td>
  3729. </tr>
  3730. </table>
  3731. chapter-06/width-and-spacing.html HTML
  3732. Old Code:
  3733. Width & Spacing
  3734. Article
  3735. TABLES 138
  3736. Result
  3737. The border attribute was used
  3738. on both the <table> and <td>
  3739. elements to indicate the width of
  3740. the border in pixels.
  3741. The bgcolor attribute was used
  3742. to indicate background colors
  3743. of either the entire table or
  3744. individual table cells. The value
  3745. is usually a hex code (which we
  3746. discuss on pages 249-252).
  3747. This example uses the HTML
  3748. border and bgcolor attributes.
  3749. No CSS attributes were utilized
  3750. in this example.
  3751. When building a new website
  3752. you should use CSS to control
  3753. the appearance of the table
  3754. rather than these attributes.
  3755. They are only covered here
  3756. because you may come across
  3757. them if you look at the code of
  3758. older websites.
  3759. <table border="2" bgcolor="#efefef">
  3760. <tr>
  3761. <th width="150"></th>
  3762. <th>Withdrawn</th>
  3763. <th>Credit</th>
  3764. <th width="150" bgcolor="#cccccc">Balance</th>
  3765. </tr>
  3766. <tr>
  3767. <th>January</th>
  3768. <td>250.00</td>
  3769. <td>660.50</td>
  3770. <td bgcolor="#cccccc">410.50</td>
  3771. </tr>
  3772. <tr>
  3773. <th>February</th>
  3774. <td>135.55</td>
  3775. <td>895.20</td>
  3776. <td bgcolor="#cccccc">1170.15</td>
  3777. </tr>
  3778. </table>
  3779. HTML chapter-06/border-and-background.html
  3780. Old Code:
  3781. Border & Background
  3782. 139 TABLES
  3783. This example shows a table for
  3784. customers to compare website
  3785. hosting packages. There are
  3786. table headings in the first row
  3787. and first column of the table.
  3788. The empty cell in the top left still
  3789. has a <th> element to represent
  3790. it. Each cell of the table must be
  3791. accounted for by a <th> or <td>
  3792. element. The <th> elements use
  3793. the scope attribute to indicate
  3794. whether they are headings for
  3795. a row or column. The final row
  3796. uses the colspan attribute to
  3797. spread across all three columns.
  3798. Example
  3799. TABLES
  3800. TABLES 140
  3801. <html>
  3802. <head>
  3803. <title>Tables</title>
  3804. </head>
  3805. <body>
  3806. <table>
  3807. <thead>
  3808. <tr>
  3809. <th></th>
  3810. <th scope="col">Home starter hosting</th>
  3811. <th scope="col">Premium business hosting</th>
  3812. </tr>
  3813. </thead>
  3814. <tbody>
  3815. <tr>
  3816. <th scope="row">Disk space</th>
  3817. <td>250mb</td>
  3818. <td>1gb</td>
  3819. </tr>
  3820. <tr>
  3821. <th scope="row">Bandwidth</th>
  3822. <td>5gb per month</td>
  3823. <td>50gb per month</td>
  3824. </tr>
  3825. <!-- more rows like the two above here -->
  3826. </tbody>
  3827. <tfoot>
  3828. <tr>
  3829. <td></td>
  3830. <td colspan="2">Sign up now and save 10%!</td>
  3831. </tr>
  3832. </tfoot>
  3833. </table>
  3834. </body>
  3835. </html>
  3836.  
  3837. Summary
  3838. TABLES
  3839. X The <table> element is used to add tables to a web
  3840. page.
  3841. X A table is drawn out row by row. Each row is created
  3842. with the <tr> element.
  3843. X Inside each row there are a number of cells
  3844. represented by the <td> element (or <th> if it is a
  3845. header).
  3846. X You can make cells of a table span more than one row
  3847. or column using the rowspan and colspan attributes.
  3848. X For long tables you can split the table into a <thead>,
  3849. <tbody>, and <tfoot>.
  3850.  
  3851. X How to collect information from visitors
  3852. X Different kinds of form controls
  3853. X New HTML5 form controls
  3854. Forms
  3855. 7
  3856. 145 FORMS
  3857. Traditionally, the term 'form' has referred
  3858. to a printed document that contains
  3859. spaces for you to fill in information.
  3860. HTML borrows the concept of a form to refer to different
  3861. elements that allow you to collect information from visitors to
  3862. your site.
  3863. Whether you are adding a simple search box to your website or
  3864. you need to create more complicated insurance applications,
  3865. HTML forms give you a set of elements to collect data from
  3866. your users. In this chapter you will learn:
  3867. ● How to create a form on your website
  3868. ● The different tools for collecting data
  3869. ● New HTML5 form controls
  3870. FORMS 146
  3871. 147 FORMS
  3872. In addition to enabling users to
  3873. search, forms also allow users
  3874. to perform other functions
  3875. online. You will see forms
  3876. when registering as a member
  3877. of a website, when shopping
  3878. online, and when signing up for
  3879. newsletters or mailing lists.
  3880. The best known form on the web is probably
  3881. the search box that sits right in the middle of
  3882. Google's homepage.
  3883. Why Forms?
  3884. FORMS 148
  3885. There are several types of form controls that
  3886. you can use to collect information from visitors
  3887. to your site.
  3888. Form Controls
  3889. ADDING TEXT:
  3890. Making Choices:
  3891. Submitting Forms: Uploading Files:
  3892. Password input
  3893. Like a single line text box but it
  3894. masks the characters entered.
  3895. Text input (single-line)
  3896. Used for a single line of text such
  3897. as email addresses and names.
  3898. Text area (multi-line)
  3899. For longer areas of text, such as
  3900. messages and comments.
  3901. Checkboxes
  3902. When a user can select and
  3903. unselect one or more options.
  3904. Radio buttons
  3905. For use when a user must select
  3906. one of a number of options.
  3907. Drop-down boxes
  3908. When a user must pick one of a
  3909. number of options from a list.
  3910. Image buttons
  3911. Similar to submit buttons but
  3912. they allow you to use an image.
  3913. Submit buttons
  3914. To submit data from your form
  3915. to another web page.
  3916. File upload
  3917. Allows users to upload files
  3918. (e.g. images) to a website.
  3919. 149 FORMS
  3920. How Forms Work
  3921. Thank you, Ivy!
  3922. You voted for Herbie Hancock.
  3923. A user fills in a form and then presses a button
  3924. to submit the information to the server.
  3925. The server creates a new
  3926. page to send back to the
  3927. browser based on the
  3928. information received.
  3929. VOTE FOR YOUR FAVORITE JAZZ
  3930. MUSICIAN OF ALL TIME
  3931. Username:
  3932. I vote for: Ella Fitzgerald
  3933. Herbie Hancock
  3934. John Coltrane
  3935. Miles Davis
  3936. Thelonius Monk
  3937. Ivy
  3938. Submit
  3939. The name of each form
  3940. control is sent to the
  3941. server along with the
  3942. value the user enters or
  3943. selects.
  3944. 1
  3945. The server processes
  3946. the information using a
  3947. programming language
  3948. such as PHP, C#, VB.net,
  3949. or Java. It may also store
  3950. the information in a
  3951. database.
  3952. 3
  3953. 2
  3954. 4
  3955. FORMS 150
  3956. A form may have several form controls, each
  3957. gathering different information. The server
  3958. needs to know which piece of inputted data
  3959. corresponds with which form element.
  3960. To differentiate between various pieces of inputted data, information
  3961. is sent from the browser to the server using name/value pairs. In this
  3962. example, the form asks for the visitor's username and also for their
  3963. favorite jazz musician. The name/value pairs sent to the server are:
  3964. You should never change the name of a form control in a page unless
  3965. you know that the code on the server will understand this new value.
  3966. username=Ivy
  3967. If the form control allows the
  3968. user to enter text, then the value
  3969. of the form control is whatever
  3970. the user has typed in.
  3971. vote=Herbie
  3972. If the form control allows you
  3973. to choose from a fixed set of
  3974. answers (e.g. radio buttons,
  3975. checkboxes or a drop down list),
  3976. the web page author will add
  3977. code that gives each option an
  3978. automatic value.
  3979. username=Ivy
  3980. Name
  3981. Value
  3982. 151 FORMS
  3983. Result
  3984. <form>
  3985. Form controls live inside a
  3986. <form> element. This element
  3987. should always carry the action
  3988. attribute and will usually have a
  3989. method and id attribute too.
  3990. action
  3991. Every <form> element requires
  3992. an action attribute. Its value
  3993. is the URL for the page on the
  3994. server that will receive the
  3995. information in the form when it
  3996. is submitted.
  3997. method
  3998. Forms can be sent using one of
  3999. two methods: get or post.
  4000. With the get method, the values
  4001. from the form are added to
  4002. the end of the URL specified in
  4003. the action attribute. The get
  4004. method is ideal for:
  4005. ● short forms (such as search
  4006. boxes)
  4007. ● when you are just retrieving
  4008. data from the web server
  4009. (not sending information that
  4010. should be added to or deleted
  4011. from a database)
  4012. <form action="http://www.example.com/subscribe.php"
  4013. method="get">
  4014. <p>This is where the form controls will appear.
  4015. </p>
  4016. </form>
  4017. chapter-07/form-structure.html HTML
  4018. Form Structure
  4019. With the post method the
  4020. values are sent in what are
  4021. known as HTTP headers. As a
  4022. rule of thumb you should use the
  4023. post method if your form:
  4024. ● allows users to upload a file
  4025. ● is very long
  4026. ● contains sensitive data
  4027. (e.g. passwords)
  4028. ● adds information to, or
  4029. deletes information from, a
  4030. database
  4031. If the method attribute is not
  4032. used, the form data will be sent
  4033. using the get method.
  4034. id
  4035. We look at the id attribute on
  4036. page 183, but the value is used to
  4037. identify the form distinctly from
  4038. other elements on the page (and
  4039. is often used by scripts — such
  4040. as those that check you have
  4041. entered information into fields
  4042. that require values).
  4043. Article
  4044. FORMS 152
  4045. Result
  4046. <input>
  4047. The <input> element is used
  4048. to create several different form
  4049. controls. The value of the type
  4050. attribute determines what kind
  4051. of input they will be creating.
  4052. type="text"
  4053. When the type attribute has a
  4054. value of text, it creates a singleline
  4055. text input.
  4056. name
  4057. When users enter information
  4058. into a form, the server needs to
  4059. know which form control each
  4060. piece of data was entered into.
  4061. (For example, in a login form, the
  4062. server needs to know what has
  4063. been entered as the username
  4064. and what has been given as the
  4065. password.) Therefore, each form
  4066. control requires a name attribute.
  4067. The value of this attribute
  4068. identifies the form control and is
  4069. sent along with the information
  4070. they enter to the server.
  4071. maxlength
  4072. You can use the maxlength
  4073. attribute to limit the number
  4074. of characters a user may enter
  4075. into the text field. Its value is the
  4076. number of characters they may
  4077. enter. For example, if you were
  4078. asking for a year, the maxlength
  4079. attribute could have a value of 4.
  4080. <form action="http://www.example.com/login.php">
  4081. <p>Username:
  4082. <input type="text" name="username" size="15"
  4083. maxlength="30" />
  4084. </p>
  4085. </form>
  4086. HTML chapter-07/text-input.html
  4087. Text Input
  4088. size
  4089. The size attribute should not
  4090. be used on new forms. It was
  4091. used in older forms to indicate
  4092. the width of the text input
  4093. (measured by the number of
  4094. characters that would be seen).
  4095. For example, a value of 3 would
  4096. create a box wide enough to
  4097. display three characters
  4098. (although a user could enter
  4099. more characters if they desired).
  4100. In any new forms you write,
  4101. CSS should be used to control
  4102. the width of form elements.
  4103. The size attribute is only
  4104. mentioned here because you
  4105. may come across it when looking
  4106. at older code.
  4107. 153 FORMS
  4108. Result
  4109. <input>
  4110. type="password"
  4111. When the type attribute has
  4112. a value of password it creates
  4113. a text box that acts just like a
  4114. single-line text input, except
  4115. the characters are blocked out.
  4116. They are hidden in this way so
  4117. that if someone is looking over
  4118. the user's shoulder, they cannot
  4119. see sensitive data such as
  4120. passwords.
  4121. name
  4122. The name attribute indicates
  4123. the name of the password input,
  4124. which is sent to the server with
  4125. the password the user enters.
  4126. size, maxlength
  4127. It can also carry the size and
  4128. maxlength attributes like the
  4129. the single-line text input.
  4130. <form action="http://www.example.com/login.php">
  4131. <p>Username:
  4132. <input type="text" name="username" size="15"
  4133. maxlength="30" />
  4134. </p>
  4135. <p>Password:
  4136. <input type="password" name="password" size="15"
  4137. maxlength="30" />
  4138. </p>
  4139. </form>
  4140. chapter-07/password-input.html HTML
  4141. Password Input
  4142. Although the password is hidden
  4143. on the screen, this does not
  4144. mean that the data in a password
  4145. control is sent securely to the
  4146. server. You should never use
  4147. these for sending sensitive data
  4148. such as credit card numbers.
  4149. For full security, the server needs
  4150. to be set up to communicate
  4151. with users' browsers using
  4152. Secure Sockets Layer (SSL). The
  4153. topic of SSL is beyond the scope
  4154. of this book, however there are
  4155. links to learn more about it on
  4156. the accompanying website.
  4157. Article
  4158. FORMS 154
  4159. Result
  4160. <textarea>
  4161. The <textarea> element
  4162. is used to create a mutli-line
  4163. text input. Unlike other input
  4164. elements this is not an empty
  4165. element. It should therefore have
  4166. an opening and a closing tag.
  4167. Any text that appears between
  4168. the opening <textarea> and
  4169. closing </textarea> tags will
  4170. appear in the text box when the
  4171. page loads.
  4172. If the user does not delete any
  4173. text between these tags, this
  4174. message will get sent to the
  4175. server along with whatever the
  4176. user has typed. (Some sites
  4177. use JavaScript to clear this
  4178. information when the user clicks
  4179. in the text area.)
  4180. <form action="http://www.example.com/comments.php">
  4181. <p>What did you think of this gig?</p>
  4182. <textarea name="comments" cols="20" rows="4">Enter
  4183. your comments...</textarea>
  4184. </form>
  4185. HTML chapter-07/textarea.html
  4186. Text Area
  4187. If you are creating a new form,
  4188. you should use CSS to control
  4189. the width and height of a
  4190. <textarea>. However, if you are
  4191. looking at older code, you may
  4192. see the cols and rows attributes
  4193. used with this element.
  4194. The cols attribute indicates
  4195. how wide the text area should
  4196. be (measured in numbers of
  4197. characters). The rows attribute
  4198. indicates how many rows
  4199. the text area should take up
  4200. vertically.
  4201. 155 FORMS
  4202. Result
  4203. <input>
  4204. type="radio"
  4205. Radio buttons allow users to pick
  4206. just one of a number of options.
  4207. name
  4208. The name attribute is sent to
  4209. the server with the value of the
  4210. option the user selects. When
  4211. a question provides users with
  4212. options for answers in the form
  4213. of radio buttons, the value of
  4214. the name attribute should be the
  4215. same for all of the radio buttons
  4216. used to answer that question.
  4217. value
  4218. The value attribute indicates
  4219. the value that is sent to the
  4220. server for the selected option.
  4221. The value of each of the buttons
  4222. in a group should be different
  4223. (so that the server knows which
  4224. option the user has selected).
  4225. checked
  4226. The checked attribute can be
  4227. used to indicate which value (if
  4228. any) should be selected when
  4229. the page loads. The value of this
  4230. attribute is checked. Only one
  4231. radio button in a group should
  4232. use this attribute.
  4233. <form action="http://www.example.com/profile.php">
  4234. <p>Please select your favorite genre:
  4235. <br />
  4236. <input type="radio" name="genre" value="rock"
  4237. checked="checked" /> Rock
  4238. <input type="radio" name="genre" value="pop" />
  4239. Pop
  4240. <input type="radio" name="genre" value="jazz" />
  4241. Jazz
  4242. </p>
  4243. </form>
  4244. chapter-07/radio-button.html HTML
  4245. Radio Button
  4246. Please note: Once a radio button
  4247. has been selected it cannot be
  4248. deselected. The user can only
  4249. select a different option. If you
  4250. are only allowing the user one
  4251. option and want them to be
  4252. able to deselect it (for example
  4253. if they are indicating they agree
  4254. to terms and conditions), you
  4255. should use a checkbox instead.
  4256. Article
  4257. FORMS 156
  4258. Result
  4259. <input>
  4260. type="checkbox"
  4261. Checkboxes allow users to select
  4262. (and unselect) one or more
  4263. options in answer to a question.
  4264. name
  4265. The name attribute is sent to
  4266. the server with the value of the
  4267. option(s) the user selects. When
  4268. a question provides users with
  4269. options for answers in the form
  4270. of checkboxes, the value of the
  4271. name attribute should be the
  4272. same for all of the buttons that
  4273. answer that question.
  4274. value
  4275. The value attribute indicates
  4276. the value sent to the server if this
  4277. checkbox is checked.
  4278. checked
  4279. The checked attribute indicates
  4280. that this box should be checked
  4281. when the page loads. If used, its
  4282. value should be checked.
  4283. <form action="http://www.example.com/profile.php">
  4284. <p>Please select your favorite music service(s):
  4285. <br />
  4286. <input type="checkbox" name="service"
  4287. value="itunes" checked="checked" /> iTunes
  4288. <input type="checkbox" name="service"
  4289. value="lastfm" /> Last.fm
  4290. <input type="checkbox" name="service"
  4291. value="spotify" /> Spotify
  4292. </p>
  4293. </form>
  4294. HTML chapter-07/checkbox.html
  4295. Checkbox
  4296. 157 FORMS
  4297. Result
  4298. <select>
  4299. A drop down list box (also
  4300. known as a select box) allows
  4301. users to select one option from a
  4302. drop down list.
  4303. The <select> element is used
  4304. to create a drop down list box. It
  4305. contains two or more <option>
  4306. elements.
  4307. name
  4308. The name attribute indicates the
  4309. name of the form control being
  4310. sent to the server, along with the
  4311. value the user selected.
  4312. <option>
  4313. The <option> element is used
  4314. to specify the options that the
  4315. user can select from. The words
  4316. between the opening <option>
  4317. and closing </option> tags will
  4318. be shown to the user in the drop
  4319. down box.
  4320. value
  4321. The <option> element uses the
  4322. value attribute to indicate the
  4323. value that is sent to the server
  4324. along with the name of the
  4325. control if this option is selected.
  4326. <form action="http://www.example.com/profile.php">
  4327. <p>What device do you listen to music on?</p>
  4328. <select name="devices">
  4329. <option value="ipod">iPod</option>
  4330. <option value="radio">Radio</option>
  4331. <option value="computer">Computer</option>
  4332. </select>
  4333. </form>
  4334. chapter-07/drop-down-list-box.html HTML
  4335. Drop Down List Box
  4336. selected
  4337. The selected attribute can be
  4338. used to indicate the option that
  4339. should be selected when the
  4340. page loads. The value of this
  4341. attribute should be selected.
  4342. If this attribute is not used,
  4343. the first option will be shown
  4344. when the page loads. If the user
  4345. does not select an option, then
  4346. the first item will be sent to
  4347. the server as the value for this
  4348. control.
  4349. The function of the drop down
  4350. list box is similar to that of the
  4351. radio buttons (in that only one
  4352. option can be selected). There
  4353. are two key factors in choosing
  4354. which to use:
  4355. 1. If users need to see all options
  4356. at a glance, radio buttons are
  4357. better suited.
  4358. 2. If there is a very long list
  4359. of options (such as a list of
  4360. countries), drop down list boxes
  4361. work better.
  4362. Article
  4363. FORMS 158
  4364. Result
  4365. <select>
  4366. size
  4367. You can turn a drop down select
  4368. box into a box that shows more
  4369. than one option by adding the
  4370. size attribute. Its value should
  4371. be the number of options you
  4372. want to show at once. In the
  4373. example you can see that three
  4374. of the four options are shown.
  4375. Unfortunately, the way that
  4376. browsers have implemented this
  4377. attribute is not perfect, and it
  4378. should be tested throroughly if
  4379. used (in particular in Firefox and
  4380. Safari on a Mac).
  4381. multiple
  4382. You can allow users to select
  4383. multiple options from this list by
  4384. adding the multiple attribute
  4385. with a value of multiple.
  4386. It is a good idea to tell users if
  4387. they can select more than one
  4388. option at a time. It is also helpful
  4389. to indicate that on a PC they
  4390. should hold down the control key
  4391. while selecting multiple options
  4392. and on a Mac they should use
  4393. the command key while selecting
  4394. options.
  4395. <form action="http://www.example.com/profile.php">
  4396. <p>Do you play any of the following instruments?
  4397. (You can select more than one option by holding
  4398. down control on a PC or command key on a Mac
  4399. while selecting different options.)</p>
  4400. <select name="instruments" size="3"
  4401. multiple="multiple">
  4402. <option value="guitar" selected="selected">
  4403. Guitar</option>
  4404. <option value="drums">Drums</option>
  4405. <option value="keyboard"
  4406. selected="selected">Keyboard</option>
  4407. <option value="bass">Bass</option>
  4408. </select>
  4409. </form>
  4410. HTML chapter-07/multiple-select-box.html
  4411. Multiple Select Box
  4412. 159 FORMS
  4413. Result
  4414. <input>
  4415. If you want to allow users to
  4416. upload a file (for example an
  4417. image, video, mp3, or a PDF),
  4418. you will need to use a file input
  4419. box.
  4420. type="file"
  4421. This type of input creates a
  4422. box that looks like a text input
  4423. followed by a browse button.
  4424. When the user clicks on the
  4425. browse button, a window opens
  4426. up that allows them to select a
  4427. file from their computer to be
  4428. uploaded to the website.
  4429. When you are allowing users
  4430. to upload files, the method
  4431. attribute on the <form> element
  4432. must have a value of post. (You
  4433. cannot send files using the HTTP
  4434. get method.)
  4435. When a user clicks on the
  4436. browse button, the presentation
  4437. of the window that allows
  4438. them to browse for the file they
  4439. want to upload will match the
  4440. windows of the user's operating
  4441. system. You cannot control the
  4442. appearance of these windows.
  4443. <form action="http://www.example.com/upload.php"
  4444. method="post">
  4445. <p>Upload your song in MP3 format:</p>
  4446. <input type="file" name="user-song" /><br />
  4447. <input type="submit" value="Upload" />
  4448. </form>
  4449. chapter-07/file-input-box.html HTML
  4450. File Input Box
  4451. Article
  4452. FORMS 160
  4453. Result
  4454. <input>
  4455. type="submit"
  4456. The submit button is used to
  4457. send a form to the server.
  4458. name
  4459. It can use a name attribute but it
  4460. does not need to have one.
  4461. value
  4462. The value attribute is used to
  4463. control the text that appears
  4464. on a button. It is a good idea to
  4465. specify the words you want to
  4466. appear on a button because the
  4467. default value of buttons on some
  4468. browsers is ‘Submit query’ and
  4469. this might not be appropriate for
  4470. all kinds of form.
  4471. Different browsers will show
  4472. submit buttons in different
  4473. ways and tend to fit the visual
  4474. presentation of the browser.
  4475. If you want to control the
  4476. appearance of a submit button,
  4477. you can either use CSS (as you
  4478. will learn on page 343), or you
  4479. can use an image for the button.
  4480. <form action="http://www.example.com/subscribe.php">
  4481. <p>Subscribe to our email list:</p>
  4482. <input type="text" name="email" />
  4483. <input type="submit" name="subscribe"
  4484. value="Subscribe" />
  4485. </form>
  4486. HTML chapter-07/submit-button.html
  4487. Submit Button
  4488. 161 FORMS
  4489. Result
  4490. <input>
  4491. type="image"
  4492. If you want to use an image for
  4493. the submit button, you can give
  4494. the type attribute a value of
  4495. image. The src, width, height,
  4496. and alt attributes work just
  4497. like they do when used with the
  4498. <img> element (which we saw
  4499. on pages 99-100).
  4500. <form action="http://www.example.org/subscribe.php">
  4501. <p>Subscribe to our email list:</p>
  4502. <input type="text" name="email" />
  4503. <input type="image" src="images/subscribe.jpg"
  4504. width="100" height="20" />
  4505. </form>
  4506. chapter-07/image-button.html HTML
  4507. Image Button
  4508. Article
  4509. FORMS 162
  4510. Result
  4511. <button>
  4512. The <button> element was
  4513. introduced to allow users more
  4514. control over how their buttons
  4515. appear, and to allow other
  4516. elements to appear inside the
  4517. button.
  4518. This means that you can
  4519. combine text and images
  4520. between the opening <button>
  4521. tag and closing </button> tag.
  4522. <input>
  4523. type="hidden"
  4524. This example also shows a
  4525. hidden form control. These form
  4526. controls are not shown on the
  4527. page (although you can see them
  4528. if you use the View Source option
  4529. in the browser). They allow web
  4530. page authors to add values to
  4531. forms that users cannot see.
  4532. For example, a web page author
  4533. might use a hidden field to
  4534. indicate which page the user was
  4535. on when they submitted a form.
  4536. <form action="http://www.example.com/add.php">
  4537. <button><img src="images/add.gif" alt="add"
  4538. width="10" height="10" /> Add</button>
  4539. <input type="hidden" name="bookmark"
  4540. value="lyrics" />
  4541. </form>
  4542. HTML chapter-07/button-and-hidden-controls.html
  4543. Button & hidden
  4544. Controls
  4545. 163 FORMS
  4546. Result
  4547. <label>
  4548. When introducing form controls,
  4549. the code was kept simple by
  4550. indicating the purpose of each
  4551. one in text next to it. However,
  4552. each form control should have
  4553. its own <label> element as this
  4554. makes the form accessible to
  4555. vision-impaired users.
  4556. The <label> element can be
  4557. used in two ways. It can:
  4558. 1. Wrap around both the text
  4559. description and the form input
  4560. (as shown on the first line of the
  4561. example to your right).
  4562. 2. Be kept separate from the
  4563. form control and use the for
  4564. attribute to indicate which form
  4565. control it is a label for (as shown
  4566. with the radio buttons).
  4567. for
  4568. The for attribute states which
  4569. form control the label belongs to.
  4570. Note how the radio buttons use
  4571. the id attribute. The value of the
  4572. id attribute uniquely identifies an
  4573. element from all other elements
  4574. on a page. (The id attribute is
  4575. covered on page 183.)
  4576. The value of the for attribute
  4577. matches that of the id attribute
  4578. on the form control it is labelling.
  4579. This technique using the for and
  4580. <label>Age: <input type="text" name="age" /></label>
  4581. <br/ >
  4582. Gender:
  4583. <input id="female" type="radio" name="gender"
  4584. value="f">
  4585. <label for="female">Female</label>
  4586. <input id="male" type="radio" name="gender"
  4587. value="m">
  4588. <label for="male">Male</label>
  4589. chapter-07/labelling-form-controls.html HTML
  4590. Labelling Form
  4591. Controls
  4592. id attributes can be used on any
  4593. form control. When a <label>
  4594. element is used with a checkbox
  4595. or radio button, users can click
  4596. on either the form control or the
  4597. label to select. The expanded
  4598. clickable area makes the form
  4599. easier to use. The position of the
  4600. label is very important. If users
  4601. do not know where to enter
  4602. information or what information
  4603. to enter, they are less likely to
  4604. use the form correctly.
  4605. As a rule of thumb, here are the
  4606. best places to place labels on
  4607. form controls.
  4608. Above or to the left:
  4609. ● Text inputs
  4610. ● Text areas
  4611. ● Select boxes
  4612. ● File uploads
  4613. To the right:
  4614. ● Individual checkboxes
  4615. ● Individual radio buttons
  4616. Article
  4617. FORMS 164
  4618. Result
  4619. <fieldset>
  4620. You can group related form
  4621. controls together inside the
  4622. <fieldset> element. This is
  4623. particularly helpful for longer
  4624. forms.
  4625. Most browsers will show the
  4626. fieldset with a line around
  4627. the edge to show how they are
  4628. related. The appearance of these
  4629. lines can be adjusted using CSS.
  4630. <legend>
  4631. The <legend> element can
  4632. come directly after the opening
  4633. <fieldset> tag and contains a
  4634. caption which helps identify the
  4635. purpose of that group of form
  4636. controls.
  4637. <fieldset>
  4638. <legend>Contact details</legend>
  4639. <label>Email:<br />
  4640. <input type="text" name="email" /></label><br />
  4641. <label>Mobile:<br />
  4642. <input type="text" name="mobile" /></label><br />
  4643. <label>Telephone:<br />
  4644. <input type="text" name="telephone" /></label>
  4645. </fieldset>
  4646. HTML chapter-07/grouping-form-elements.html
  4647. Grouping Form
  4648. Elements
  4649. 165 FORMS
  4650. Result
  4651. You have probably seen forms
  4652. on the web that give users
  4653. messages if the form control has
  4654. not been filled in correctly; this is
  4655. known as form validation.
  4656. Traditionally, form validation
  4657. has been performed using
  4658. JavaScript (which is beyond the
  4659. scope of this book). But HTML5
  4660. is introducing validation and
  4661. leaving the work to the browser.
  4662. Validation helps ensure the
  4663. user enters information in a
  4664. form that the server will be able
  4665. to understand when the form
  4666. is submitted. Validating the
  4667. contents of the form before it is
  4668. sent to the server the helps:
  4669. ● Reduce the amount of work
  4670. the server has to do
  4671. ● Enables users to see if there
  4672. are problems with the form
  4673. faster than if validation were
  4674. performed on the server.
  4675. <form action="http://www.example.com/login/"
  4676. method="post">
  4677. <label for="username">Username:</label>
  4678. <input type="text" name="username"
  4679. required="required" /></title><br />
  4680. <label for="password">Password:</label>
  4681. <input type="password" name="password"
  4682. required="required" />
  4683. <input type="submit" value="Submit" />
  4684. </form>
  4685. chapter-07/html5-form-validation.html HTML
  4686. HTML5: Form Validation
  4687. At the time of writing, only
  4688. Chrome and Opera supported
  4689. HTML5 validation, although other
  4690. browsers are expected to follow.
  4691. In order to support older browsers
  4692. (that do not understand HTML5),
  4693. web page authors are likely to
  4694. continue using JavaScript to
  4695. validate forms.
  4696. An example of HTML5 form
  4697. validation is the required
  4698. attribute, which can be used on
  4699. any form element that the user
  4700. is expected to fill in. This HTML5
  4701. attribute does not need a value,
  4702. but in HTML 4 all attributes must
  4703. have a value. So, some people give
  4704. this attribute a value of required.
  4705. Article
  4706. FORMS 166
  4707. Result
  4708. <input>
  4709. Many forms need to gather
  4710. information such as dates, email
  4711. addresses, and URLs. This has
  4712. traditionally been done using
  4713. text inputs.
  4714. HTML5 introduces new form
  4715. controls to standardize the
  4716. way that some information is
  4717. gathered. Older browsers that
  4718. do not recognize these inputs
  4719. will just treat them as a single
  4720. line text box.
  4721. type="date"
  4722. If you are asking the user for a
  4723. date, you can use an <input>
  4724. element and give the type
  4725. attribute a value of date.
  4726. This will create a date input in
  4727. browsers that support the new
  4728. HMTL5 input types.
  4729. This example shows what the
  4730. date input looks like in the Opera
  4731. browser. The appearance of
  4732. the date input changes across
  4733. different browsers.
  4734. <form action="http://www.example.com/bookings/"
  4735. method="post">
  4736. <label for="username">Departure date:</label>
  4737. <input type="date" name="depart" />
  4738. <input type="submit" value="Submit" />
  4739. </form>
  4740. HTML chapter-07/html5-date-input.html
  4741. HTML5: Date Input
  4742. 167 FORMS
  4743. <input>
  4744. HTML5 has also introduced
  4745. inputs that allow visitors to
  4746. enter email addresses and URLs.
  4747. Browsers that do not support
  4748. these input types will just treat
  4749. them as text boxes.
  4750. type="email"
  4751. If you ask a user for an email
  4752. address, you can use the email
  4753. input. Browsers that support
  4754. HTML5 validation will check
  4755. that the user has provided
  4756. information in the correct format
  4757. of an email address. Some smart
  4758. phones also optimize their
  4759. keyboard to display the keys you
  4760. are most likely to need when
  4761. entering an email address (such
  4762. as the @ symbol).
  4763. type="url"
  4764. A URL input can be used when
  4765. you are asking a user for a web
  4766. page address. Browsers that
  4767. support HTML5 validation will
  4768. check that the user has provided
  4769. information in the format of
  4770. a URL. Some smart phones
  4771. also optimize their keyboard to
  4772. display the keys you are most
  4773. likely to need when entering a
  4774. URL.
  4775. <form action="http://www.example.org/profile.php">
  4776. <p>Please enter your website address:</p>
  4777. <input type="url" name="website" />
  4778. <input type="submit" value="Submit" />
  4779. </form>
  4780. chapter-07/html5-url-input.html HTML
  4781. Result
  4782. <form action="http://www.example.org/subscribe.php">
  4783. <p>Please enter your email address:</p>
  4784. <input type="email" name="email" />
  4785. <input type="submit" value="Submit" />
  4786. </form>
  4787. chapter-07/html5-email-input.html HTML
  4788. Result
  4789. HTML5: Email & URL Input
  4790. Article
  4791. FORMS 168
  4792. <input>
  4793. If you want to create a single
  4794. line text box for search queries,
  4795. HTML5 provides a special type
  4796. of input for that purpose.
  4797. type="search"
  4798. If you want to create a single
  4799. line text box for search queries,
  4800. HTML5 provides a special
  4801. search input.
  4802. To create the HTML5 search box
  4803. the <input> element should
  4804. have a type attribute whose
  4805. value is search. Older browsers
  4806. will simply treat it like a single
  4807. line text box.
  4808. Recent browsers add some
  4809. features that improve usability.
  4810. For example, Safari on a Mac
  4811. adds a cross to clear the search
  4812. box when you have started to
  4813. enter information. Safari also
  4814. automatically rounds the corners
  4815. on the search input field.
  4816. placeholder
  4817. On any text input, you can
  4818. also use an attribute called
  4819. placeholder whose value is
  4820. text that will be shown in the
  4821. text box until the user clicks in
  4822. that area. Older browsers simply
  4823. ignore this attribute.
  4824. <form action="http://www.example.org/search.php">
  4825. <p>Search:</p>
  4826. <input type="search" name="search"
  4827. placeholder="Enter keyword" />
  4828. <input type="submit" value="Search" />
  4829. </form>
  4830. HTML chapter-07/html5-placeholder.html
  4831. Result
  4832. <form action="http://www.example.org/search.php">
  4833. <p>Search:</p>
  4834. <input type="search" name="search" />
  4835. <input type="submit" value="Search" />
  4836. </form>
  4837. HTML chapter-07/html5-search-input.html
  4838. Result
  4839. HTML5: Search Input
  4840. 169 FORMS
  4841. Example
  4842. FORMS
  4843. FORMS 170
  4844. This example shows a feedback and newsletter
  4845. sign-up form. It uses a variety of form controls.
  4846. The <form> element uses the action attribute to indicate the page that
  4847. the data is being sent to. Each of the form controls sits inside the <form>
  4848. element. Different types of form control are suited to collecting different
  4849. types of data. The <fieldset> element is used to group related
  4850. questions together. The <label> element indicates the purpose of each
  4851. form control.
  4852. 171 FORMS
  4853. Example
  4854. FORMS
  4855. <html>
  4856. <head>
  4857. <title>Forms</title>
  4858. </head>
  4859. <body>
  4860. <form action="http://www.example.com/review.php" method="get">
  4861. <fieldset>
  4862. <legend>
  4863. Your Details:
  4864. </legend>
  4865. <label>
  4866. Name:
  4867. <input type="text" name="name" size="30" maxlength="100">
  4868. </label>
  4869. <br />
  4870. <label>
  4871. Email:
  4872. <input type="email" name="email" size="30" maxlength="100">
  4873. </label>
  4874. <br />
  4875. </fieldset>
  4876. <br />
  4877. <fieldset>
  4878. <legend>
  4879. Your Review:
  4880. </legend>
  4881. <p>
  4882. <label for="hear-about">
  4883. How did you hear about us?
  4884. </label>
  4885. <select name="referrer" id="hear-about">
  4886. <option value="google">Google</option>
  4887. <option value="friend">Friend</option>
  4888. <option value="advert">Advert</option>
  4889. <option value="other">Other</option>
  4890. </select>
  4891. </p>
  4892. <p>
  4893. FORMS 172
  4894. Example
  4895. FORMS
  4896. Would you visit again?
  4897. <br />
  4898. <label>
  4899. <input type="radio" name="rating" value="yes" />
  4900. Yes
  4901. </label>
  4902. <label>
  4903. <input type="radio" name="rating" value="no" />
  4904. No
  4905. </label>
  4906. <label>
  4907. <input type="radio" name="rating" value="maybe" />
  4908. Maybe
  4909. </label>
  4910. </p>
  4911. <p>
  4912. <label for="comments">
  4913. Comments:
  4914. </label>
  4915. <br />
  4916. <textarea rows="4" cols="40" id="comments">
  4917. </textarea>
  4918. </p>
  4919. <label>
  4920. <input type="checkbox" name="subscribe" checked="checked" />
  4921. Sign me up for email updates
  4922. </label>
  4923. <br />
  4924. <input type="submit" value="Submit review" />
  4925. </fieldset>
  4926. </form>
  4927. </body>
  4928. </html>
  4929.  
  4930. Summary
  4931. FORMS
  4932. X Whenever you want to collect information from
  4933. visitors you will need a form, which lives inside a
  4934. <form> element.
  4935. X Information from a form is sent in name/value pairs.
  4936. X Each form control is given a name, and the text the
  4937. user types in or the values of the options they select
  4938. are sent to the server.
  4939. X HTML5 introduces new form elements which make it
  4940. easier for visitors to fill in forms.
  4941.  
  4942. X Specifying different versions of HTML
  4943. X Identifying and grouping elements
  4944. X Comments, meta information and iframes
  4945. Extra
  4946. Markup
  4947. 8
  4948. 177 EXTRA MARKUP
  4949. At this point, we have covered the main
  4950. tags that fit nicely into groups and
  4951. sections.
  4952. In this chapter, we will focus on some helpful topics that are
  4953. not easily grouped together. You will learn about:
  4954. ● The different versions of HTML and how to indicate which
  4955. version you are using
  4956. ● How to add comments to your code
  4957. ● Global attributes, which are attributes that can be used on
  4958. any element, including the class and id attributes
  4959. ● Elements that are used to group together parts of the page
  4960. where no other element is suitable
  4961. ● How to embed a page within a page using iframes
  4962. ● How to add information about the web page using the
  4963. <meta> element
  4964. ● Adding characters such as angled brackets and copyright
  4965. symbols
  4966. EXTRA MARKUP 178
  4967. 179 EXTRA MARKUP
  4968. Since the web was first created, there have
  4969. been several different versions of HTML.
  4970. Each new version was designed
  4971. to be an improvement on the
  4972. last (with new elements and
  4973. attributes added and older code
  4974. removed).
  4975. There have also been several
  4976. versions of each browser used to
  4977. view web pages, each of which
  4978. implements new code. Not all
  4979. web users, however, have the
  4980. latest browsers installed on
  4981. their computers, which means
  4982. that not everyone will be able to
  4983. view all of the latest features and
  4984. markup.
  4985. Where you should be
  4986. particularly aware of browsers
  4987. not supporting certain features,
  4988. I have made a note of this (as
  4989. you have seen with some of the
  4990. HTML5 elements introduced in
  4991. the Forms chapter — and as you
  4992. will see in the CSS chapters).
  4993. With the exception of a few
  4994. elements added in HTML5
  4995. (which have been highlighted),
  4996. the elements you have seen in
  4997. this book were all available in
  4998. HTML 4.
  4999. Although HTML 4 had some
  5000. presentational elements to
  5001. control the appearance of pages,
  5002. authors are not recommended to
  5003. use them any more. (Examples
  5004. include the <center> element
  5005. for centering content on a
  5006. page, <font> for controlling
  5007. the appearance of text, and
  5008. <strike> to put a line through
  5009. the text — all of these can be
  5010. achieved with CSS instead.)
  5011. In 1998, a language called XML
  5012. was published. Its purpose
  5013. was to allow people to write
  5014. new markup languages. Since
  5015. HTML was the most widely used
  5016. markup language around, it was
  5017. decided that HTML 4 should be
  5018. reformulated to follow the rules
  5019. of XML and it was renamed
  5020. XHTML. This meant that
  5021. authors had to follow some new,
  5022. more strict rules about writing
  5023. markup. For example:
  5024. ● Every element needed a
  5025. closing tag (except for empty
  5026. elements such as <img />).
  5027. ● Attribute names had to be in
  5028. lowercase.
  5029. ● All attributes required a value,
  5030. and all values were to be
  5031. placed in double quotes.
  5032. ● Deprecated elements should
  5033. no longer be used.
  5034. ● Every element that was
  5035. opened inside another
  5036. element should be closed
  5037. inside that same element.
  5038. The Evolution of HTML
  5039. HTML 4
  5040. Released 1997
  5041. XHTML 1.0
  5042. Released 2000
  5043. EXTRA MARKUP 180
  5044. The examples in this book all
  5045. follow these strict rules of XML.
  5046. One of the key benefits of this
  5047. change was that XHTML works
  5048. seamlessly with other programs
  5049. that are written to create and
  5050. process XML documents.
  5051. It could also be used with other
  5052. data formats such as Scalable
  5053. Vector Graphics (SVG) — a
  5054. graphical language written in
  5055. XML, MathML (used to mark
  5056. up mathematical formulae), and
  5057. CML (used to mark up chemical
  5058. formulae).
  5059. In order to help web page
  5060. authors move to this new syntax,
  5061. two main flavors of XHTML 1.0
  5062. were created:
  5063. ● Strict XHTML 1.0, where
  5064. authors had to follow the rules
  5065. to the letter
  5066. ● Transitional XHTML 1.0,
  5067. where authors could still use
  5068. presentational elements (such
  5069. as <center> and <font>).
  5070. The transitional version of
  5071. XHTML was created because
  5072. it allowed authors to continue
  5073. to follow older practices (with a
  5074. less strict syntax) and use some
  5075. of the elements and attributes
  5076. that were going to be removed
  5077. from future versions of HTML.
  5078. There was also a third version
  5079. of XHTML 1.0 called XHTML
  5080. 1.0 Frameset, which allowed
  5081. web page authors to partition
  5082. a browser window into several
  5083. "frames," each of which would
  5084. hold a different HTML page.
  5085. These days, frames are very
  5086. rarely used and are being phased
  5087. out.
  5088. In HTML5, web page authors do
  5089. not need to close all tags, and
  5090. new elements and attributes will
  5091. be introduced. At the time of
  5092. writing, the HTML5 specification
  5093. had not been completed, but
  5094. the major browser makers had
  5095. started to implement many of
  5096. the new features, and web page
  5097. authors were rapidly adopting
  5098. the new markup.
  5099. Despite the fact that HTML5
  5100. is not yet completed, you can
  5101. safely take advantage of the
  5102. new features of the language as
  5103. long as you endeavour to ensure
  5104. that users with older browsers
  5105. will be able to view your pages
  5106. (even though some of the extra
  5107. features will not be visible to
  5108. them).
  5109. HTML5
  5110. Released 2000
  5111. 181 EXTRA MARKUP
  5112. <!DOCTYPE html>
  5113. <!DOCTYPE html PUBLIC
  5114. "-//W3C//DTD HTML 4.01 Transitional//EN"
  5115. "http://www.w3.org/TR/html4/loose.dtd">
  5116. <!DOCTYPE html PUBLIC
  5117. "-//W3C//DTD XHTML 1.0 Transitional//EN"
  5118. "http://www.w3.org/TR/xhtml1/DTD/
  5119. xhtml1-transitional.dtd">
  5120. <!DOCTYPE html PUBLIC
  5121. "-//W3C//DTD XHTML 1.0 Strict//EN"
  5122. "http://www.w3.org/TR/xhtml1/DTD/
  5123. xhtml1-strict.dtd">
  5124. <?xml version="1.0" ?>
  5125. HTML5 HTML
  5126. Because there have been
  5127. several versions of HTML, each
  5128. web page should begin with a
  5129. DOCTYPE declaration to tell a
  5130. browser which version of HTML
  5131. the page is using (although
  5132. browsers usually display the
  5133. page even if it is not included).
  5134. We will therefore be including
  5135. one in each example for the rest
  5136. of the book.
  5137. As you will see when we come to
  5138. look at CSS and its box model on
  5139. page 316, the use of a DOCTYPE
  5140. can also help the browser to
  5141. render a page correctly.
  5142. Because XHTML was written
  5143. in XML, you will sometimes
  5144. see pages that use the XHTML
  5145. strict DOCTYPE start with
  5146. the optional XML declaration.
  5147. Where this is used, it should be
  5148. the first thing in a document.
  5149. There must be nothing before it,
  5150. not even a space.
  5151. DOCTYPEs
  5152. HTML 4
  5153. Transitional XHTML 1.0
  5154. Strict XHTML 1.0
  5155. XML Declaration
  5156. Article
  5157. EXTRA MARKUP 182
  5158. R esult
  5159. <!-- start of introduction -->
  5160. <h1>Current Exhibitions</h1>
  5161. <h2>Olafur Eliasson</h2>
  5162. <!-- end of introduction -->
  5163. <!-- start of main text -->
  5164. <p>Olafur Eliasson was born in Copenhagen, Denmark
  5165. in 1967 to Icelandic parents.</p>
  5166. <p>He is known for sculptures and large-scale
  5167. installation art employing elemental materials
  5168. such as light, water, and air temperature to
  5169. enhance the viewer's experience.</p>
  5170. <!-- end of main text -->
  5171. <!--
  5172. <a href="mailto:info@example.org">Contact</a>
  5173. -->
  5174. HTML chapter-08/comments-in-html.html <!-- -->
  5175. If you want to add a comment
  5176. to your code that will not be
  5177. visible in the user's browser, you
  5178. can add the text between these
  5179. characters:
  5180. <!-- comment goes here -->
  5181. It is a good idea to add
  5182. comments to your code because,
  5183. no matter how familiar you
  5184. are with the page at the time
  5185. of writing it, when you come
  5186. back to it later (or if someone
  5187. else needs to look at the code),
  5188. comments will make it much
  5189. easier to understand.
  5190. Although comments are not
  5191. visible to users in the main
  5192. browser window, they can be
  5193. viewed by anyone who looks at
  5194. the source code behind the page.
  5195. On a long page you will often
  5196. see comments used to indicate
  5197. where sections of the page start
  5198. or end, and to pass on notes to
  5199. help anyone who is looking at
  5200. the code understand it.
  5201. Comments can also be used
  5202. around blocks of code to stop
  5203. that code from being displayed
  5204. in the browser. In the example on
  5205. the left, the email link has been
  5206. commented out.
  5207. Comments in HTML
  5208. 183 EXTRA MARKUP
  5209. R esult
  5210. <p>Water and air. So very commonplace are these
  5211. substances, they hardly attract attention - and
  5212. yet they vouchsafe our very existence.</p>
  5213. <p id="pullquote">Every time I view the sea I feel
  5214. a calming sense of security, as if visiting my
  5215. ancestral home; I embark on a voyage of seeing.
  5216. </p>
  5217. <p>Mystery of mysteries, water and air are right
  5218. there before us in the sea.</p>
  5219. chapter-08/id-attribute.html HTML Every HTML element can carry
  5220. the id attribute. It is used to
  5221. uniquely identify that element
  5222. from other elements on the
  5223. page. Its value should start with
  5224. a letter or an underscore (not a
  5225. number or any other character).
  5226. It is important that no two
  5227. elements on the same page
  5228. have the same value for their id
  5229. attributes (otherwise the value is
  5230. no longer unique).
  5231. As you will see when you
  5232. come to look at CSS in the next
  5233. section, giving an element a
  5234. unique identity allows you to
  5235. style it differently than any other
  5236. instance of the same element
  5237. on the page. For example,
  5238. you might want to assign one
  5239. paragraph within the page
  5240. (perhaps a paragraph containing
  5241. a pull quote) a different style
  5242. than all of the other paragraphs.
  5243. In the example on the right, the
  5244. paragraph with the id attribute
  5245. whose value is pullquote is
  5246. made uppercase using CSS.
  5247. If you go on to learn about
  5248. JavaScript (a language that
  5249. allows you to add interactivity to
  5250. your pages), id attributes can be
  5251. used to allow the script to work
  5252. with that particular element.
  5253. The id attribute is known as a
  5254. global attribute because it can
  5255. be used on any element.
  5256. ID Attribute
  5257. Article
  5258. EXTRA MARKUP 184
  5259. Every HTML element can
  5260. also carry a class attribute.
  5261. Sometimes, rather than uniquely
  5262. identifying one element within
  5263. a document, you will want a
  5264. way to identify several elements
  5265. as being different from the
  5266. other elements on the page.
  5267. For example, you might have
  5268. some paragraphs of text that
  5269. contain information that is more
  5270. important than others and want
  5271. to distinguish these elements, or
  5272. you might want to differentiate
  5273. between links that point to other
  5274. pages on your own site and links
  5275. that point to external sites.
  5276. To do this you can use the
  5277. class attribute. Its value
  5278. should describe the class it
  5279. belongs to. In the example on
  5280. the left, key paragraphs have a
  5281. class attribute whose value is
  5282. important.
  5283. The class attribute on any
  5284. element can share the same
  5285. value. So, in this example, the
  5286. value of important could be
  5287. used on headings and links, too.
  5288. R esult
  5289. <p class="important">For a one-year period from
  5290. November 2010, the Marugame Genichiro-Inokuma
  5291. Museum of Contemporary Art (MIMOCA) will host a
  5292. cycle of four Hiroshi Sugimoto exhibitions.</p>
  5293. <p>Each will showcase works by the artist
  5294. thematically contextualized under the headings
  5295. "Science," "Architecture," "History" and
  5296. "Religion" so as to present a comprehensive
  5297. panorama of the artist's oeuvre.</p>
  5298. <p class="important admittance">Hours: 10:00 – 18:00
  5299. (No admittance after 17:30)</p>
  5300. HTML chapter-08/class-attribute.html
  5301. Class Attribute
  5302. By default, using these attributes
  5303. does not affect the presentation
  5304. of an element. It will only change
  5305. their appearance if there is a CSS
  5306. rule that indicates it should be
  5307. displayed differently.
  5308. In this example, CSS has been
  5309. applied to make elements with
  5310. a class attribute whose value
  5311. is important uppercase, and
  5312. elements with a class attribute
  5313. whose value is admittance red.
  5314. If you would like to indicate that
  5315. an element belongs to several
  5316. classes, you can separate class
  5317. names with a space, as you can
  5318. see in the third paragraph in the
  5319. example above.
  5320. 185 EXTRA MARKUP
  5321. R esult
  5322. Some elements will always
  5323. appear to start on a new line in
  5324. the browser window. These are
  5325. known as block level elements.
  5326. Examples of block elements are
  5327. <h1>, <p>, <ul>, and <li>.
  5328. <h1>Hiroshi Sugimoto</h1>
  5329. <p>The dates for the ORIGIN OF ART exhibition are as
  5330. follows:</p>
  5331. <ul>
  5332. <li>Science: 21 Nov - 20 Feb 2010/11</li>
  5333. <li>Architecture: 6 Mar - 15 May 2011</li>
  5334. <li>History: 29 May - 21 Aug 2011</li>
  5335. <li>Religion: 28 Aug - 6 Nov 2011</li>
  5336. </ul>
  5337. chapter-08/block-elements.html HTML
  5338. Block Elements
  5339. Article
  5340. EXTRA MARKUP 186
  5341. Timed to a single revolution of the planet around
  5342. the sun at a 23.4 degrees tilt that plays out the
  5343. rhythm of the seasons, this <em>Origins of Art</em>
  5344. cycle is organized around four themes: <b>science,
  5345. architecture, history</b> and <b>religion</b>.
  5346. HTML chapter-08/inline-elements.html Some elements will always
  5347. appear to continue on the
  5348. same line as their neighbouring
  5349. elements. These are known as
  5350. inline elements.
  5351. Examples of inline elements are
  5352. <a>, <b>, <em>, and <img>.
  5353. Inline Elements
  5354. R esult
  5355. 187 EXTRA MARKUP
  5356. R esult
  5357. <div id="header">
  5358. <img src="images/logo.gif" alt="Anish Kapoor" />
  5359. <ul>
  5360. <li><a href="index.html">Home</a></li>
  5361. <li><a href="biography.html">Biography</a></li>
  5362. <li><a href="works.html">Works</a></li>
  5363. <li><a href="contact.html">Contact</a></li>
  5364. </ul>
  5365. </div><!-- end of header -->
  5366. <div> chapter-08/grouping-block-elements.html HTML
  5367. The <div> element allows you to
  5368. group a set of elements together
  5369. in one block-level box.
  5370. For example, you might create
  5371. a <div> element to contain all
  5372. of the elements for the header
  5373. of your site (the logo and the
  5374. navigation), or you might create
  5375. a <div> element to contain
  5376. comments from visitors.
  5377. In a browser, the contents of
  5378. the <div> element will start on
  5379. a new line, but other than this
  5380. it will make no difference to the
  5381. presentation of the page.
  5382. Using an id or class attribute
  5383. on the <div> element, however,
  5384. means that you can create
  5385. CSS style rules to indicate how
  5386. much space the <div> element
  5387. should occupy on the screen and
  5388. change the appearance of all the
  5389. elements contained within it.
  5390. It can also make it easier to
  5391. follow your code if you have used
  5392. <div> elements to hold each
  5393. section of the page.
  5394. Grouping Text &
  5395. Elements In a Block
  5396. Since there may be several
  5397. other elements inside a <div>
  5398. element, it can be helpful to add
  5399. a comment after the closing
  5400. </div> tag.
  5401. This allows you to clearly see
  5402. which opening tag it is supposed
  5403. to correspond to, as shown at
  5404. the end of the example here.
  5405. Article
  5406. EXTRA MARKUP 188
  5407. R esult
  5408. <span>
  5409. The <span> element acts like
  5410. an inline equivalent of the <div>
  5411. element. It is used to either:
  5412. 1. Contain a section of text
  5413. where there is no other suitable
  5414. element to differentiate it from
  5415. its surrounding text
  5416. 2. Contain a number of inline
  5417. elements
  5418. The most common reason why
  5419. people use <span> elements
  5420. is so that they can control the
  5421. appearance of the content of
  5422. these elements using CSS.
  5423. You will usually see that a class
  5424. or id attribute is used with
  5425. <span> elements:
  5426. ● To explain the purpose of this
  5427. <span> element
  5428. ● So that CSS styles can be
  5429. applied to elements that
  5430. have specific values for these
  5431. attributes
  5432. Grouping Text &
  5433. Elements Inline
  5434. <p>Anish Kapoor won the Turner Prize in 1991 and
  5435. exhibited at the <span class="gallery">Tate
  5436. Modern</span> gallery in London in 2003.</p>
  5437. HTML chapter-08/grouping-inline-elements.html
  5438. 189 EXTRA MARKUP
  5439. R esult
  5440. <iframe
  5441. width="450"
  5442. height="350"
  5443. src="http://maps.google.co.uk/maps?q=moma+new+york
  5444. &amp;output=embed">
  5445. </iframe>
  5446. <iframe> chapter-08/iframes.html HTML
  5447. An iframe is like a little window
  5448. that has been cut into your
  5449. page — and in that window you
  5450. can see another page. The term
  5451. iframe is an abbreviation of inline
  5452. frame.
  5453. One common use of iframes
  5454. (that you may have seen on
  5455. various websites) is to embed
  5456. a Google Map into a page. The
  5457. content of the iframe can be any
  5458. html page (either located on the
  5459. same server or anywhere else on
  5460. the web).
  5461. An iframe is created using the
  5462. <iframe> element. There are a
  5463. few attributes that you will need
  5464. to know to use it:
  5465. src
  5466. The src attribute specifies the
  5467. URL of the page to show in the
  5468. frame.
  5469. height
  5470. The height attribute specifies
  5471. the height of the iframe in pixels.
  5472. width
  5473. The width attribute specifies
  5474. the width of the iframe in pixels.
  5475. IFrames
  5476. Article
  5477. EXTRA MARKUP 190
  5478. scrolling
  5479. The scrolling attribute will
  5480. not be supported in HTML5. In
  5481. HTML 4 and XHTML, it indicates
  5482. whether the iframe should
  5483. have scrollbars or not. This is
  5484. important if the page inside the
  5485. iframe is larger than the space
  5486. you have allowed for it (using the
  5487. height and width attributes).
  5488. Scrollbars allow the user to move
  5489. around the frame to see more
  5490. content. It can take one of three
  5491. values: yes (to show scrollbars),
  5492. no (to hide scrollbars) and auto
  5493. (to show them only if needed).
  5494. frameborder
  5495. The frameborder attribute will
  5496. not be supported in HTML5. In
  5497. HTML 4 and XHTML, it indicates
  5498. whether the frame should have
  5499. a border or not. A value of 0
  5500. indicates that no border should
  5501. be shown. A value of 1 indicates
  5502. that a border should be shown.
  5503. seamless
  5504. In HTML5, a new attribute
  5505. called seamless can be applied
  5506. to an iframe where scrollbars
  5507. are not desired. The seamless
  5508. attribute (like some other new
  5509. HTML5 attributes) does not
  5510. need a value, but you will often
  5511. see authors give it a value of
  5512. seamless. Older browsers
  5513. do not support the seamless
  5514. attribute.
  5515. R esult
  5516. <iframe
  5517. src="http://maps.google.co.uk/maps?q=moma+new+york
  5518. &amp;output=embed"
  5519. width="450"
  5520. height="350"
  5521. frameborder="0"
  5522. scrolling="no">
  5523. </iframe>
  5524. HTML chapter-08/iframes-continued.html
  5525. 191 EXTRA MARKUP
  5526. Information About
  5527. Your Pages
  5528. <meta>
  5529. The <meta> element lives
  5530. inside the <head> element and
  5531. contains information about that
  5532. web page.
  5533. It is not visible to users but
  5534. fulfills a number of purposes
  5535. such as telling search engines
  5536. about your page, who created
  5537. it, and whether or not it is time
  5538. sensitive. (If the page is time
  5539. sensitive, it can be set to expire.)
  5540. The <meta> element is an empty
  5541. element so it does not have a
  5542. closing tag. It uses attributes to
  5543. carry the information.
  5544. The most common attributes
  5545. are the name and content
  5546. attributes, which tend to be
  5547. used together. These attributes
  5548. specify properties of the entire
  5549. page. The value of the name
  5550. attribute is the property you
  5551. are setting, and the value of the
  5552. content attribute is the value
  5553. that you want to give to this
  5554. property.
  5555. In the first line of the example on
  5556. the opposite page, you can see a
  5557. <meta> element where the name
  5558. attribute indicates an intention
  5559. to specify a description for the
  5560. page. The content attribute is
  5561. where this description is actually
  5562. specified.
  5563. The value of the name attribute
  5564. can be anything you want it to
  5565. be. Some defined values for this
  5566. attribute that are commonly
  5567. used are:
  5568. description
  5569. This contains a description
  5570. of the page. This description
  5571. is commonly used by search
  5572. engines to understand what the
  5573. page is about and should be a
  5574. maximum of 155 characters.
  5575. Sometimes it is also displayed in
  5576. search engine results.
  5577. keywords
  5578. This contains a list of commaseparated
  5579. words that a user
  5580. might search on to find the page.
  5581. In practice, this no longer has
  5582. any noticeable effect on how
  5583. search engines index your site.
  5584. robots
  5585. This indicates whether search
  5586. engines should add this page
  5587. to their search results or not. A
  5588. value of noindex can be used if
  5589. this page should not be added. A
  5590. value of nofollow can be used
  5591. if search engines should add this
  5592. page in their results but not any
  5593. pages that it links to.
  5594. Article
  5595. EXTRA MARKUP 192
  5596. <!DOCTYPE html>
  5597. <html>
  5598. <head>
  5599. <title>Information About Your Pages</title>
  5600. <meta name="description"
  5601. content="An Essay on Installation Art" />
  5602. <meta name="keywords"
  5603. content="installation, art, opinion" />
  5604. <meta name="robots"
  5605. content="nofollow" />
  5606. <meta http-equiv="author"
  5607. content="Jon Duckett" />
  5608. <meta http-equiv="pragma"
  5609. content="no-cache" />
  5610. <meta http-equiv="expires"
  5611. content="Fri, 04 Apr 2014 23:59:59 GMT" />
  5612. </head>
  5613. <body>
  5614. </body>
  5615. </html>
  5616. HTML chapter-08/meta.html
  5617. The <meta> element also
  5618. uses the http-equiv and
  5619. content attributes in pairs.
  5620. In our example, you can see
  5621. three instances of the httpequiv
  5622. attribute. Each one has a
  5623. different purpose:
  5624. author
  5625. This defines the author of the
  5626. web page.
  5627. pragma
  5628. This prevents the browser from
  5629. caching the page. (That is,
  5630. storing it locally to save time
  5631. downloading it on subsequent
  5632. visits.)
  5633. expires
  5634. Because browsers often cache
  5635. the content of a page, the
  5636. expires option can be used
  5637. to indicate when the page
  5638. should expire (and no longer be
  5639. cached). Note that the date must
  5640. be specified in the format shown.
  5641. 193 EXTRA MARKUP
  5642. Therefore, if you want these
  5643. characters to appear on your
  5644. page you need to use what are
  5645. termed "escape" characters
  5646. (also known as escape codes or
  5647. entity references). For example,
  5648. to write a left angled bracket,
  5649. you can use either &lt; or
  5650. &#60;. For an ampersand, you
  5651. can use either &amp; or &#38;.
  5652. There are also special codes
  5653. that can be used to show
  5654. symbols such as copyright and
  5655. trademark, currency symbols,
  5656. mathematical characters, and
  5657. some punctuation marks. For
  5658. example, if you want to include a
  5659. copyright symbol on a web page
  5660. you can use either &copy; or
  5661. &#169;.
  5662. When using escape characters,
  5663. it is important to check the
  5664. page in your browser to ensure
  5665. that the correct symbol shows
  5666. up. This is because some fonts
  5667. do not support all of these
  5668. characters and you might
  5669. therefore need to specify
  5670. a different font for these
  5671. characters in your CSS code.
  5672. There are some characters that are used in
  5673. and reserved by HTML code. (For example, the
  5674. left and right angled brackets.)
  5675. Escape Characters
  5676. Online Extra
  5677. You can find a more complete
  5678. list of escape codes in the
  5679. tools section of the website
  5680. accompanying this book.
  5681. EXTRA MARKUP 194
  5682. <
  5683. >
  5684. &
  5685. "
  5686. ¢
  5687. £
  5688. ¥
  5689. ¤
  5690. ©
  5691. ®
  5692. '
  5693. ×
  5694. ÷
  5695. Less-than sign
  5696. &lt;
  5697. &#60;
  5698. Greater-than sign
  5699. &gt;
  5700. &amp;
  5701. Ampersand
  5702. &amp;
  5703. &#38;
  5704. Quotation mark
  5705. &quot;
  5706. &#34;
  5707. Cent sign
  5708. &cent;
  5709. &#162;
  5710. Pound sign
  5711. &pound;
  5712. &#163;
  5713. Yen sign
  5714. &yen;
  5715. &#165;
  5716. Euro sign
  5717. &euro;
  5718. &#8364;
  5719. Copyright symbol
  5720. &copy;
  5721. &#169;
  5722. Registered trademark
  5723. &reg;
  5724. &#174;
  5725. Trademark
  5726. &trade;
  5727. &#8482;
  5728. Left single quote
  5729. &lsquo;
  5730. &#8216;
  5731. Right single quote
  5732. &rsquo;
  5733. &#8217;
  5734. Left double quotes
  5735. &ldquo;
  5736. &#8220;
  5737. Right double quotes
  5738. &rdquo;
  5739. &#8221;
  5740. Multiplication sign
  5741. &times;
  5742. &#215;
  5743. Division sign
  5744. &divide;
  5745. &#247;
  5746. 195 EXTRA MARKUP
  5747. This example starts by using a
  5748. DOCTYPE to indicate that this
  5749. is an HTML 4 web page. In the
  5750. head, you can also see a <meta>
  5751. tag describing the page's
  5752. content. Several elements use
  5753. the id and class attributes
  5754. to identify their purpose. The
  5755. copyright symbol has been
  5756. added using an escape code.
  5757. Parts of the page have been
  5758. grouped using <div> elements,
  5759. and comments have been added
  5760. to indicate what the </div>
  5761. elements are closing.
  5762. Example
  5763. EXTRA MARKUP
  5764. EXTRA MARKUP 196
  5765. <!DOCTYPE html PUBLIC
  5766. "-//W3C//DTD HTML 4.01 Transitional//EN"
  5767. "http://www.w3.org/TR/html4/loose.dtd">
  5768. <html>
  5769. <head>
  5770. <meta name="description" content="Telephone, email
  5771. and directions for The Art Bookshop, London, UK" />
  5772. <title>Contact The Art Bookshop, London UK</title>
  5773. </head>
  5774. <body>
  5775. <div id="header">
  5776. <h1>The Art Book Shop</h1>
  5777. <ul>
  5778. <li><a href="index.html">home</a></li>
  5779. <li><a href="index.html">new publications</a>
  5780. </li>
  5781. <li class="current-page">
  5782. <a href="index.html">contact</a></li>
  5783. </ul>
  5784. </div><!-- end header -->
  5785. <div id="content">
  5786. <p>Charing Cross Road, London, WC2, UK</p>
  5787. <p><span class="contact">Telephone</span>
  5788. 0207 946 0946</p>
  5789. <p><span class="contact">Email</span>
  5790. <a href="mailto:books@example.com">
  5791. books@example.com</a></p>
  5792. <iframe width="425" height="275" frameborder="0"
  5793. scrolling="no" marginheight="0" marginwidth="0"
  5794. src="http://maps.google.co.uk/maps?f=q&amp;
  5795. source=s_q&amp;hl=en&amp;geocode=&amp;
  5796. q=charing+cross+road+london&amp;output=embed">
  5797. </iframe>
  5798. </div><!-- end content -->
  5799. <p>&copy; The Art Bookshop</p>
  5800. </body>
  5801. </html>
  5802.  
  5803. Summary
  5804. EXTRA MARKUP
  5805. X DOCTYPES tell browsers which version of HTML you
  5806. are using.
  5807. X You can add comments to your code between the
  5808. <!-- and --> markers.
  5809. X The id and class attributes allow you to identify
  5810. particular elements.
  5811. X The <div> and <span> elements allow you to group
  5812. block-level and inline elements together.
  5813. X <iframes> cut windows into your web pages through
  5814. which other pages can be displayed.
  5815. X The <meta> tag allows you to supply all kinds of
  5816. information about your web page.
  5817. X Escape characters are used to include special
  5818. characters in your pages such as <, >, and ©.
  5819.  
  5820. X How to add Flash movies into your site
  5821. X How to add video and audio to your site
  5822. X HTML5 <video> and <audio> elements
  5823. Flash, Video
  5824. & Audio
  5825. 9
  5826. 201 FLASH, VIDEO & AUDIO
  5827. Flash is a very popular technology used
  5828. to add animations, video, and audio to
  5829. websites. This chapter begins by looking
  5830. at how to use it in your web pages.
  5831. We then focus on how to add video and audio to your site,
  5832. using either the new HTML5 <video> and <audio> elements
  5833. or a hosted service (such as YouTube or SoundCloud). In this
  5834. chapter you will learn:
  5835. ● How to use Flash in your web pages
  5836. ● How to use HTML5 <video> and <audio> elements
  5837. ● When to host your own video and audio and when to use a
  5838. service such as YouTube
  5839. FLASH, VIDEO & AUDIO 202
  5840. 203 FLASH, VIDEO & AUDIO
  5841. Whether you are creating an
  5842. animation or a media player in
  5843. Flash, the files you put on your
  5844. website are referred to as Flash
  5845. movies.
  5846. If you want to create your
  5847. own Flash movie, you need to
  5848. purchase the Flash authoring
  5849. environment from Adobe.
  5850. There are, however, several
  5851. companies that offer Flash
  5852. animations and slideshows,
  5853. as well as video and audio
  5854. players that you can use without
  5855. purchasing this tool.
  5856. When you create a Flash file in
  5857. the Flash authoring environment,
  5858. it is saved with the .fla file
  5859. extension. In order to use this file
  5860. on a web page it has to be saved
  5861. in a different format known
  5862. as SWF. (It has the .swf file
  5863. extension.)
  5864. When you export the movie
  5865. into SWF format, Flash creates
  5866. code that you can use to embed
  5867. the Flash movie in your page.
  5868. Traditionally, this code used the
  5869. HTML <object> and <embed>
  5870. tags. However, now it is more
  5871. common to use JavaScript.
  5872. To view Flash, browsers need
  5873. to use a plugin (an extra piece
  5874. of software that runs in the
  5875. browser) called the Flash Player.
  5876. Statistics commonly indicate
  5877. that 98% of browsers on
  5878. desktop computers have the
  5879. Flash plugin installed. (The
  5880. percentage of mobiles and
  5881. tablets with it is much less.)
  5882. There is not space in this book
  5883. to teach you how to create Flash
  5884. movies (there are many books
  5885. devoted to that one topic), but
  5886. this chapter will show you how
  5887. to add Flash movies to your site.
  5888. Since the late 1990s, Flash has been a very
  5889. popular tool for creating animations, and later
  5890. for playing audio and video in websites.
  5891. How Flash Works
  5892. The Flash authoring environment
  5893. is used to create Flash Movies.
  5894. The .fla file is exported to .swf
  5895. format to use in a web page.
  5896. The .swf file is included in your
  5897. web page using JavaScript.
  5898. FLASH, VIDEO & AUDIO 204
  5899. When Flash was first released,
  5900. it was developed to create
  5901. animations. The technology
  5902. quickly evolved, however, and
  5903. people started to use it to build
  5904. media players and even entire
  5905. websites.
  5906. Although Flash is still very
  5907. popular, in recent years people
  5908. have been more selective about
  5909. when they use it (and now rarely
  5910. consider building an entire
  5911. website in Flash).
  5912. Despite this, Flash does have a
  5913. future on the web because there
  5914. are some things it does very well,
  5915. such as creating animations.
  5916. There are several reasons why
  5917. fewer websites are using Flash
  5918. these days, including:
  5919. In 2005-6, a set of JavaScript
  5920. libraries were launched
  5921. (including Prototype,
  5922. script.aculo.us, and JQuery)
  5923. which made it easier for people
  5924. to create animated effects using
  5925. JavaScript.
  5926. When Apple launched the
  5927. iPhone in 2007 and later the
  5928. the iPad in 2010, they took the
  5929. decision not to support Flash.
  5930. There have been laws introduced
  5931. to ensure that websites are
  5932. usable by those with visual or
  5933. physical impairments — and
  5934. Flash has been criticized because
  5935. Flash content does not always
  5936. meet accessibility requirements.
  5937. In 2008, browsers started to
  5938. support HTML5 <video> and
  5939. <audio> tags. At the time of
  5940. writing, Flash is still a popular
  5941. way of playing video and audio
  5942. on the web but more and more
  5943. people are switching to HTML5.
  5944. (You will see how to use these
  5945. elements later in the chapter.)
  5946. Since 2005, a number of factors have meant
  5947. that fewer websites are written in Flash or even
  5948. use elements of Flash in their pages.
  5949. Use of Flash
  5950. 205 FLASH, VIDEO & AUDIO
  5951. Web technologies change quickly. Here you
  5952. can see some of the changes in how animation,
  5953. video, and audio are created on the web.
  5954. Timeline:
  5955. Flash, VidEo & Audio
  5956. On this page you can see the
  5957. first major players to provide
  5958. web animation, audio, and video.
  5959. On the facing page, you can see
  5960. some of the technologies and
  5961. events replacing them.
  5962. RealVideo 8 streaming video
  5963. RealAudio streaming audio
  5964. Flash 4 streaming audio
  5965. FutureSplash, forerunner to Flash
  5966. RealVideo streaming video
  5967. Flash MX Flash video
  5968. Audio
  5969. Animation
  5970. Video
  5971. 1995 1996 1997 1998 1999 2000 2001 2002 2003
  5972. FLASH, VIDEO & AUDIO 206
  5973. YouTube releases iPhone app
  5974. Vimeo releases HTML5 player
  5975. Vimeo releases iPhone app
  5976. YouTube launched
  5977. Vimeo launched
  5978. YouTube releases HTML5 player
  5979. Video sharing sites offer alternatives to self-hosting
  5980. jQuery
  5981. script.aculo.us
  5982. Prototype
  5983. JavaScript libraries are written to create animated effects
  5984. iPhone
  5985. iPad
  5986. Apple releases devices that don't support Flash
  5987. Safari 3.1
  5988. Chrome 3
  5989. Firefox 3.5
  5990. Opera 9 .62
  5991. Internet Explorer 9
  5992. Browsers introduce HTML5 <video> and <audio> tags
  5993. 2004 2005 2006 2007 2008 2009 2010 2011
  5994. 207 FLASH, VIDEO & AUDIO
  5995. <!DOCTYPE html>
  5996. <html>
  5997. <head>
  5998. <title>Adding a Flash Movie</title>
  5999. <script type="text/javascript"
  6000. src="http://ajax.googleapis.com/ajax/libs/
  6001. swfobject/2.2/swfobject.js"></script>
  6002. <script type="text/javascript">
  6003. swfobject.embedSWF("flash/bird.swf",
  6004. "bird", "400", "300", "8.0.0");</script>
  6005. </head>
  6006. <body>
  6007. <div id="bird"><p>An animation of a bird taking
  6008. a shower</p></div>
  6009. </body>
  6010. </html>
  6011. chapter-09/adding-a-flash-movie.html HTML The most popular way of
  6012. adding Flash into a web page
  6013. is using JavaScript. There are
  6014. several scripts that allow you
  6015. to do this without an in-depth
  6016. understanding of the JavaScript
  6017. language.
  6018. The script we will be looking at
  6019. here is called SWFObject. You
  6020. can obtain a copy of it for free
  6021. from Google, and you can see
  6022. how we use it on the next page.
  6023. One advantage to using this
  6024. technique is that it allows
  6025. browsers to show alternative
  6026. content for users whose
  6027. browsers are not capable of
  6028. showing Flash.
  6029. This technique uses a <div>
  6030. element to create a space where
  6031. the Flash movie should sit.
  6032. The <div> element has an id
  6033. attribute whose value is used
  6034. by the SWFObject script. In this
  6035. example, the value of the id
  6036. attribute is bird.
  6037. Inside the <div> element you
  6038. can place the alternative content
  6039. for users who are not able to
  6040. play Flash.
  6041. Adding a Flash Movie
  6042. to Your Web Page
  6043. The SWFObject script will check
  6044. to see if the user's browser can
  6045. play the Flash movie. If it can, the
  6046. script will replace the content of
  6047. the <div> with the .swf file.
  6048. For users who cannot see the
  6049. Flash movie, you could show a
  6050. still from the movie instead. You
  6051. might also like to consider using
  6052. a text description of the Flash
  6053. file.
  6054. If you use a text description as
  6055. alternative content, then you can
  6056. achieve two further benefits:
  6057. 1. The text can be accessed by
  6058. those with visual and/or physical
  6059. impairments who are not able to
  6060. interact with the Flash file.
  6061. 2. The text can be indexed by
  6062. search engines (which are not as
  6063. effective at indexing SWF files),
  6064. increasing the chance that your
  6065. content will be found.
  6066. A
  6067. r
  6068. ticle
  6069. FLASH, VIDEO & AUDIO 208
  6070. Result In this example, the SWFObject
  6071. script is hosted on Google's
  6072. servers. We include the script in
  6073. this web page using the first of
  6074. the two <script> elements.
  6075. The type attribute is used on the
  6076. <script> element to indicate
  6077. that the script inside is written
  6078. in JavaScript. The src attribute
  6079. tells the browser where to find
  6080. the script.
  6081. The second <script> element
  6082. is used to tell the browser about
  6083. the Flash movie, as well as which
  6084. element it should replace. This
  6085. element is actually telling the
  6086. SWFObject script five pieces
  6087. of information, which are in the
  6088. brackets:
  6089. 1. The location of the .swf file:
  6090. flash/bird.swf
  6091. 2. The element that the Flash
  6092. movie should replace, specified
  6093. by the value of the id attribute
  6094. on the <div> element:
  6095. bird
  6096. 3. The width of the Flash movie:
  6097. 400 px
  6098. 4. The height of the Flash movie:
  6099. 300 px
  6100. 5. The minimum version of the
  6101. Flash player needed to view the
  6102. movie:
  6103. Flash Player 8
  6104. 209 FLASH, VIDEO & AUDIO
  6105. Formats
  6106. Movies are available in many
  6107. formats (BluRay, DVD, VHS,
  6108. to name a few). Online, there
  6109. are even more video formats
  6110. (including AVI, Flash Video,
  6111. H264, MPEG, Ogg Theora,
  6112. QuickTime, WebM, and
  6113. Windows Media).
  6114. Just as your DVD player won't
  6115. play a VHS cassette, browsers
  6116. differ in what video formats they
  6117. do and don't support.
  6118. In order for users to view your
  6119. video online, you may need to
  6120. convert it to another format.
  6121. The process of converting
  6122. a video into another format
  6123. is sometimes referred to as
  6124. "encoding" the video.
  6125. There are several apps available
  6126. on the web that enable you to
  6127. encode videos (such as www.
  6128. mirovideoconverter.com).
  6129. Players / pluginS
  6130. Browsers were initially designed
  6131. to show text and images only.
  6132. For this reason, browsers built
  6133. prior to 2010 generally required
  6134. another program called a player
  6135. or plugin to to be installed in
  6136. order to play video content.
  6137. These players and plugins only
  6138. supported certain video formats.
  6139. Recently browsers have evolved
  6140. to support the HTML5 <video>
  6141. tag (which renders players and
  6142. plugins obsolete).
  6143. Unfortunately, however, you
  6144. cannot rely on every visitor to
  6145. your website having a recent
  6146. browser that supports this
  6147. new HTML5 element and the
  6148. browsers that do recognize the
  6149. <video> element require the
  6150. video to be encoded in different
  6151. formats.
  6152. Approach
  6153. The easiest way to add video
  6154. to your site is to use a hosted
  6155. service such as YouTube or
  6156. Vimeo.
  6157. However, there are some cases
  6158. where using these services is
  6159. not appropriate (as you will see
  6160. on the next page) and you will
  6161. want to host the video on your
  6162. own site.
  6163. At the time of writing, to ensure
  6164. most people can play your
  6165. video content, it is considered
  6166. best practice to use the HTML5
  6167. <video> element for browsers
  6168. that support it, and also Flash
  6169. video for those that do not.This
  6170. means you would need to upload
  6171. any videos you want to show in
  6172. at least two different formats:
  6173. WebM and MP4.
  6174. To add video to your site, there are two key
  6175. issues to understand: file formats and video
  6176. players/plugins.
  6177. Understanding Video
  6178. Formats and Players
  6179. FLASH, VIDEO & AUDIO 210
  6180. Advantages
  6181. Hosted video sites (such as
  6182. YouTube) provide players that
  6183. work with the majority of web
  6184. browsers.
  6185. You do not need to worry about
  6186. encoding your video since
  6187. these sites allow you to upload
  6188. your content in a range of
  6189. formats. Once uploaded, they
  6190. automatically convert your video
  6191. into the various formats required
  6192. by different browsers.
  6193. Web hosting companies often
  6194. charge extra if you use a lot of
  6195. bandwidth, and video files can
  6196. be quite large. Therefore, it can
  6197. cost you extra to host the videos
  6198. on your own site. If your video
  6199. is hosted on a site like YouTube
  6200. or Vimeo, however, you do not
  6201. need to pay for the bandwidth.
  6202. Disadvantages
  6203. Your video will be available on
  6204. the site of the hosted service,
  6205. so if you want the content to be
  6206. exclusively available on your site
  6207. (and not visible on other sites),
  6208. you need to host the video on
  6209. your own server and add your
  6210. own player into the page.
  6211. Some services will limit what
  6212. your video is allowed to include.
  6213. For example, most prohibit
  6214. the use of advertising within
  6215. the video you upload (which
  6216. prevents you from monetizing
  6217. that content).
  6218. Some hosted services will play
  6219. their own adverts before your
  6220. video will begin, or even overlay
  6221. them over the screen as your
  6222. video is playing. The quality of
  6223. video on some hosted services
  6224. can also be limited.
  6225. The Alternative
  6226. If you want to host video on your
  6227. own site - rather than a hosted
  6228. service - a lot more work is
  6229. involved in setting up your site to
  6230. play the video.
  6231. We will be looking at two
  6232. different ways that you can host
  6233. your own videos: using both
  6234. Flash Video and the HTML5
  6235. <video> element.
  6236. In order to ensure that the
  6237. maximum number of visitors to
  6238. your site can see the video, you
  6239. will need to use a combination of
  6240. both of these techniques.
  6241. Using Hosted
  6242. Video Services
  6243. The easiest way to add a video to your site is
  6244. to upload the video to a site like YouTube or
  6245. Vimeo and use the features provided on their
  6246. site to embed the video in your page.
  6247. 211 FLASH, VIDEO & AUDIO
  6248. There are three steps you need to follow to add
  6249. a Flash Video to your web page:
  6250. Preparing a Flash
  6251. Video for Your Site
  6252. 1
  6253. Convert Your Video
  6254. into FLV Format
  6255. To play a Flash Video, you need
  6256. to convert your video into FLV
  6257. format. Since Flash 6, the Flash
  6258. authoring environment has come
  6259. with a Flash Video Encoder to
  6260. convert videos into FLV format.
  6261. Some Flash video players
  6262. also support a format called
  6263. H264 (and some video editing
  6264. programs export video in this
  6265. format).
  6266. Googling "FLV or H264
  6267. converters" will allow you to find
  6268. alternative encoding software.
  6269. 2
  6270. FinD an FLV Player to
  6271. Play the Video
  6272. You'll need a player written in
  6273. Flash to play the FLV file. Its
  6274. purpose is to hold the FLV movie
  6275. and add controls such as
  6276. play/pause. Here are two sites
  6277. that offer FLV players:
  6278. www.osflv.com
  6279. www.longtailvideo.com
  6280. You do not need the Flash
  6281. authoring environment to use
  6282. either of these on your website.
  6283. 3
  6284. Include the Player &
  6285. Video in Your Page
  6286. You can include the player in
  6287. your page using a JavaScript
  6288. technique such as SWFObject,
  6289. which was mentioned earlier in
  6290. this chapter.
  6291. You will also need to tell the
  6292. player where it can find the video
  6293. file that you want it to play.
  6294. (Some players have advanced
  6295. features such as the ability
  6296. to create playlists of multiple
  6297. videos, or add a still picture
  6298. before the video plays.)
  6299. I have provided a sample FLV
  6300. file that you can use with the
  6301. download code on the website
  6302. (It is in a separate folder because
  6303. the video files are large.)
  6304. In the following example, we will
  6305. use the OS FLV player, which is
  6306. a free, open-source Flash Video
  6307. player. This is included in the
  6308. download code. It only supports
  6309. the FLV format (not H264).
  6310. In the following example, we will
  6311. also be using the SWFObject
  6312. JavaScript technique mentioned
  6313. on pages 207-208.
  6314. Article
  6315. FLASH, VIDEO & AUDIO 212
  6316. This example uses the OS FLV
  6317. player to display a video called
  6318. puppy.flv, which has already
  6319. been convered into FLV format.
  6320. You have already seen how to
  6321. use SWFObject to embed a
  6322. basic animation in a page, but
  6323. sometimes Flash movies need
  6324. information in order for them
  6325. to work. In this example, the
  6326. video player needs to know the
  6327. path to the video it has to play,
  6328. so SWFObject uses JavaScript
  6329. variables to pass this information
  6330. to the Flash movie. These are
  6331. provided in the two lines of code
  6332. that start with var.
  6333. This particular player is not
  6334. expecting any information in the
  6335. flashvars variable, so that is
  6336. left empty.
  6337. The path to the movie is supplied
  6338. in the variable called params.
  6339. var params = {movie:
  6340. "../videos/puppy.flv"};
  6341. The line after the variables is
  6342. the one that tells the script to
  6343. replace the HTML element
  6344. with the video player. It is very
  6345. similar to the one you saw in the
  6346. earlier example that introduced
  6347. SWFObject.
  6348. Result
  6349. <!DOCTYPE html>
  6350. <html>
  6351. <head>
  6352. <title>Adding a Flash Video</title>
  6353. <script type="text/javascript"
  6354. src="http://ajax.googleapis.com/ajax/libs/
  6355. swfobject/2.2/swfobject.js"></script>
  6356. <script type="text/javascript">
  6357. var flashvars = {};
  6358. var params = {movie:"../video/puppy.flv"};
  6359. swfobject.embedSWF("flash/splayer.swf",
  6360. "snow", "400", "320", "8.0.0",
  6361. flashvars, params);</script>
  6362. </head>
  6363. <body>
  6364. <div id="snow"><p>A video of a puppy playing in
  6365. the snow</p></div>
  6366. </body>
  6367. </html>
  6368. HTML chapter-09/adding-a-flash-video.html
  6369. Adding a Flash Video
  6370. to Your Pages
  6371. Different video players usually require information such as the path to the video in slightly different formats, but
  6372. they usually come with examples and documentation to help you understand how to use them.
  6373. 213 FLASH, VIDEO & AUDIO
  6374. Support
  6375. The new HTML5 <video>
  6376. element is only supported by
  6377. recent browsers, so you cannot
  6378. just use this one technique if you
  6379. want everyone to be able to see
  6380. your video (you need to combine
  6381. this HTML5 with Flash Video).
  6382. Digital Rights
  6383. At the time of writing, the
  6384. <video> element does not
  6385. support any type of Digital
  6386. Rights Management (DRM —
  6387. sometimes referred to as copy
  6388. protection). But a dedicated
  6389. pirate will usually find a way
  6390. around DRM.
  6391. Formats
  6392. Not all browsers support the
  6393. same video formats. Therefore,
  6394. you need to supply your video in
  6395. more than one format.
  6396. To reach as many browsers as
  6397. possible, you should provide the
  6398. video in the following formats:
  6399. H264: IE and Safari
  6400. WebM: Android, Chrome,
  6401. Firefox, Opera
  6402. Chrome, Firefox, and Opera have
  6403. indicated that they will support
  6404. a format called WebM. (Some
  6405. Flash players also support H264,
  6406. and WebM - which will save on
  6407. the number of conversions).
  6408. Controls
  6409. The browser supplies its own
  6410. controls for the player, and
  6411. these can vary from browser
  6412. to browser. You can control the
  6413. appearance of these controls
  6414. using JavaScript (but that is
  6415. beyond the scope of this book).
  6416. In the Browser
  6417. One of the problems with players
  6418. such as the Flash Player is that
  6419. they can behave inconsistently
  6420. when elements such as menus
  6421. drop over them, or the window is
  6422. scaled up or down. The HTML5
  6423. option solves these issues.
  6424. Despite the HTML5 <video> element being a
  6425. very recent addition, it is enjoying widespread
  6426. use. Here are some of the key issues to be
  6427. aware of:
  6428. HTML5: Preparing Video
  6429. for Your Pages
  6430. On page 222 you will see how
  6431. to combine this HTML5 video
  6432. technique with Flash Video to
  6433. achieve wider reach.
  6434. I have provided a sample video in
  6435. H264 and WebM format for you
  6436. to try with the code downloads.
  6437. If you look at this example in
  6438. Firefox and Opera you will see
  6439. different controls when you
  6440. hover over the video.
  6441. Article
  6442. FLASH, VIDEO & AUDIO 214
  6443. <!DOCTYPE html>
  6444. <html>
  6445. <head>
  6446. <title>Adding HTML5 Video</title>
  6447. </head>
  6448. <body>
  6449. <video src="video/puppy.mp4"
  6450. poster="images/puppy.jpg"
  6451. width="400" height="300"
  6452. preload
  6453. controls
  6454. loop>
  6455. <p>A video of a puppy playing in the snow</p>
  6456. </video>
  6457. </body>
  6458. </html>
  6459. HTML chapter-09/adding-html5-video.html <video>
  6460. The <video> element has a
  6461. number of attributes which allow
  6462. you to control video playback:
  6463. src
  6464. This attribute specifies the path
  6465. to the video. (The example video
  6466. is in H264 format so it will only
  6467. work in IE and Safari.)
  6468. poster
  6469. This attribute allows you to
  6470. specify an image to show while
  6471. the video is downloading or until
  6472. the user tells the video to play.
  6473. width, height
  6474. These attributes specify the size
  6475. of the player in pixels.
  6476. controls
  6477. When used, this attribute
  6478. indicates that the browser
  6479. should supply its own controls
  6480. for playback.
  6481. autoplay
  6482. When used, this attribute
  6483. specifies that the file should play
  6484. automatically.
  6485. loop
  6486. When used, this attribute
  6487. indicates that the video should
  6488. start playing again once it has
  6489. ended.
  6490. HTML5: Adding Video
  6491. to Your Pages
  6492. In HTML5 you do not need to
  6493. supply values for all attributes,
  6494. such as the controls, autoplay,
  6495. and loop attributes used
  6496. with the <video> element.
  6497. These attributes are like on/
  6498. off switches. If the attribute is
  6499. present, it turns that option on.
  6500. If the attribute is omitted, the
  6501. option is turned off.
  6502. If the browser does not
  6503. support the <video> element
  6504. or the format of video used,
  6505. it will display whatever is
  6506. between the opening <video>
  6507. and closing </video> tags.
  6508. preload
  6509. This attribute tells the browser
  6510. what to do when the page
  6511. loads. It can have one of three
  6512. values:
  6513. none
  6514. The browser should not load
  6515. the video until the user presses
  6516. play.
  6517. auto
  6518. The browser should download
  6519. the video when the page loads.
  6520. metadata
  6521. The browser should just collect
  6522. information such as the size,
  6523. first frame, track list, and
  6524. duration.
  6525. 215 FLASH, VIDEO & AUDIO
  6526. Result
  6527. <source>
  6528. To specify the location of the file
  6529. to be played, you can use the
  6530. <source> element inside the
  6531. <video> element. (This should
  6532. replace the src attribute on the
  6533. opening <video> tag.)
  6534. You can also use multiple
  6535. <source> elements to specify
  6536. that the video is available in
  6537. different formats.
  6538. (Due to a bug on the iPad, you
  6539. should provide the MP4 video
  6540. as the first format. Otherwise, it
  6541. might not play.)
  6542. src
  6543. This attribute specifies the path
  6544. to the video.
  6545. type
  6546. You should use this attribute
  6547. to tell the browser what format
  6548. the video is. Otherwise, it will
  6549. download some of the video to
  6550. see if it can play the file (which
  6551. will take time and bandwidth).
  6552. codecs
  6553. The codec that was used to
  6554. encode the video is supplied
  6555. within the type attribute. Note
  6556. the use of single quotes, as well
  6557. as double quotes in the type
  6558. attribute, when it is supplied.
  6559. <!DOCTYPE html>
  6560. <html>
  6561. <head>
  6562. <title>Multiple Video Sources</title>
  6563. </head>
  6564. <body>
  6565. <video poster="images/puppy.jpg" width="400"
  6566. height="320" preload controls loop>
  6567. <source src="video/puppy.mp4" type='video/
  6568. mp4;codecs="avc1.42E01E, mp4a.40.2"' />
  6569. <source src="video/puppy.webm" type='video/
  6570. webm;codecs="vp8, vorbis"' />
  6571. <p>A video of a puppy playing in the snow</p>
  6572. </video>
  6573. </body>
  6574. </html>
  6575. chapter-09/multiple-video-sources.html HTML
  6576. HTML5: Multiple Video
  6577. Sources
  6578. If the browser does not support
  6579. the <video> element or the
  6580. format of video used, it will
  6581. display whatever is between the
  6582. opening <video> and closing
  6583. </video> tags.
  6584. Online Extra
  6585. We have provided links to tools
  6586. that help you encode videos and
  6587. audio into the correct formats in
  6588. the Tools section of the website.
  6589. FLASH, VIDEO & AUDIO 216
  6590. You may choose to offer HTML5
  6591. as the first option, and Flash
  6592. video as a fallback for people
  6593. whose browser does not support
  6594. HTML5 video. Or you may work
  6595. the other way around.
  6596. Because some of the video
  6597. players built in Flash support
  6598. H264 encoding, if you use a
  6599. player that supports this format
  6600. you would only need to provide
  6601. the video in H264 and WebM
  6602. formats. (You would not need
  6603. it in FLV format as well.) You
  6604. will see this demonstrated in
  6605. the example at the end of the
  6606. chapter.
  6607. If you start to work with HTML5
  6608. video in depth, you can also:
  6609. ● Create your own playback
  6610. controls
  6611. ● Provide different versions
  6612. of the video for browsers
  6613. that have different sized
  6614. screens (so you can provide
  6615. lower resolution content for
  6616. handheld devices)
  6617. ● Tell different parts of a page
  6618. to change when the video
  6619. reaches a certain point
  6620. By offering your videos in both HTML5 and
  6621. Flash Video formats, you will ensure that it can
  6622. be viewed by the majority of users on your site.
  6623. HTML5: Combining Flash
  6624. & HTML5 Video
  6625. 217 FLASH, VIDEO & AUDIO
  6626. By far the most popular format for putting
  6627. audio on web pages is MP3. As with video,
  6628. there are three routes commonly taken:
  6629. Adding Audio to
  6630. Web Pages
  6631. 1
  6632. Use a Hosted Service
  6633. There are several sites that allow
  6634. you to upload your audio, and
  6635. provide a player which you can
  6636. embed in your page, such as
  6637. SoundCloud.com and
  6638. MySpace.com.
  6639. 2
  6640. Use Flash
  6641. There are several Flash movies
  6642. that allow you to play MP3 files;
  6643. from simple buttons that play
  6644. one track to complex players
  6645. that allow you to create playlists
  6646. and juke boxes.
  6647. 3
  6648. Use HTML5
  6649. HTML5 has introduced a new
  6650. <audio> element. Browsers that
  6651. support this element provide
  6652. their own controls — much as
  6653. they do for the video files we just
  6654. looked at.
  6655. Some people ask how to get
  6656. music to play consistently even
  6657. when visitors move from one
  6658. page to another on a website.
  6659. This is actually quite difficult
  6660. to achieve and would rely on
  6661. techniques like using AJAX to
  6662. load page content or developing
  6663. the entire site in Flash.
  6664. This is why some sites offer
  6665. audio players in new windows,
  6666. so that listeners are not
  6667. interrupted when they move
  6668. between pages.
  6669. Article
  6670. FLASH, VIDEO & AUDIO 218
  6671. There are many MP3 players
  6672. that have already been written in
  6673. Flash, such as:
  6674. flash-mp3-player.net
  6675. musicplayer.sourceforge.net
  6676. www.wimpyplayer.com
  6677. Each of these players has
  6678. different functionality, so check
  6679. their features before choosing
  6680. one for your site.
  6681. This example uses a free player
  6682. from flash-mp3-player.net
  6683. which is embedded in the page
  6684. using the SWFObject technique
  6685. we met on pages 208-208. The
  6686. player is told the path to the MP3
  6687. file using a parameter called mp3.
  6688. After the second <script> tag,
  6689. you can see that we have created
  6690. two JavaScript variables; the first
  6691. called flashvars, the second
  6692. called params. Even though we
  6693. are not using the flashvars
  6694. variable, the SWFObject script
  6695. expects it before the params
  6696. variable so we need it there.
  6697. var flashvars = {};
  6698. var params = {
  6699. mp3: "music/noise.mp3"};
  6700. These variables are then added
  6701. at the end of the line that
  6702. embeds the MP3 player in the
  6703. page (just before the second
  6704. closing <script> tag).
  6705. Result
  6706. <!DOCTYPE html>
  6707. <html>
  6708. <head>
  6709. <title>Adding a Flash MP3 Player</title>
  6710. <script type="text/javascript"
  6711. src="http://ajax.googleapis.com/ajax/libs/
  6712. swfobject/2.2/swfobject.js"></script>
  6713. <script type="text/javascript">
  6714. var flashvars = {};
  6715. var params = {mp3: "audio/test-audio.mp3"};
  6716. swfobject.embedSWF(
  6717. "flash/player_mp3_1.0.0.swf",
  6718. "music-player", "200", "20", "8.0.0",
  6719. flashvars, params);</script>
  6720. </head>
  6721. <body>
  6722. <div id="music-player">
  6723. <p>You cannot hear this track because this
  6724. browser does not support our Flash music
  6725. player.</p>
  6726. </div>
  6727. </body>
  6728. </html>
  6729. HTML chapter-09/adding-a-flash-mp3-player.html
  6730. Adding a FLash
  6731. MP3 Player
  6732. 219 FLASH, VIDEO & AUDIO
  6733. Result
  6734. <!DOCTYPE html>
  6735. <html>
  6736. <head>
  6737. <title>Adding HTML5 Audio</title>
  6738. </head>
  6739. <body>
  6740. <audio src="audio/test-audio.ogg"
  6741. controls autoplay>
  6742. <p>This browser does not support our audio
  6743. format.</p>
  6744. </audio>
  6745. </body>
  6746. </html>
  6747. <audio> chapter-09/adding-html5-audio.html HTML
  6748. HTML5 introduced the <audio>
  6749. element to include audio files
  6750. in your pages. As with HTML5
  6751. video, browsers expect different
  6752. formats for the audio.
  6753. The <audio> element has a
  6754. number of attributes which allow
  6755. you to control audio playback:
  6756. src
  6757. This attribute specifies the path
  6758. to the audio file.
  6759. controls
  6760. This attribute indicates whether
  6761. the player should display
  6762. controls. If you do not use this
  6763. attribute, no controls will be
  6764. shown by default. You can also
  6765. specify your own controls using
  6766. JavaScript.
  6767. autoplay
  6768. The presence of this attribute
  6769. indicates that the audio should
  6770. start playing automatically. (It is
  6771. considered better practice to let
  6772. visitors choose to play audio.)
  6773. HTML5: Adding HTML5
  6774. Audio to Your Pages
  6775. preload
  6776. This attribute indicates what the
  6777. browser should do if the player is
  6778. not set to autoplay. It can have
  6779. the same values we saw on page
  6780. 214 for the <video> element.
  6781. loop
  6782. This attribute specifies that the
  6783. audio track should play again
  6784. once it has finished.
  6785. This example only works in
  6786. browsers that support the Ogg
  6787. Vorbis audio format (Firefox,
  6788. Chrome, and Opera). For it to
  6789. work in Safari 5 and IE 9, the
  6790. audio would need to be in MP3
  6791. format (or use the <source>
  6792. element covered on the next
  6793. page to offer different formats).
  6794. Article
  6795. FLASH, VIDEO & AUDIO 220
  6796. HTML5: Multiple Audio
  6797. Sources
  6798. <source>
  6799. It is possible to specify more
  6800. than one audio file using the
  6801. <source> element between the
  6802. opening <audio> and closing
  6803. </audio> tags (instead of the
  6804. src attribute on the opening
  6805. <audio> tag).
  6806. This is important because
  6807. different browsers support
  6808. different formats for audio files.
  6809. MP3: Safari 5+, Chrome 6+, IE9
  6810. Ogg Vorbis: Firefox 3.6, Chome
  6811. 6, Opera 1.5, IE9
  6812. So you would need to supply two
  6813. audio formats to get coverage
  6814. across all recent browsers that
  6815. support the <audio> element.
  6816. You could also provide a Flash
  6817. alternative for older browsers
  6818. that do not support the <audio>
  6819. element.
  6820. The HTML5 <audio> tag has
  6821. not gained as widespread
  6822. adoption as the <video> tag,
  6823. and there have been some issues
  6824. with audio quality in the first
  6825. browsers to implement it.
  6826. Result
  6827. <!DOCTYPE html>
  6828. <html>
  6829. <head>
  6830. <title>Multiple Audio Sources</title>
  6831. </head>
  6832. <body>
  6833. <audio controls autoplay>
  6834. <source src="audio/test-audio.ogg" />
  6835. <source src="audio/test-audio.mp3" />
  6836. <p>This browser does not support our audio
  6837. format.</p>
  6838. </audio>
  6839. </body>
  6840. </html>
  6841. HTML chapter-09/multiple-audio-sources.html
  6842. src
  6843. The <source> element uses the
  6844. src attribute to indicate where
  6845. the audio file is located.
  6846. type
  6847. At the time of writing, the type
  6848. attribute was not commonly
  6849. being used on the <source>
  6850. element in the same way it was
  6851. for the <video> element.
  6852. 221 FLASH, VIDEO & AUDIO
  6853. Example
  6854. FLASH, VIDEO & AUDIO
  6855. FLASH, VIDEO & AUDIO 222
  6856. This example uses HTML5 to show a video.
  6857. The video has been encoded in H264 and WebM formats to reach as
  6858. many browsers as possible. A Flash player has been added to the page
  6859. for browsers that do not support HTML5 video. The Flash player is
  6860. embedded using SWFObject. If the browser does not support HTML5
  6861. video or Flash, then a plain text message will be shown to the user.
  6862. <!DOCTYPE html>
  6863. <html>
  6864. <head>
  6865. <title>Flash, Video and Audio</title>
  6866. <script type="text/javascript"
  6867. src="http://ajax.googleapis.com/ajax/libs/
  6868. swfobject/2.2/swfobject.js"></script>
  6869. <script type="text/javascript">
  6870. var flashvars = {};
  6871. var params = {movie: "../video/puppy.flv"};
  6872. swfobject.embedSWF("flash/osplayer.swf", "snow",
  6873. "400", "320", "8.0.0", flashvars, params);</script>
  6874. </head>
  6875. <body>
  6876. <video poster="images/puppy.jpg" width="400"
  6877. height="320" controls="controls">
  6878. <source src="video/puppy.mp4" type='video/mp4;
  6879. codecs="avc1.42E01E, mp4a.40.2"' />
  6880. <source src="video/puppy.webm" type='video/webm;
  6881. codecs="vp8, vorbis"' />
  6882. <div id="snow">
  6883. <p>You cannot see this video of a puppy playing
  6884. in the snow because this browser does not
  6885. support our video formats.</p>
  6886. </div>
  6887. </video>
  6888. </body>
  6889. </html>
  6890.  
  6891. Summary
  6892. FLASH, VIDEO & AUDIO
  6893. X Flash allows you to add animations, video and audio to
  6894. the web.
  6895. X Flash is not supported on iPhone or iPad.
  6896. X HTML5 introduces new <video> and <audio>
  6897. elements for adding video and audio to web pages, but
  6898. these are only supported in the latest browsers.
  6899. X Browsers that support the HTML5 elements do not
  6900. all support the same video and audio formats, so you
  6901. need to supply your files in different formats to ensure
  6902. that everyone can see/hear them.
  6903.  
  6904. 10
  6905. X What CSS does
  6906. X How CSS works
  6907. X Rules, properties, and values
  6908. Introducing
  6909. CSS
  6910. 227 INTRODUCING CSS
  6911. In this section, we will look at how to
  6912. make your web pages more attractive,
  6913. controlling the design of them using CSS.
  6914. CSS allows you to create rules that specify how the content of
  6915. an element should appear. For example, you can specify that
  6916. the background of the page is cream, all paragraphs should
  6917. appear in gray using the Arial typeface, or that all level one
  6918. headings should be in a blue, italic, Times typeface.
  6919. Once you have learned how to write a CSS rule, learning CSS
  6920. mostly involves learning the different properties you can use.
  6921. So this chapter will:
  6922. ● Introduce you to how CSS works
  6923. ● Teach you how to write CSS rules
  6924. ● Show you how CSS rules apply to HTML pages
  6925. The remaining chapters in this section will look at all of the
  6926. various CSS properties you can use.
  6927. INTRODUCING CSS 228
  6928. 229 INTRODUCING CSS
  6929. You may remember from
  6930. pages 185-186 that in there is a
  6931. difference between block level
  6932. and inline elements and how
  6933. how browsers display them.
  6934. Block level elements look
  6935. like they start on a new line.
  6936. Examples include the <h1>-
  6937. <h6>, <p> and <div> elements.
  6938. Inline elements flow within the
  6939. text and do not start on a new
  6940. line. Examples include <b>, <i>,
  6941. <img>, <em> and <span>.
  6942. The key to understanding how CSS works is to
  6943. imagine that there is an invisible box around
  6944. every HTML element.
  6945. Understanding CSS:
  6946. Thinking Inside the Box
  6947. On this page, you can see a basic
  6948. HTML page.
  6949. On the right hand page, you can
  6950. see the same HTML page, but I
  6951. have added outlines to each of
  6952. the elements so that you can see
  6953. how CSS will treat each element
  6954. as if it lives inside its own box.
  6955. BLOCK & INLINE ELEMENTS
  6956. INTRODUCING CSS 230
  6957. CSS allows you to create rules that control the
  6958. way that each individual box (and the contents
  6959. of that box) is presented.
  6960. In this example, block level
  6961. elements are shown with red
  6962. borders, and inline elements
  6963. have green borders.
  6964. The <body> element creates the
  6965. first box, then the <h1>, <h2>,
  6966. <p>, <i>, and <a> elements each
  6967. create their own boxes within it.
  6968. Using CSS, you could add a
  6969. border around any of the boxes,
  6970. specify its width and height, or
  6971. add a background color. You
  6972. could also control text inside
  6973. a box — for example, its color,
  6974. size, and the typeface used.
  6975. Width and height
  6976. Borders (color, width, and style)
  6977. Background color and images
  6978. Position in the browser window.
  6979. Typeface
  6980. Size
  6981. Color
  6982. Italics, bold, uppercase,
  6983. lowercase, small-caps
  6984. There are also specific ways
  6985. in which you can style certain
  6986. elements such as lists, tables,
  6987. and forms.
  6988. Example Styles
  6989. Boxes Text Specific
  6990. 231 INTRODUCING CSS
  6991. This rule indicates that all <p>
  6992. elements should be shown in the
  6993. Arial typeface.
  6994. Selectors indicate which
  6995. element the rule applies to.
  6996. The same rule can apply to
  6997. more than one element if you
  6998. separate the element names
  6999. with commas.
  7000. Declarations indicate how
  7001. the elements referred to in
  7002. the selector should be styled.
  7003. Declarations are split into two
  7004. parts (a property and a value),
  7005. and are separated by a colon.
  7006. CSS works by associating rules with HTML elements. These rules govern
  7007. how the content of specified elements should be displayed. A CSS rule
  7008. contains two parts: a selector and a declaration.
  7009. CSS Associates Style
  7010. rules with HTML
  7011. elements
  7012. p {
  7013. font-family: Arial;}
  7014. Selector
  7015. Declaration
  7016. INTRODUCING CSS 232
  7017. This rule indicates that all <h1>,
  7018. <h2> and <h3> elements
  7019. should be shown in the Arial
  7020. typeface, in a yellow color.
  7021. Properties indicate the aspects
  7022. of the element you want to
  7023. change. For example, color, font,
  7024. width, height and border.
  7025. Values specify the settings
  7026. you want to use for the chosen
  7027. properties. For example, if you
  7028. want to specify a color property
  7029. then the value is the color you
  7030. want the text in these elements
  7031. to be.
  7032. CSS declarations sit inside curly brackets and each is made up of two
  7033. parts: a property and a value, separated by a colon. You can specify
  7034. several properties in one declaration, each separated by a semi-colon.
  7035. CSS Properties Affect
  7036. How Elements Are
  7037. Displayed
  7038. h1, h2, h3 {
  7039. font-family: Arial;
  7040. color: yellow;}
  7041. Property Value
  7042. 233 INTRODUCING CSS
  7043. Example
  7044. INTRODUCING CSS
  7045. INTRODUCING CSS 234
  7046. Here you can see a simple web page that is
  7047. styled using CSS.
  7048. This example uses two documents: the HTML file (example.html)
  7049. and a separate CSS file (example.css). The fifth line of HTML uses the
  7050. <link> element to indicate where the CSS file is located.
  7051. On the next page, you will see how CSS rules can also be placed in your
  7052. HTML pages and we will discuss when you might want to do this.
  7053. <!DOCTYPE html>
  7054. <html>
  7055. <head>
  7056. <title>Introducing CSS</title>
  7057. <link href="css/example.css" type="text/css"
  7058. rel="stylesheet" />
  7059. </head>
  7060. <body>
  7061. <h1>From Garden to Plate</h1>
  7062. <p>A <i>potager</i> is a French term for an
  7063. ornamental vegetable or kitchen garden ... </p>
  7064. <h2>What to Plant</h2>
  7065. <p>Plants are chosen as much for their functionality
  7066. as for their color and form ... </p>
  7067. </body>
  7068. </html>
  7069. body {
  7070. font-family: Arial, Verdana, sans-serif;}
  7071. h1, h2 {
  7072. color: #ee3e80;}
  7073. p {
  7074. color: #665544;}
  7075. 235 INTRODUCING CSS
  7076. Result
  7077. <!DOCTYPE html>
  7078. <html>
  7079. <head>
  7080. <title>Using External CSS</title>
  7081. <link href="css/styles.css" type="text/css"
  7082. rel="stylesheet" />
  7083. </head>
  7084. <body>
  7085. <h1>Potatoes</h1>
  7086. <p>There are dozens of different potato
  7087. varieties. They are usually described as
  7088. early, second early and maincrop.</p>
  7089. </body>
  7090. </html>
  7091. <link> chapter-10/using-external-css.html HTML
  7092. The <link> element can be used
  7093. in an HTML document to tell the
  7094. browser where to find the CSS
  7095. file used to style the page. It is an
  7096. empty element (meaning it does
  7097. not need a closing tag), and it
  7098. lives inside the <head> element.
  7099. It should use three attributes:
  7100. href
  7101. This specifies the path to the
  7102. CSS file (which is often placed in
  7103. a folder called css or styles).
  7104. type
  7105. This attribute specifies the type
  7106. of document being linked to. The
  7107. value should be text/css.
  7108. rel
  7109. This specifies the relationship
  7110. between the HTML page and
  7111. the file it is linked to. The value
  7112. should be stylesheet when
  7113. linking to a CSS file.
  7114. An HTML page can use more
  7115. than one CSS style sheet. To
  7116. do this it could have a <link>
  7117. element for every CSS file it
  7118. uses. For example, some authors
  7119. use one CSS file to control the
  7120. presentation (such as fonts and
  7121. colors) and a second to control
  7122. the layout.
  7123. Using External CSS
  7124. body {
  7125. font-family: arial;
  7126. background-color: rgb(185,179,175);}
  7127. h1 {
  7128. color: rgb(255,255,255);}
  7129. chapter-10/styles.css CSS
  7130. Article
  7131. INTRODUCING CSS 236
  7132. <!DOCTYPE html>
  7133. <html>
  7134. <head>
  7135. <title>Using Internal CSS</title>
  7136. <style type="text/css">
  7137. body {
  7138. font-family: arial;
  7139. background-color: rgb(185,179,175);}
  7140. h1 {
  7141. color: rgb(255,255,255);}
  7142. </style>
  7143. </head>
  7144. <body>
  7145. <h1>Potatoes</h1>
  7146. <p>There are dozens of different potato
  7147. varieties. They are usually described as
  7148. early, second early and maincrop.</p>
  7149. </body>
  7150. </html>
  7151. HTML chapter-10/using-internal-css.html
  7152. Result
  7153. <style>
  7154. You can also include CSS rules
  7155. within an HTML page by placing
  7156. them inside a <style> element,
  7157. which usually sits inside the
  7158. <head> element of the page.
  7159. The <style> element should use
  7160. the type attribute to indicate
  7161. that the styles are specified in
  7162. CSS. The value should be text/
  7163. css.
  7164. When building a site with more
  7165. than one page, you should use
  7166. an external CSS style sheet. This:
  7167. ● Allows all pages to use the
  7168. same style rules (rather than
  7169. repeating them in each page).
  7170. ● Keeps the content separate
  7171. from how the page looks.
  7172. ● Means you can change the
  7173. styles used across all pages
  7174. by altering just one file
  7175. (rather than each individual
  7176. page).
  7177. Using Internal CSS
  7178. In HTML 4 and Transitional
  7179. XHTML, you could also use
  7180. a style attribute on most of
  7181. the elements that appear in the
  7182. body of a page. The CSS rules
  7183. that appeared within the value
  7184. of the attribute would only apply
  7185. to that one element. You should
  7186. avoid using this attribute in any
  7187. new site but I mention it here
  7188. because you may see it used in
  7189. older code. Here is an example
  7190. that changes the color of the text
  7191. in a single paragraph red:
  7192. <p style="color:red;">
  7193. + CSS
  7194. 237 INTRODUCING CSS
  7195. There are many different types
  7196. of CSS selector that allow you to
  7197. target rules to specific elements
  7198. in an HTML document.
  7199. The table on the opposite page
  7200. introduces the most commonly
  7201. used CSS selectors.
  7202. On this page, there is an HTML
  7203. file to demonstrate which
  7204. elements these CSS selectors
  7205. would apply to.
  7206. CSS selectors are case sensitive,
  7207. so they must match element
  7208. names and attribute values
  7209. exactly.
  7210. There are some more advanced
  7211. selectors which allow you
  7212. to select elements based on
  7213. attributes and their values,
  7214. which you will see on page 292.
  7215. IE 7 was the first version of IE to
  7216. support the last two selectors in
  7217. the table (the sibling selectors),
  7218. so their use is less common than
  7219. the other selectors shown here.
  7220. <!DOCTYPE html>
  7221. <html>
  7222. <head>
  7223. <title>CSS Selectors</title>
  7224. </head>
  7225. <body>
  7226. <h1 id="top">Kitchen Garden Calendar</h1>
  7227. <p id="introduction">Here you can read our
  7228. handy guide about what to do when.</p>
  7229. <h2>Spring</h2>
  7230. <ul>
  7231. <li><a href="mulch.html">
  7232. Spring mulch vegetable beds</a></li>
  7233. <li><a href="potato.html">
  7234. Plant out early potatoes</a></li>
  7235. <li><a href="tomato.html">
  7236. Sow tomato seeds</a></li>
  7237. <li><a href="beet.html">
  7238. Sow beet seeds</a></li>
  7239. <li><a href="zucchini.html">
  7240. Sow zucchini seeds</a></li>
  7241. <li><a href="rhubarb.html">
  7242. Deadhead rhubarb flowers</a></li>
  7243. </ul>
  7244. <p class="note">
  7245. This page was written by
  7246. <a href="mailto:ivy@example.org">
  7247. ivy@example.org</a> for
  7248. <a href="http://www.example.org">Example</a>.
  7249. </p>
  7250. <p>
  7251. <a href="#top">Top of page</a>
  7252. </p>
  7253. </body>
  7254. </html>
  7255. chapter-10/css-selectors.html HTML
  7256. CSS Selectors
  7257. INTRODUCING CSS 238
  7258. * {}
  7259. Targets all elements on the page
  7260. h1, h2, h3 {}
  7261. Targets the <h1>, <h2> and <h3>
  7262. elements
  7263. .note {}
  7264. Targets any element whose class
  7265. attribute has a value of note
  7266. p.note {}
  7267. Targets only <p> elements
  7268. whose class attribute has a
  7269. value of note
  7270. #introduction {}
  7271. Targets the element whose
  7272. id attribute has a value of
  7273. introduction
  7274. li>a {}
  7275. Targets any <a> elements that
  7276. are children of an <li> element
  7277. (but not other <a> elements in
  7278. the page)
  7279. p a {}
  7280. Targets any <a> elements that
  7281. sit inside a <p> element, even if
  7282. there are other elements nested
  7283. between them
  7284. h1+p {}
  7285. Targets the first <p> element
  7286. after any <h1> element (but not
  7287. other <p> elements)
  7288. h1~p {}
  7289. If you had two <p> elements that
  7290. are siblings of an <h1> element,
  7291. this rule would apply to both
  7292. Universal Selector
  7293. Type Selector
  7294. Class Selector
  7295. ID Selector
  7296. Child Selector
  7297. Descendant Selector
  7298. Adjacent Sibling
  7299. Selector
  7300. General Sibling
  7301. Selector
  7302. Applies to all elements in the
  7303. document
  7304. Matches element names
  7305. Matches an element whose
  7306. class attribute has a value that
  7307. matches the one specified after
  7308. the period (or full stop) symbol
  7309. Matches an element whose
  7310. id attribute has a value that
  7311. matches the one specified after
  7312. the pound or hash symbol
  7313. Matches an element that is a
  7314. direct child of another
  7315. Matches an element that is a
  7316. descendent of another specified
  7317. element (not just a direct child of
  7318. that element)
  7319. Matches an element that is the
  7320. next sibling of another
  7321. Matches an element that is a
  7322. sibling of another, although it
  7323. does not have to be the directly
  7324. preceding element
  7325. Selector Meaning Example
  7326. 239 INTRODUCING CSS
  7327. <h1>Potatoes</h1>
  7328. <p id="intro">There are <i>dozens</i> of different
  7329. <b>potato</b> varieties.</p>
  7330. <p>They are usually described as early, second early
  7331. and maincrop potatoes.</p>
  7332. chapter-10/cascade.html HTML
  7333. If there are two or more rules
  7334. that apply to the same element,
  7335. it is important to understand
  7336. which will take precedence.
  7337. LAST RULE
  7338. If the two selectors are identical,
  7339. the latter of the two will take
  7340. precedence. Here you can see
  7341. the second i selector takes
  7342. precedence over the first.
  7343. SPECIFICITY
  7344. If one selector is more specific
  7345. than the others, the more
  7346. specific rule will take precedence
  7347. over more general ones. In this
  7348. example:
  7349. h1 is more specific than *
  7350. p b is more specific than p
  7351. p#intro is more specific than p
  7352. IMPORTANT
  7353. You can add !important after
  7354. any property value to indicate
  7355. that it should be considered
  7356. more important than other rules
  7357. that apply to the same element.
  7358. Understanding how CSS rules
  7359. cascade means you can write
  7360. simpler style sheets because
  7361. you can create generic rules
  7362. that apply to most elements and
  7363. then override the properties on
  7364. individual elements that need to
  7365. appear differently.
  7366. How Css Rules Cascade
  7367. Result
  7368. * {
  7369. font-family: Arial, Verdana, sans-serif;}
  7370. h1 {
  7371. font-family: "Courier New", monospace;}
  7372. i {
  7373. color: green;}
  7374. i {
  7375. color: red;}
  7376. b {
  7377. color: pink;}
  7378. p b {
  7379. color: blue !important;}
  7380. p b {
  7381. color: violet;}
  7382. p#intro {
  7383. font-size: 100%;}
  7384. p {
  7385. font-size: 75%;}
  7386. CSS
  7387. Article
  7388. INTRODUCING CSS 240
  7389. Result
  7390. <div class="page">
  7391. <h1>Potatoes</h1>
  7392. <p>There are dozens of different potato
  7393. varieties.</p>
  7394. <p>They are usually described as early, second
  7395. early and maincrop potatoes.</p>
  7396. </div>
  7397. HTML chapter-10/inheritance.html If you specify the font-family
  7398. or color properties on the
  7399. <body> element, they will apply
  7400. to most child elements. This is
  7401. because the value of the
  7402. font-family property is
  7403. inherited by child elements. It
  7404. saves you from having to apply
  7405. these properties to as many
  7406. elements (and results in simpler
  7407. style sheets).
  7408. You can compare this with
  7409. the background-color or
  7410. border properties; they are not
  7411. inherited by child elements. If
  7412. these were inherited by all child
  7413. elements then the page could
  7414. look quite messy.
  7415. You can force a lot of properties
  7416. to inherit values from their
  7417. parent elements by using
  7418. inherit for the value of the
  7419. properties. In this example, the
  7420. <div> element with a class
  7421. called page inherits the padding
  7422. size from the CSS rule that
  7423. applies to the <body> element.
  7424. Inheritance
  7425. body {
  7426. font-family: Arial, Verdana, sans-serif;
  7427. color: #665544;
  7428. padding: 10px;}
  7429. .page {
  7430. border: 1px solid #665544;
  7431. background-color: #efefef;
  7432. padding: inherit;}
  7433. CSS
  7434. 241 INTRODUCING CSS
  7435. All of your web pages can share
  7436. the same style sheet. This is
  7437. achieved by using the <link>
  7438. element on each HTML page of
  7439. your site to link to the same CSS
  7440. document. This means that the
  7441. same code does not need to be
  7442. repeated in every page (which
  7443. results in less code and smaller
  7444. HTML pages).
  7445. Therefore, once the user has
  7446. downloaded the CSS stylesheet,
  7447. the rest of the site will load
  7448. faster. If you want to make a
  7449. change to how your site appears,
  7450. you only need to edit the one
  7451. CSS file and all of your pages
  7452. will be updated. For example,
  7453. you can change the style of
  7454. every <h1> element by altering
  7455. the one CSS style sheet, rather
  7456. than changing the CSS rules on
  7457. every page. The HTML code
  7458. will be easier to read and edit
  7459. because it does not have lots of
  7460. CSS rules in the same document.
  7461. It is generally considered good
  7462. practice to have the content of
  7463. the site separated from the rules
  7464. that determine how it appears.
  7465. When building a website there are several advantages to placing your
  7466. CSS rules in a separate style sheet.
  7467. Why use External
  7468. Style Sheets?
  7469. If you are just creating a single
  7470. page, you might decide to put
  7471. the rules in the same file to
  7472. keep everything in one place.
  7473. (However, many authors would
  7474. consider it better practice to
  7475. keep the CSS in a separate file.)
  7476. If you have one page which
  7477. requires a few extra rules (that
  7478. are not used by the rest of the
  7479. site), you might consider using
  7480. CSS in the same page. (Again,
  7481. most authors consider it better
  7482. practice to keep all CSS rules in a
  7483. separate file.)
  7484. Most of the examples in this
  7485. book place the CSS rules in the
  7486. <head> of the document (using
  7487. the <style> element) rather
  7488. than a separate document. This
  7489. is simply to save you opening
  7490. two files to see how the CSS
  7491. examples work.
  7492. Sometimes you might consider placing CSS rules in the same page as
  7493. your HTML code.
  7494. INTRODUCING CSS 242
  7495. In the same way that there have
  7496. been several versions of HTML,
  7497. there have also been different
  7498. versions of CSS.
  7499. Browsers did not implement all
  7500. CSS features at once, so some
  7501. older browsers do not support
  7502. every property.
  7503. This is mentioned when it is
  7504. likely to affect you, along with
  7505. notes where CSS properties
  7506. might not behave as expected.
  7507. Before launching any new site,
  7508. it is important to test it in more
  7509. than one browser, because there
  7510. can be slight differences in how
  7511. browsers display the pages.
  7512. You do not need lots of
  7513. computers to test your site, as
  7514. there are online tools to show
  7515. you what a page looks like in
  7516. multiple browsers:
  7517. BrowserCam.com
  7518. BrowserLab.Adobe.com
  7519. BrowserShots.org
  7520. CrossBrowserTesting.com
  7521. Using these tools, it is a good
  7522. idea to check the site on
  7523. different operating systems (PC,
  7524. Mac, and Linux) and in older
  7525. versions of the major browsers,
  7526. as well as recent versions.
  7527. When you look at your site in
  7528. more than one browser, you
  7529. might find that some elements
  7530. on your page do not look as you
  7531. expect them to.
  7532. When a CSS property does
  7533. not display as expected, it
  7534. is generally referred to as a
  7535. browser quirk or CSS bug.
  7536. Some common browser bugs are
  7537. discussed in this book, but there
  7538. are many smaller bugs that only
  7539. occur in rare situations, or on old
  7540. browsers that few people use.
  7541. If you come across a CSS bug,
  7542. you can use your favorite search
  7543. engine to try and find a solution.
  7544. Or you can check these sites:
  7545. PositionIsEverything.net
  7546. QuirksMode.org
  7547. CSS1 was released in 1996 and CSS2 followed two years later. Work on
  7548. CSS3 has been ongoing but the major browsers have already started to
  7549. implement it.
  7550. Any seasoned user of CSS will tell you that some browsers display a few
  7551. of the CSS properties in an unexpected way. But finding and squashing
  7552. those bugs is easy when you know how...
  7553. Different versions of
  7554. CSS & Browser Quirks
  7555.  
  7556. Summary
  7557. INTRODUCING CSS
  7558. X CSS treats each HTML element as if it appears inside
  7559. its own box and uses rules to indicate how that
  7560. element should look.
  7561. X Rules are made up of selectors (that specify the
  7562. elements the rule applies to) and declarations (that
  7563. indicate what these elements should look like).
  7564. X Different types of selectors allow you to target your
  7565. rules at different elements.
  7566. X Declarations are made up of two parts: the properties
  7567. of the element that you want to change, and the values
  7568. of those properties. For example, the font-family
  7569. property sets the choice of font, and the value arial
  7570. specifies Arial as the preferred typeface.
  7571. X CSS rules usually appear in a separate document,
  7572. although they may appear within an HTML page.
  7573.  
  7574. X How to specify colors
  7575. X Color terminology and contrast
  7576. X Background color
  7577. Color
  7578. 11
  7579. 247 COLOR
  7580. Color can really bring your pages to life.
  7581. In this chapter we will look at:
  7582. ● How to specify colors, as there are three common ways in
  7583. which you can indicate your choice of colors (plus extra
  7584. ways made available in CSS3)
  7585. ● Color terminology, as there are some terms that are very
  7586. helpful to understand when it comes to picking colors
  7587. ● Contrast, and ensuring that your text is readable
  7588. ● Background colors for behind either your entire page or
  7589. parts of a page
  7590. What you will learn about colors in this chapter will then be
  7591. used in subsequent chapters when it comes to looking at
  7592. colors of text and boxes in CSS.
  7593. COLOR 248
  7594. 249 COLOR
  7595. Result
  7596. /* color name */
  7597. h1 {
  7598. color: DarkCyan;}
  7599. /* hex code */
  7600. h2 {
  7601. color: #ee3e80;}
  7602. /* rgb value */
  7603. p {
  7604. color: rgb(100,100,90);}
  7605. chapter-11/foreground-color.html CSS
  7606. The color property allows you
  7607. to specify the color of text inside
  7608. an element. You can specify any
  7609. color in CSS in one of three ways:
  7610. rgb values
  7611. These express colors in terms
  7612. of how much red, green and
  7613. blue are used to make it up. For
  7614. example: rgb(100,100,90)
  7615. hex codes
  7616. These are six-digit codes that
  7617. represent the amount of red,
  7618. green and blue in a color,
  7619. preceded by a pound or hash #
  7620. sign. For example: #ee3e80
  7621. color names
  7622. There are 147 predefined color
  7623. names that are recognized
  7624. by browsers. For example:
  7625. DarkCyan
  7626. We look at these three different
  7627. ways of specifying colors on the
  7628. next double-page spread.
  7629. CSS3 has also introduced
  7630. another way to specify colors
  7631. called HSLA, which you will
  7632. meet near the end of this chapter
  7633. on page 255-256.
  7634. Foreground Color
  7635. color
  7636. Above each CSS rule in this
  7637. example you can see how CSS
  7638. allows you to add comments
  7639. to your CSS files. Anything
  7640. between the /* symbols and
  7641. the */ symbols will not be
  7642. interpreted by the browser.
  7643. They are shown in grey above.
  7644. The use of comments can help
  7645. you to understand a CSS file
  7646. (and organise it, by splitting a
  7647. long document into sections).
  7648. Here, we have used comments
  7649. to indicate which method is used
  7650. to specify each of the different
  7651. types of colors.
  7652. Article
  7653. COLOR 250
  7654. Result
  7655. body {
  7656. background-color: rgb(200,200,200);}
  7657. h1 {
  7658. background-color: DarkCyan;}
  7659. h2 {
  7660. background-color: #ee3e80;}
  7661. p {
  7662. background-color: white;}
  7663. CSS chapter-11/background-color.html
  7664. CSS treats each HTML element
  7665. as if it appears in a box, and the
  7666. background-color property
  7667. sets the color of the background
  7668. for that box.
  7669. You can specify your choice of
  7670. background color in the same
  7671. three ways you can specify
  7672. foreground colors: RGB values,
  7673. hex codes, and color names
  7674. (covered on the next page).
  7675. If you do not specify a
  7676. background color, then the
  7677. background is transparent.
  7678. By default, most browser
  7679. windows have a white
  7680. background, but browser users
  7681. can set a background color for
  7682. their windows, so if you want
  7683. to be sure that the background
  7684. is white you can use the
  7685. background-color property on
  7686. the <body> element.
  7687. We have also used the padding
  7688. property to separate the text
  7689. from the edges of the boxes.
  7690. This makes it easier to read and
  7691. you will learn more about this
  7692. property on page 313.
  7693. Background Color
  7694. background-color
  7695. 251 COLOR
  7696. Every color on a computer screen is created by mixing amounts of red,
  7697. green, and blue. To find the color you want, you can use a color picker.
  7698. Understanding Color
  7699. Computer monitors are made
  7700. up of thousands of tiny squares
  7701. called pixels (if you look very
  7702. closely at your monitor you
  7703. should be able to see them).
  7704. When the screen is not turned
  7705. on, it's black because it's not
  7706. emitting any light. When it's
  7707. on, each pixel can be a different
  7708. color, creating a picture.
  7709. The color of every pixel on the
  7710. screen is expressed in terms of
  7711. a mix of red, green, and blue —
  7712. just like on a television screen.
  7713. Color picking tools are available
  7714. in image editing programs like
  7715. Photoshop and GIMP. You can
  7716. see the RGB values specified
  7717. next to the radio buttons that
  7718. say R, G, B.
  7719. The hex value is provided
  7720. next to the pound or hash
  7721. # symbol. There is also a
  7722. good color picking tool at:
  7723. colorschemedesigner.com
  7724. COLOR 252
  7725. RGB Values
  7726. Values for red, green, and blue
  7727. are expressed as numbers
  7728. between 0 and 255.
  7729. rgb(102,205,170)
  7730. This color is made up of the
  7731. following values:
  7732. 102 red
  7733. 205 green
  7734. 170 blue
  7735. Hex Codes
  7736. Hex values represent values
  7737. for red, green, and blue in
  7738. hexadecimal code.
  7739. #66cdaa
  7740. The value of the red, 102, is
  7741. expressed as 66 in hexadecimal
  7742. code. The 205 of the green is
  7743. expressed as cd and the 170 of
  7744. the blue equates to aa.
  7745. Color Names
  7746. Colors are represented by
  7747. predefined names. However,
  7748. they are very limited in number.
  7749. MediumAquaMarine
  7750. There are 147 color names
  7751. supported by browsers (this
  7752. color is MediumAquaMarine).
  7753. Most consider this to be a
  7754. limited color palette, and it is
  7755. hard to remember the name for
  7756. each of the colors so (apart from
  7757. white and black) they are not
  7758. commonly used.
  7759. Hue
  7760. Hue is near to the colloquial idea
  7761. of color. Technically speaking
  7762. however, a color can also have
  7763. saturation and brightness as
  7764. well as hue.
  7765. Saturation
  7766. Saturation refers to the amount
  7767. of gray in a color. At maximum
  7768. saturation, there would be no
  7769. gray in the color. At minimum
  7770. saturation, the color would be
  7771. mostly gray.
  7772. Brightness
  7773. Brightness (or "value") refers
  7774. to how much black is in a color.
  7775. At maximum brightness, there
  7776. would be no black in the color.
  7777. At minimum brightness, the
  7778. color would be very dark.
  7779. 253 COLOR
  7780. Contrast
  7781. When picking foreground and background
  7782. colors, it is important to ensure that there is
  7783. enough contrast for the text to be legible.
  7784. Text is easier to read when
  7785. there is higher contrast between
  7786. background and foreground
  7787. colors.
  7788. If you want people to read a lot
  7789. of text on your page, however,
  7790. then too much contrast can
  7791. make it harder to read, too.
  7792. Low
  7793. Contrast
  7794. High
  7795. Contrast
  7796. Medium
  7797. Contrast
  7798. If text is reversed out (a light color on a dark background), you
  7799. can increase the height between lines and the weight of the font
  7800. to make it easier to read.
  7801. For long spans of text, reducing
  7802. the contrast a little bit improves
  7803. readability.
  7804. You can reduce contrast by
  7805. using dark gray text on a white
  7806. background or an off-white text
  7807. on a dark background.
  7808. Text is harder to read when
  7809. there is low contrast between
  7810. background and foreground
  7811. colors.
  7812. A lack of contrast is particularly
  7813. a problem for those with
  7814. visual impairments and color
  7815. blindness.
  7816. It also affects those with poor
  7817. monitors and sunlight on their
  7818. screens (which is increasingly
  7819. common as people use handheld
  7820. devices outdoors).
  7821. To check contrast there is a handy online tool at: www.snook.ca/technical/colour_contrast/colour.html
  7822. Article
  7823. COLOR 254
  7824. Result
  7825. p.one {
  7826. background-color: rgb(0,0,0);
  7827. opacity: 0.5;}
  7828. p.two {
  7829. background-color: rgb(0,0,0);
  7830. background-color: rgba(0,0,0,0.5);}
  7831. CSS chapter-11/opacity.html
  7832. CSS3 introduces the opacity
  7833. property which allows you to
  7834. specify the opacity of an element
  7835. and any of its child elements.
  7836. The value is a number between
  7837. 0.0 and 1.0 (so a value of 0.5
  7838. is 50% opacity and 0.15 is 15%
  7839. opacity).
  7840. The CSS3 rgba property allows
  7841. you to specify a color, just like
  7842. you would with an RGB value,
  7843. but adds a fourth value to
  7844. indicate opacity. This value is
  7845. known as an alpha value and is
  7846. a number between 0.0 and 1.0
  7847. (so a value of 0.5 is 50% opacity
  7848. and 0.15 is 15% opacity). The
  7849. rgba value will only affect the
  7850. element on which it is applied
  7851. (not child elements).
  7852. Because some browsers will
  7853. not recognize RGBA colors, you
  7854. can offer a fallback so that they
  7855. display a solid color. If there are
  7856. two rules that apply to the same
  7857. element, the latter of the two
  7858. will take priority. To create the
  7859. fallback, you can specify a color
  7860. as a hex code, color name or
  7861. RGB value, followed by the rule
  7862. that specifies an RGBA value. If
  7863. the browser understands RGBA
  7864. colors it will use that rule. If it
  7865. doesn't, it will use the RGB value.
  7866. At the time of writing, the
  7867. opacity and rgba properties
  7868. are only supported by the most
  7869. recent browsers.
  7870. CSS3: Opacity
  7871. opacity, rgba
  7872. Result in Older Browser
  7873. 255 COLOR
  7874. hue
  7875. Hue is the colloquial idea of
  7876. color. In HSL colors, hue is often
  7877. represented as a color circle
  7878. where the angle represents the
  7879. color, although it may also be
  7880. shown as a slider with values
  7881. from 0 to 360.
  7882. saturation
  7883. Saturation is the amount of
  7884. gray in a color. Saturation is
  7885. represented as a percentage.
  7886. 100% is full saturation and 0%
  7887. is a shade of gray.
  7888. lightness
  7889. Lightness is the amount of
  7890. white (lightness) or black
  7891. (darkness) in a color. Lightness
  7892. is represented as a percentage.
  7893. 0% lightness is black, 100%
  7894. lightness is white, and 50%
  7895. lightness is normal. Lightness
  7896. is sometimes referred to as
  7897. luminosity.
  7898. CSS3 introduces an entirely new and intuitive
  7899. way to specify colors using hue, saturation,
  7900. and lightness values.
  7901. CSS3: HSL Colors
  7902. Please note that lightness is a
  7903. different concept to brightness.
  7904. Graphic design software (such
  7905. as Photoshop and GIMP) have
  7906. color pickers that use hue,
  7907. saturation, and brightness —
  7908. but brightness only adds black,
  7909. whereas lightness offers both
  7910. white and black.
  7911. Article
  7912. COLOR 256
  7913. Result
  7914. body {
  7915. background-color: #C8C8C8;
  7916. background-color: hsl(0,0%,78%);}
  7917. p {
  7918. background-color: #ffffff;
  7919. background-color: hsla(0,100%,100%,0.5);}
  7920. CSS chapter-11/hsla.html
  7921. The hsl color property has
  7922. been introduced in CSS3 as an
  7923. alternative way to specify colors.
  7924. The value of the property starts
  7925. with the letters hsl, followed
  7926. by individual values inside
  7927. parentheses for:
  7928. hue
  7929. This is expressed as an angle
  7930. (between 0 and 360 degrees).
  7931. saturation
  7932. This is expressed as a
  7933. percentage.
  7934. lightness
  7935. This is expressed as a
  7936. percentage with 0% being white,
  7937. 50% being normal, and 100%
  7938. being black.
  7939. The hsla color property allows
  7940. you to specify color properties
  7941. using hue, saturation, and
  7942. lightness as above, and adds a
  7943. fourth value which represents
  7944. transparency (just like the rgba
  7945. property). The a stands for:
  7946. alpha
  7947. This is expressed as a
  7948. number between 0 and 1.0.
  7949. For example, 0.5 represents
  7950. 50% transparency, and 0.75
  7951. represents 75% transparency.
  7952. CSS3: HSL & HSLA
  7953. hsl, hsla
  7954. Because older browsers do not
  7955. recognize HSL and HSLA values,
  7956. it is a good idea to add an extra
  7957. rule which specifies the color
  7958. using a hex code, RGB value, or
  7959. color name. This should appear
  7960. before the rule that uses the HSL
  7961. or HSLA value.
  7962. This provides a fallback because
  7963. if there are two rules that apply
  7964. to the same element in CSS, the
  7965. latter of the two always takes
  7966. priority. This means that if the
  7967. browser understands HSL and
  7968. HSLA colors, it will use that rule;
  7969. and if it does not, it will use the
  7970. first rule.
  7971. 257 COLOR
  7972. Example
  7973. COLOR
  7974. COLOR 258
  7975. The rule for the <body> element sets a default color for all the text as
  7976. well as the default background color for the page. Both use color names.
  7977. The rule for the <h1> element sets the color of the heading using a hex
  7978. code. There are two values for the background-color property of the
  7979. <h1> element. The first provides a fallback color using a hex code and
  7980. the second is an HSLA value for browsers that support this method.
  7981. Each paragraph is then shown in a different color to represent the
  7982. varying levels of acidity or alkalinity, and these are specified using RGB
  7983. values.
  7984. The example also uses a property called margin to decrease the gap
  7985. between the paragraph boxes, and a property called padding to create
  7986. a gap between the edge of the boxes and the text within them. (These
  7987. properties are covered on pages 313-314.)
  7988. This example shows a pH scale to demonstrate
  7989. the different ways that colors can be specified
  7990. using CSS (using color names, hex codes, RGB,
  7991. and HSL).
  7992. 259 COLOR
  7993. Example
  7994. COLOR
  7995. <!DOCTYPE html>
  7996. <html>
  7997. <head>
  7998. <title>Color</title>
  7999. <style type="text/css">
  8000. body {
  8001. background-color: silver;
  8002. color: white;
  8003. padding: 20px;
  8004. font-family: Arial, Verdana, sans-serif;}
  8005. h1 {
  8006. background-color: #ffffff;
  8007. background-color: hsla(0,100%,100%,0.5);
  8008. color: #64645A;
  8009. padding: inherit;}
  8010. p {
  8011. padding: 5px;
  8012. margin: 0px;}
  8013. p.zero {
  8014. background-color: rgb(238,62,128);}
  8015. p.one {
  8016. background-color: rgb(244,90,139);}
  8017. p.two {
  8018. background-color: rgb(243,106,152);}
  8019. p.three {
  8020. background-color: rgb(244,123,166);}
  8021. p.four {
  8022. background-color: rgb(245,140,178);}
  8023. p.five {
  8024. background-color: rgb(246,159,192);}
  8025. p.six {
  8026. background-color: rgb(245,176,204);}
  8027. p.seven {
  8028. background-color: rgb(0,187,136);}
  8029. p.eight {
  8030. background-color: rgb(140,202,242);}
  8031. p.nine {
  8032. background-color: rgb(114,193,240);}
  8033. COLOR 260
  8034. Example
  8035. COLOR
  8036. p.ten {
  8037. background-color: rgb(84,182,237);}
  8038. p.eleven {
  8039. background-color: rgb(48,170,233);}
  8040. p.twelve {
  8041. background-color: rgb(0,160,230);}
  8042. p.thirteen {
  8043. background-color: rgb(0,149,226);}
  8044. p.fourteen {
  8045. background-color: rgb(0,136,221);}
  8046. </style>
  8047. </head>
  8048. <body>
  8049. <h1>pH Scale</h1>
  8050. <p class="fourteen">14.0 VERY ALKALINE</p>
  8051. <p class="thirteen">13.0</p>
  8052. <p class="twelve">12.0</p>
  8053. <p class="eleven">11.0</p>
  8054. <p class="ten">10.0</p>
  8055. <p class="nine">9.0</p>
  8056. <p class="eight">8.0</p>
  8057. <p class="seven">7.0 NEUTRAL</p>
  8058. <p class="six">6.0</p>
  8059. <p class="five">5.0</p>
  8060. <p class="four">4.0</p>
  8061. <p class="three">3.0</p>
  8062. <p class="two">2.0</p>
  8063. <p class="one">1.0</p>
  8064. <p class="zero">0.0 VERY ACID</p>
  8065. </body>
  8066. </html>
  8067.  
  8068. Summary
  8069. COLOR
  8070. X Color not only brings your site to life, but also helps
  8071. convey the mood and evokes reactions.
  8072. X There are three ways to specify colors in CSS:
  8073. RGB values, hex codes, and color names.
  8074. X Color pickers can help you find the color you want.
  8075. X It is important to ensure that there is enough contrast
  8076. between any text and the background color (otherwise
  8077. people will not be able to read your content).
  8078. X CSS3 has introduced an extra value for RGB colors to
  8079. indicate opacity. It is known as RGBA.
  8080. X CSS3 also allows you to specify colors as HSL values,
  8081. with an optional opacity value. It is known as HSLA.
  8082.  
  8083. X Size and typeface of text
  8084. X Bold, italics, capitals, underlines
  8085. X Spacing between lines, words, and letters
  8086. Text
  8087. 12
  8088. 265 TEXT
  8089. The properties that allow you to control
  8090. the appearance of text can be split into
  8091. two groups:
  8092. ● Those that directly affect the font and its appearance
  8093. (including the typeface, whether it is regular, bold or italic,
  8094. and the size of the text)
  8095. ● Those that would have the same effect on text no matter
  8096. what font you were using (including the color of text and
  8097. the spacing between words and letters)
  8098. The formatting of your text can have a significant effect
  8099. on how readable your pages are. As we look through these
  8100. properties I will also give you some design tips on how to
  8101. display your type.
  8102. TEXT 266
  8103. 267 TEXT
  8104. Typeface Terminology
  8105. Serif
  8106. Serif fonts have extra details on
  8107. the ends of the main strokes of
  8108. the letters. These details are
  8109. known as serifs.
  8110. In print, serif fonts were
  8111. traditionally used for long
  8112. passages of text because they
  8113. were considered easier to read.
  8114. Sans-Serif
  8115. Sans-serif fonts have straight
  8116. ends to letters, and therefore
  8117. have a much cleaner design.
  8118. Screens have a lower resolution
  8119. than print. So, if the text is small,
  8120. sans-serif fonts can be clearer
  8121. to read.
  8122. Monospace
  8123. Every letter in a monospace (or
  8124. fixed-width) font is the same
  8125. width. (Non-monospace fonts
  8126. have different widths.)
  8127. Monospace fonts are commonly
  8128. used for code because they align
  8129. nicely, making the text easier to
  8130. follow.
  8131. im im im
  8132. TEXT 268
  8133. Light
  8134. Medium
  8135. Bold
  8136. Black
  8137. Normal
  8138. Italic
  8139. Oblique
  8140. Condensed
  8141. Regular
  8142. Extended
  8143. The font weight not only adds
  8144. emphasis but can also affect
  8145. the amount of white space and
  8146. contrast on a page.
  8147.  
  8148. Italic fonts have a cursive aspect
  8149. to some of the lettering. Oblique
  8150. font styles take the normal style
  8151. and put it on an angle.
  8152. In condensed (or narrow)
  8153. versions of the font, letters are
  8154. thinner and closer together.
  8155. In expanded versions they are
  8156. thicker and further apart.
  8157. Weight Style Stretch
  8158. The xyz descender below the baseline
  8159. baseline line the letters sit on
  8160. x-height height of the letter x
  8161. cap height top of flat letters
  8162. ascender above the cap height
  8163. 269 TEXT
  8164. Choosing a Typeface
  8165. for your Website
  8166. When choosing
  8167. a typeface, it
  8168. is important to
  8169. understand that a
  8170. browser will usually
  8171. only display it if it's
  8172. installed on that
  8173. user's computer.
  8174. Serif
  8175. Serif fonts have extra details on
  8176. the end of the main strokes of
  8177. the letters.
  8178. Examples:
  8179. Georgia
  8180. Times
  8181. Times New Roman
  8182. Sans-Serif
  8183. Sans-serif fonts have straight
  8184. ends to letters and therefore
  8185. have a much cleaner design.
  8186. Examples:
  8187. Arial
  8188. Verdana
  8189. Helvetica
  8190. As a result, sites often use a small set of typefaces that are installed
  8191. on most computers (shown above). There are some techniques to get
  8192. around this limitation (which are covered on pages 271-272).
  8193. It is possible to specify more than one typeface and create an order of
  8194. preference (in case the user does not have your first choice of typeface
  8195. installed). This is sometimes referred to as a font stack.
  8196. TEXT 270
  8197. Monospace
  8198. Every letter in a monospace
  8199. typeface is the same width.
  8200. (Non-monospace fonts have
  8201. different widths.)
  8202. Examples:
  8203. Courier
  8204. Courier New
  8205. Cursive
  8206. Cursive fonts either have
  8207. joining strokes or other cursive
  8208. characteristics, such as
  8209. handwriting styles.
  8210. Examples:
  8211. Comic Sans MS
  8212. Monotype Corsiva
  8213. Fantasy
  8214. Fantasy fonts are usually
  8215. decorative fonts and are often
  8216. used for titles. They're not
  8217. designed for long bodies of text.
  8218. Examples:
  8219. Impact
  8220. Haettenschweiler
  8221. Browsers are supposed to support at least one typeface from each of
  8222. the groups above. For this reason, it is common to add the generic font
  8223. name after your preferred choice of typefaces.
  8224. For example, if you wanted serif type, you could write the following:
  8225. font-family: Georgia, Times, serif;
  8226. 271 TEXT
  8227. Techniques That Offer
  8228. a Wider Choice of
  8229. Typefaces
  8230. There are several ways to use fonts other than those listed on the
  8231. previous page. However, typefaces are subject to copyright, so the
  8232. techniques you can choose from are limited by their respective licenses.
  8233. Covered On
  8234. Issues
  8235. Licensing
  8236. Choice of Typefaces
  8237. Suitable for Any Length of Text
  8238. The user's computer needs the
  8239. typeface installed. CSS is used to
  8240. specify the typeface.
  8241. Pages 273-274
  8242. There is a limited choice of
  8243. typefaces that most users have
  8244. installed.
  8245. You are not distributing the
  8246. typeface, so there is no licensing
  8247. issue.
  8248. There is a limited choice because
  8249. the font needs to be installed on
  8250. users' computers.
  8251. CSS specifies where a font can
  8252. be downloaded from if it is not
  8253. installed on the computer.
  8254. Pages 277-278
  8255. The user has to download the
  8256. font file, which can slow down
  8257. loading of the web page.
  8258. The license to use the font must
  8259. permit its distribution using
  8260. @font-face.
  8261. Choice is limited because
  8262. few typefaces can be freely
  8263. distributed this way.
  8264. Commercial services give users
  8265. access to a wider range of fonts
  8266. using @font-face.
  8267. Pages 277-278
  8268. There is an ongoing fee to cover
  8269. licenses paid to font foundries.
  8270. The service takes care of the
  8271. licensing issues with the people
  8272. who made the font.
  8273. Each service offers a different
  8274. choice of fonts based on their
  8275. agreements with font foundries.
  8276. font-family font-face Service-based
  8277. Font-Face
  8278. TEXT 272
  8279. If you design on a Mac, it is important to check what the typefaces look
  8280. like on a PC because PCs can render type less smoothly. But if you design
  8281. on a PC, then it should look fine on a Mac.
  8282. Covered On
  8283. Issues
  8284. Licensing
  8285. Choice of Typefaces
  8286. Not suitable for long Passages of text
  8287. Images
  8288. You can create a graphic that
  8289. contains the text as you want it
  8290. to appear in a different typeface.
  8291. Pages 99-100 and 109-113
  8292. People who use screen readers
  8293. will rely on the alt text to know
  8294. what is said.
  8295. You can use any typeface that
  8296. you have a license to use on your
  8297. computer (because you are not
  8298. distributing the typeface).
  8299. Very wide choice because you
  8300. can use any typeface that you
  8301. have a license for.
  8302. SIFR
  8303. The font is embedded into a
  8304. Flash movie, and JavaScript
  8305. replaces specified HTML text
  8306. with a flash version of it.
  8307. See website for more details
  8308. This method only works if the
  8309. user has Flash and JavaScript
  8310. enabled on their device.
  8311. Many commercial makers of
  8312. typefaces allow this technique,
  8313. although you may need to pay
  8314. for an extra web-use license.
  8315. This method provides a lot of
  8316. choice because many of the
  8317. major typeface manufacturers
  8318. permit this kind of usage.
  8319. CUFON
  8320. Cufon offers similar functionality
  8321. to sIFR. It uses JavaScript to
  8322. create either an SVG or VML
  8323. version of the text.
  8324. See website for more details
  8325. Requires JavaScript to be
  8326. enabled. Also, users cannot
  8327. select text, and text can't change
  8328. when a user hovers over it.
  8329. As with sIFR, some typeface
  8330. makers allow use of their fonts
  8331. with CUFON, but you need to
  8332. check the license.
  8333. Slightly less choice than for sIFR,
  8334. as some typeface manufacturers
  8335. are not as keen on this
  8336. technique.
  8337. 273 TEXT
  8338. Result
  8339. <!DOCTYPE html>
  8340. <html>
  8341. <head>
  8342. <title>Font Family</title>
  8343. <style type="text/css">
  8344. body {
  8345. font-family: Georgia, Times, serif;}
  8346. h1, h2 {
  8347. font-family: Arial, Verdana, sans-serif;}
  8348. .credits {
  8349. font-family: "Courier New", Courier,
  8350. monospace;}
  8351. </style>
  8352. </head>
  8353. <body>
  8354. <h1>Briards</h1>
  8355. <p class="credits">by Ivy Duckett</p>
  8356. <p class="intro">The <a class="breed"
  8357. href="http://en.wikipedia.org/wiki/
  8358. Briard">briard</a>, or berger de brie, is
  8359. a large breed of dog traditionally used as
  8360. a herder and guardian of sheep...</p>
  8361. </body>
  8362. </html>
  8363. chapter-12/font-family.html CSS
  8364. The font-family property
  8365. allows you to specify the
  8366. typeface that should be used for
  8367. any text inside the element(s) to
  8368. which a CSS rule applies.
  8369. The value of this property is the
  8370. name of the typeface you want
  8371. to use.
  8372. The people who are visiting
  8373. your site need the typeface you
  8374. have specified installed on their
  8375. computer in order for it to be
  8376. displayed.
  8377. You can specify a list of fonts
  8378. separated by commas so that,
  8379. if the user does not have your
  8380. first choice of typeface installed,
  8381. the browser can try to use an
  8382. alternative font from the list.
  8383. It is also common to end with a
  8384. generic font name for that type
  8385. of font (which you saw on pages
  8386. 269-270).
  8387. If a font name is made up of
  8388. more than one word, it should be
  8389. put in double quotes.
  8390. Designers suggest pages usually
  8391. look better if they use no more
  8392. than three typefaces on a page.
  8393. We will be using an extended
  8394. version of the HTML shown on
  8395. this page for all of the examples
  8396. in this chapter.
  8397. Specifying Typefaces
  8398. font-family
  8399. HTML +
  8400. Article
  8401. TEXT 274
  8402. Result
  8403. The font-size property enables
  8404. you to specify a size for the
  8405. font. There are several ways to
  8406. specify the size of a font. The
  8407. most common are:
  8408. pixels
  8409. Pixels are commonly used
  8410. because they allow web
  8411. designers very precise control
  8412. over how much space their text
  8413. takes up. The number of pixels is
  8414. followed by the letters px.
  8415. percentages
  8416. The default size of text in
  8417. browsers is 16px. So a size of
  8418. 75% would be the equivalent of
  8419. 12px, and 200% would be 32px.
  8420. If you create a rule to make all
  8421. text inside the <body> element
  8422. to be 75% of the default size (to
  8423. make it 12px), and then specify
  8424. another rule that indicates the
  8425. content of an element inside the
  8426. <body> element should be 75%
  8427. size, it will be 9px (75% of the
  8428. 12px font size).
  8429. ems
  8430. An em is equivalent to the width
  8431. of a letter m.
  8432. We will look at these
  8433. measurements in greater detail
  8434. on the next page.
  8435. Size of Type
  8436. font-size
  8437. body {
  8438. font-family: Arial, Verdana, sans-serif;
  8439. font-size: 12px;}
  8440. h1 {
  8441. font-size: 200%;}
  8442. h2 {
  8443. font-size: 1.3em;}
  8444. CSS chapter-12/font-size.html
  8445. 275 TEXT
  8446. You may have noticed that programs such as
  8447. Word, Photoshop and InDesign offer the same
  8448. sizes of text.
  8449. Type Scales
  8450. 8pt
  8451. 9pt
  8452. 10pt
  8453. 11pt
  8454. 12pt
  8455. 14pt
  8456. 18pt
  8457. 24pt
  8458. 36pt
  8459. 48pt
  8460. 60pt
  8461. 72pt
  8462. This is because they are set
  8463. according to a scale or ratio that
  8464. was developed by European
  8465. typographers in the sixteenth
  8466. century.
  8467. It is considered that this scale
  8468. for type is pleasing to the eye
  8469. and it has therefore changed
  8470. little in the last 400 years.
  8471. For this reason, when you are
  8472. designing pages, using sizes
  8473. from this scale will help them
  8474. look more attractive.
  8475. On the next page, you can see
  8476. how to achieve this scale using
  8477. pixels, percentages, and ems.
  8478. Print designers often refer to the
  8479. size of text in terms of points
  8480. rather than pixels (hence the
  8481. use of pt in the scale on the
  8482. right). A pixel roughly equates
  8483. to a point because a point
  8484. corresponds to 1/72 of an inch,
  8485. and most computer displays
  8486. have a resolution of 72 dots per
  8487. inch.
  8488. The default size of text in a
  8489. browser is 16 pixels. So if you
  8490. use percentages or ems, you
  8491. calculate the size of text you
  8492. want based on the default size
  8493. of the text used in browsers.
  8494. For example, you could scale
  8495. down to 12 pixels for body copy
  8496. and scale up to 24 pixels for
  8497. headings.
  8498. Recently, some web designers
  8499. have started to leave the body
  8500. text at the default size of 16
  8501. pixels and adjust the other font
  8502. sizes using a scale that keeps
  8503. the relative proportions of this
  8504. one.
  8505. When you first see body text at
  8506. 16 pixels, it might seem quite
  8507. large. Once you get used to
  8508. the larger type, however, most
  8509. people find it far easier to read;
  8510. and going back to a page where
  8511. main type is 12 pixels will often
  8512. then look quite small.
  8513. TEXT 276
  8514. Units of Type Size
  8515. Setting font size in pixels is the
  8516. best way to ensure that the type
  8517. appears at the size you intended
  8518. (because percentages and ems
  8519. are more likely to vary if a user
  8520. has changed the default size of
  8521. text in their browser).
  8522. Pixels are relative to the
  8523. resolution of the screen, so the
  8524. same type size will look larger
  8525. when a screen has a resolution
  8526. of 800x600 than it would when
  8527. it is 1280x800.
  8528. You can also use pt for point
  8529. sizes instead of px for pixels, but
  8530. you should only do this when
  8531. creating style sheets for printerfriendly
  8532. versions of pages.
  8533. The default size of text in a
  8534. web browser is 16 pixels. Using
  8535. percentages of this amount, you
  8536. can create a scale where the
  8537. default text size is 12 pixels, and
  8538. headings are sized in relation
  8539. to this.
  8540. It is possible for users to change
  8541. the default size of text in their
  8542. web browsers. If they have
  8543. done this, the fonts will be
  8544. displayed at the same scale that
  8545. the designer intended, but at a
  8546. larger size.
  8547. Ems allow you to change the size
  8548. of text relative to the size of the
  8549. text in the parent element. Since
  8550. the default size of text in web
  8551. browsers is 16 pixels, you can
  8552. use similar rules to those shown
  8553. for percentages.
  8554. Because users can change
  8555. the default size of text in their
  8556. browser, the fonts could all
  8557. appear larger (or smaller) than
  8558. the designer intended.
  8559. The extra p rule above is to help
  8560. Internet Explorer 6 and 7 display
  8561. the fonts at the right size.
  8562. Without this extra rule, IE6 and
  8563. IE7 exaggerate the relative sizes
  8564. of other text.
  8565. Pixels Percentages Ems
  8566. h1
  8567. h2
  8568. h3
  8569. body
  8570. 24px
  8571. 18px
  8572. 14px
  8573. 12px
  8574. 200%
  8575. 150%
  8576. 117%
  8577. 75%
  8578. h1
  8579. h2
  8580. h3
  8581. body
  8582. 1.5em
  8583. 1.3em
  8584. 1.17em
  8585. 100%
  8586. 0.75em
  8587. h1
  8588. h2
  8589. h3
  8590. body
  8591. p
  8592. = =
  8593. 2em
  8594. 1.5em
  8595. 1.125em
  8596. 100%
  8597. 1em
  8598. h1
  8599. h2
  8600. h3
  8601. body
  8602. p
  8603. h1
  8604. h2
  8605. h3
  8606. body
  8607. 32px
  8608. 24px
  8609. 18px
  8610. 16px
  8611. 200%
  8612. 150%
  8613. 133%
  8614. 100%
  8615. h1
  8616. h2
  8617. h3
  8618. body
  8619. = =
  8620. Sixteen PIXEL SCALE
  8621. Twelve PIXEL SCALE
  8622. 277 TEXT
  8623. @font-face allows you to use
  8624. a font, even if it is not installed
  8625. on the computer of the person
  8626. browsing, by allowing you to
  8627. specify a path to a copy of the
  8628. font, which will be downloaded if
  8629. it is not on the user's machine.
  8630. Because this technique allows
  8631. a version of the font to be
  8632. downloaded to the user's
  8633. computer, it is important that the
  8634. license for the font permits it to
  8635. be used in this way.
  8636. You add the font to your style
  8637. sheet using the @font-face
  8638. rule, as shown on the right.
  8639. font-family
  8640. This specifies the name of the
  8641. font. This name can then be used
  8642. as a value of the font-family
  8643. property in the rest of the style
  8644. sheet (as shown in the rule for
  8645. the <h1> and <h2> elements).
  8646. src
  8647. This specifies the path to the
  8648. font. In order for this technique
  8649. to work in all browsers, you will
  8650. probably need to specify paths
  8651. to a few different versions of the
  8652. font, as shown on the next page.
  8653. format
  8654. This specifies the format that the
  8655. font is supplied in. (It's discussed
  8656. in detail on the next page.)
  8657. Result
  8658. @font-face {
  8659. font-family: 'ChunkFiveRegular';
  8660. src: url('fonts/chunkfive.eot');}
  8661. h1, h2 {
  8662. font-family: ChunkFiveRegular, Georgia, serif;}
  8663. chapter-12/font-face.html CSS
  8664. More Font Choice
  8665. @font-face
  8666. Many typeface makers do not
  8667. allow you to use their fonts in
  8668. this way, but there are open
  8669. source fonts you can use freely.
  8670. You can find lists of them at:
  8671. www.fontsquirrel.com
  8672. www.fontex.org
  8673. www.openfontlibrary.org
  8674. When looking at fonts on these
  8675. sites, it is still important to check
  8676. the font's license agreement
  8677. because some fonts are only free
  8678. for personal use (that is, not for
  8679. use on commercial websites).
  8680. There are some sites that give
  8681. you access to use commercial
  8682. fonts, because they negotiated
  8683. permission to let their customers
  8684. use these fonts for a fee:
  8685. www.typekit.com
  8686. www.kernest.com
  8687. www.fontspring.com
  8688. Google also provides open
  8689. source fonts. Rather than adding
  8690. the @font-face rule to your own
  8691. style sheet, you link to a CSS file
  8692. and font files on their servers:
  8693. www.google.com/webfonts
  8694. Article
  8695. TEXT 278
  8696. @font-face {
  8697. font-family: 'ChunkFiveRegular';
  8698. src: url('fonts/chunkfive.eot');
  8699. src: url('fonts/chunkfive.eot?#iefix')
  8700. format('embedded-opentype'),
  8701. url('fonts/chunkfive.woff') format('woff'),
  8702. url('fonts/chunkfive.ttf')
  8703. format('truetype'),
  8704. url('fonts/chunkfive.svg#ChunkFiveRegular')
  8705. format('svg');}
  8706. CSS chapter-12/understanding-font-formats.html Different browsers support
  8707. different formats for fonts
  8708. (in the same way that they
  8709. support different audio and
  8710. video formats), so you will need
  8711. to supply the font in several
  8712. variations to reach all browsers.
  8713. If you do not have all of these
  8714. formats for your font, you can
  8715. upload the font to a website
  8716. called FontSquirrel where they
  8717. will convert it for you:
  8718. www.fontsquirrel.com/
  8719. fontface/generator
  8720. Font Squirrel also provides you
  8721. with the CSS code for the
  8722. @font-face rule. This is very
  8723. helpful because, when you
  8724. are dealing with multiple font
  8725. formats, the src and format
  8726. properties of the @font-face
  8727. rule can get rather complicated.
  8728. You can see an example of a
  8729. more complicated @font-face
  8730. rule on the left.
  8731. The various font formats should
  8732. appear in your code in this order:
  8733. 1: eot
  8734. 2: woff
  8735. 3: ttf/otf
  8736. 4: svg
  8737. Understanding
  8738. Font Formats
  8739. Browser FORMAT
  8740. eot woff ttf / otf svg
  8741. Chrome (all)
  8742. Chrome 6+
  8743. Firefox 3.5
  8744. Firefox 3.6+
  8745. IE 5 - 8
  8746. IE 9+
  8747. Opera 10+
  8748. Safari 3.1+
  8749. iOS <4.2
  8750. iOS 4.2+
  8751. Because the browser needs to
  8752. download the font file in order
  8753. to show it, users might see
  8754. something known as a Flash of
  8755. Unstyled Content (FOUC) or
  8756. Flash of Unstyled Text (FOUT).
  8757. Two things you can do to try to
  8758. minimize this behavior are to
  8759. delete any unneccesary glyphs
  8760. from the font and/or host the
  8761. font on a Content Delivery
  8762. Network (a special type of web
  8763. hosting that offers faster delivery
  8764. of files).
  8765. 279 TEXT
  8766. Result
  8767. .credits {
  8768. font-weight: bold;}
  8769. chapter-12/font-weight.html CSS
  8770. The font-weight property
  8771. allows you to create bold text.
  8772. There are two values that this
  8773. property commonly takes:
  8774. normal
  8775. This causes text to appear at a
  8776. normal weight.
  8777. bold
  8778. This causes text to appear bold.
  8779. In this example, you can see
  8780. that the element whose class
  8781. attribute has a value of credits
  8782. has been bolded.
  8783. You might wonder why there is
  8784. a normal weight. This is because
  8785. if, for example, you created a
  8786. rule for the <body> element
  8787. indicating that all text inside the
  8788. body should appear bold, you
  8789. might need an option that allows
  8790. the text in certain instances
  8791. to appear normal weight. So
  8792. it is essentially used as an "off
  8793. switch."
  8794. Bold
  8795. font-weight
  8796. Article
  8797. TEXT 280
  8798. If you want to create italic text,
  8799. you can use the font-style
  8800. property. There are three values
  8801. this property can take:
  8802. normal
  8803. This causes text to appear in a
  8804. normal style (as opposed to italic
  8805. or oblique).
  8806. italic
  8807. This causes text to appear italic.
  8808. oblique
  8809. This causes text to appear
  8810. oblique.
  8811. In this example, you can see that
  8812. the credits have been italicized.
  8813. Italic fonts were traditionally
  8814. stylized versions of the font
  8815. based on calligraphy, whereas an
  8816. oblique version would take the
  8817. normal version and put it on an
  8818. angle.
  8819. It is not unusual for the browser
  8820. to fail to find an italic version of a
  8821. typeface, in which case it will use
  8822. an algorithm to place the normal
  8823. version of the type on a slant,
  8824. which means that a lot of italic
  8825. text online is actually oblique.
  8826. Italic
  8827. font-style
  8828. Result
  8829. .credits {
  8830. font-style: italic;}
  8831. CSS chapter-12/font-style.html
  8832. 281 TEXT
  8833. Result
  8834. h1 {
  8835. text-transform: uppercase;}
  8836. h2 {
  8837. text-transform: lowercase;}
  8838. .credits {
  8839. text-transform: capitalize;}
  8840. chapter-12/text-transform.html CSS
  8841. The text-transform property
  8842. is used to change the case of
  8843. text giving it one of the following
  8844. values:
  8845. uppercase
  8846. This causes the text to appear
  8847. uppercase.
  8848. lowercase
  8849. This causes the text to appear
  8850. lowercase.
  8851. capitalize
  8852. This causes the first letter of
  8853. each word to appear capitalized.
  8854. In this example, the <h1>
  8855. element is uppercase, the <h2>
  8856. element is lowercase, and the
  8857. credits are capitalized. In the
  8858. HTML, the word by in the credits
  8859. had a lowercase b.
  8860. If you do utilize the uppercase
  8861. option, it is worth looking at
  8862. the letter-spacing property
  8863. to increase the gap between
  8864. each letter as shown on page
  8865. 284. This will help improve
  8866. readability.
  8867. UpperCase &
  8868. LowerCase
  8869. text-transform
  8870. Article
  8871. TEXT 282
  8872. Result
  8873. .credits {
  8874. text-decoration: underline;}
  8875. a {
  8876. text-decoration: none;}
  8877. CSS chapter-12/text-decoration.html
  8878. The text-decoration property
  8879. allows you to specify the
  8880. following values:
  8881. none
  8882. This removes any decoration
  8883. already applied to the text.
  8884. underline
  8885. This adds a line underneath the
  8886. text.
  8887. overline
  8888. This adds a line over the top of
  8889. the text.
  8890. line-through
  8891. This adds a line through words.
  8892. blink
  8893. This animates the text to make it
  8894. flash on and off (however this is
  8895. generally frowned upon, as it is
  8896. considered rather annoying).
  8897. In this example, the credits have
  8898. been underlined. Also, the name
  8899. of the breed (which is a link) is
  8900. not underlined, which it would
  8901. be by default because it is a link.
  8902. This property is commonly
  8903. used by designers to remove
  8904. the underlines that browsers
  8905. place under links. Pages 290-291
  8906. show how to add or remove an
  8907. underline when a user hovers
  8908. over a link.
  8909. Underline & Strike
  8910. text-decoration
  8911. 283 TEXT
  8912. Result
  8913. p {
  8914. line-height: 1.4em;}
  8915. chapter-12/line-height.html CSS Leading (pronounced ledding) is
  8916. a term typographers use for the
  8917. vertical space between lines of
  8918. text. In a typeface, the part of
  8919. a letter that drops beneath the
  8920. baseline is called a descender,
  8921. while the highest point of a letter
  8922. is called the ascender. Leading
  8923. is measured from the bottom of
  8924. the descender on one line to the
  8925. top of the ascender on the next.
  8926. hey there
  8927. hey there
  8928. In CSS, the line-height
  8929. property sets the height of
  8930. an entire line of text, so the
  8931. difference between the fontsize
  8932. and the line-height is
  8933. equivalent to the leading (as
  8934. shown in the diagram above).
  8935. Increasing the line-height
  8936. makes the vertical gap between
  8937. lines of text larger.
  8938. Leading
  8939. line-height
  8940. leading
  8941. font-size line-height
  8942. Increasing the default amount of
  8943. leading can make text easier to
  8944. read. The vertical space between
  8945. lines should be larger than the
  8946. space between each word as this
  8947. helps the eye move along the line
  8948. instead of down them. A good
  8949. starter setting is around 1.4 to
  8950. 1.5em. Because users can adjust
  8951. the default size of text in their
  8952. browser, the value of the lineheight
  8953. property is best given in
  8954. ems, not pixels, so that the gap
  8955. between lines is relative to the
  8956. size of text the user has selected.
  8957. Result Minus CSS
  8958. Article
  8959. TEXT 284
  8960. Result
  8961. h1, h2 {
  8962. text-transform: uppercase;
  8963. letter-spacing: 0.2em;}
  8964. .credits {
  8965. font-weight: bold;
  8966. word-spacing: 1em;}
  8967. CSS chapter-12/letter-and-word-spacing.html Kerning is the term
  8968. typographers use for the space
  8969. between each letter. You can
  8970. control the space between each
  8971. letter with the letter-spacing
  8972. property.
  8973. It is particularly helpful to
  8974. increase the kerning when
  8975. your heading or sentence is
  8976. all in uppercase. If your text is
  8977. in sentence (or normal) case,
  8978. increasing or decreasing the
  8979. kerning can make it harder to
  8980. read.
  8981. You can also control the gap
  8982. between words using the
  8983. word-spacing property.
  8984. When you specify a value for
  8985. these properties, it should
  8986. be given in ems, and it will be
  8987. added on top of the default value
  8988. specified by the font.
  8989. The default gap between
  8990. words is set by the typeface
  8991. (often around 0.25em), and
  8992. it is unlikely that you would
  8993. need to change this property
  8994. regularly. If the typeface is bold
  8995. or you have increased the space
  8996. between letters, then a larger
  8997. gap between words can increase
  8998. readability.
  8999. Letter & Word Spacing
  9000. letter-spacing, word-spacing
  9001. Result Minus CSS
  9002. 285 TEXT
  9003. Result
  9004. h1 {
  9005. text-align: left;}
  9006. p {
  9007. text-align: justify;}
  9008. .credits {
  9009. text-align: right;}
  9010. chapter-12/text-align.html CSS
  9011. The text-align property allows
  9012. you to control the alignment of
  9013. text. The property can take one
  9014. of four values:
  9015. left
  9016. This indicates that the text
  9017. should be left-aligned.
  9018. right
  9019. This indicates that the text
  9020. should be right-aligned.
  9021. center
  9022. This allows you to center text.
  9023. justify
  9024. This indicates that every line in
  9025. a paragraph, except the last line,
  9026. should be set to take up the full
  9027. width of the containing box.
  9028. When you have several
  9029. paragraphs of text, it is
  9030. considered easiest to read if the
  9031. text is left-aligned.
  9032. Justified text looks at the words
  9033. on each individual line and
  9034. creates an equal gap between
  9035. those words. It can look odd
  9036. if you end up with large gaps
  9037. between some words and
  9038. smaller gaps between others.
  9039. This often happens when your
  9040. lines are not very wide or when
  9041. your text contains long words.
  9042. Alignment
  9043. text-align
  9044. Article
  9045. TEXT 286
  9046. Result
  9047. The vertical-align property is
  9048. a common source of confusion.
  9049. It is not intended to allow you to
  9050. vertically align text in the middle
  9051. of block level elements such as
  9052. <p> and <div>, although it does
  9053. have this effect when used with
  9054. table cells (the <td> and <th>
  9055. elements).
  9056. It is more commonly used with
  9057. inline elements such as <img>,
  9058. <em>, or <strong> elements.
  9059. When used with these elements,
  9060. it performs a task very similar to
  9061. the HTML align attribute used
  9062. on the <img> element, which
  9063. you met on pages 103-106. The
  9064. values it can take are:
  9065. baseline
  9066. sub
  9067. super
  9068. top
  9069. text-top
  9070. middle
  9071. bottom
  9072. text-bottom
  9073. It can also take a length (usually
  9074. specified in pixels or ems) or a
  9075. percentage of the line height.
  9076. Vertical Alignment
  9077. vertical-align
  9078. #six-months {
  9079. vertical-align: text-top;}
  9080. #one-year {
  9081. vertical-align: baseline;}
  9082. #two-years {
  9083. vertical-align: text-bottom;}
  9084. CSS chapter-12/vertical-align.html
  9085. 287 TEXT
  9086. The text-indent property
  9087. allows you to indent the first
  9088. line of text within an element.
  9089. The amount you want the line
  9090. indented by can be specified in
  9091. a number of ways but is usually
  9092. given in pixels or ems.
  9093. It can take a negative value,
  9094. which means it can be used
  9095. to push text off the browser
  9096. window. You can see this
  9097. technique used in this example,
  9098. where the <h1> element uses a
  9099. background image to represent
  9100. the heading. The text has been
  9101. moved far to the left, off the
  9102. screen. (Background images are
  9103. covered on pages 413-418.)
  9104. We still want the heading text
  9105. to be on the page (for search
  9106. engines and those who cannot
  9107. see the image), but we cannot
  9108. have it displayed on top of the
  9109. logo or it will be unreadable. By
  9110. pushing it 9,999 pixels to the
  9111. left, it is way out of sight but still
  9112. in the HTML code.
  9113. The second rule in this example
  9114. indents the credits 20 pixels to
  9115. the right.
  9116. Result
  9117. h1 {
  9118. background-image: url("images/logo.gif");
  9119. background-repeat: no-repeat;
  9120. text-indent: -9999px;}
  9121. .credits {
  9122. text-indent: 20px;}
  9123. chapter-12/text-indent.html CSS
  9124. Indenting Text
  9125. text-indent
  9126. Article
  9127. TEXT 288
  9128. Result
  9129. p.one {
  9130. background-color: #eeeeee;
  9131. color: #666666;
  9132. text-shadow: 1px 1px 0px #000000;}
  9133. p.two {
  9134. background-color: #dddddd;
  9135. color: #666666;
  9136. text-shadow: 1px 1px 3px #666666;}
  9137. p.three {
  9138. background-color: #cccccc;
  9139. color: #ffffff;
  9140. text-shadow: 2px 2px 7px #111111;}
  9141. p.four {
  9142. background-color: #bbbbbb;
  9143. color: #cccccc;
  9144. text-shadow: -1px -2px #666666;}
  9145. p.five {
  9146. background-color: #aaaaaa;
  9147. color: #ffffff;
  9148. text-shadow: -1px -1px #666666;}
  9149. CSS chapter-12/text-shadow.html
  9150. The text-shadow property has
  9151. become commonly used despite
  9152. lacking support in all browsers.
  9153. It is used to create a drop
  9154. shadow, which is a dark version
  9155. of the word just behind it and
  9156. slightly offset. It can also be used
  9157. to create an embossed effect by
  9158. adding a shadow that is slightly
  9159. lighter than the text.
  9160. The value of this property is
  9161. quite complicated because it can
  9162. take three lengths and a color for
  9163. the drop shadow.
  9164. The first length indicates how
  9165. far to the left or right the shadow
  9166. should fall.
  9167. The second value indicates the
  9168. distance to the top or bottom
  9169. that the shadow should fall.
  9170. The third value is optional and
  9171. specifies the amount of blur that
  9172. should be applied to the drop
  9173. shadow.
  9174. The fourth value is the color of
  9175. the drop shadow.
  9176. The text-shadow property
  9177. has become very popular but
  9178. at the time of writing it was
  9179. not supported in any versions
  9180. of Internet Explorer (currently
  9181. IE9). Other browser makers
  9182. introduced it in Firefox 3.1, Safari
  9183. 3, Chrome 2 and Opera 9.5.
  9184. CSS3: Drop Shadow
  9185. text-shadow
  9186. 289 TEXT
  9187. Result
  9188. You can specify different values
  9189. for the first letter or first line of
  9190. text inside an element using
  9191. :first-letter and
  9192. :first-line.
  9193. Technically these are not
  9194. properties. They are known as
  9195. pseudo-elements.
  9196. You specify the pseudo-element
  9197. at the end of the selector, and
  9198. then specify the declarations as
  9199. you would normally for any other
  9200. element.
  9201. It is worth trying this example in
  9202. your browser so that you can see
  9203. how the first-line pseudoelement
  9204. will only affect the first
  9205. line of text, even if you resize
  9206. your browser window and less or
  9207. more words appear on each line.
  9208. p.intro:first-letter {
  9209. font-size: 200%;}
  9210. p.intro:first-line {
  9211. font-weight: bold;}
  9212. chapter-12/first-letter-and-line.html CSS
  9213. First Letter or Line
  9214. :first-letter, :first-line
  9215. CSS introduces both pseudoelements
  9216. and pseudo-classes.
  9217. A pseudo-element acts like an
  9218. extra element is in the code. In
  9219. the case of the :first-letter
  9220. and :first-line pseudo
  9221. elements, it is as if there is an
  9222. extra element around the first
  9223. letter or the first line which can
  9224. have its own styles applied.
  9225. A pseudo-class acts like an
  9226. extra value for a class attribute.
  9227. In the case of the :visited
  9228. pseudo-class, which you meet
  9229. on the next page, it allows you
  9230. to have different styles for links
  9231. that have been visited. Similarly,
  9232. the :hover pseudo-class allows
  9233. you to style elements differently
  9234. when a user hovers over them.
  9235. Article
  9236. TEXT 290
  9237. Browsers tend to show links
  9238. in blue with an underline by
  9239. default, and they will change
  9240. the color of links that have been
  9241. visited to help users know which
  9242. pages they have been to.
  9243. In CSS, there are two pseudoclasses
  9244. that allow you to set
  9245. different styles for links that
  9246. have and have not yet been
  9247. visited.
  9248. :link
  9249. This allows you to set styles
  9250. for links that have not yet been
  9251. visited.
  9252. :visited
  9253. This allows you to set styles for
  9254. links that have been clicked on.
  9255. They are commonly used to
  9256. control colors of the links and
  9257. also whether they are to appear
  9258. underlined or not.
  9259. On the left, you can see that
  9260. visited links are shown in a
  9261. different color to help visitors
  9262. know what they have already
  9263. seen.
  9264. Often, the :hover and :active
  9265. pseudo-classes (covered on the
  9266. next page) are used to alter the
  9267. appearance of a link when a user
  9268. hovers over or clicks on it.
  9269. Result
  9270. a:link {
  9271. color: deeppink;
  9272. text-decoration: none;}
  9273. a:visited {
  9274. color: black;}
  9275. a:hover {
  9276. color: deeppink;
  9277. text-decoration: underline;}
  9278. a:active {
  9279. color: darkcyan;}
  9280. CSS chapter-12/link-visited.html
  9281. Styling Links
  9282. :link, :visited
  9283. 291 TEXT
  9284. Result
  9285. input {
  9286. padding: 6px 12px 6px 12px;
  9287. border: 1px solid #665544;
  9288. color: #ffffff;}
  9289. input.submit:hover {
  9290. background-color: #665544;}
  9291. input.submit:active {
  9292. background-color: chocolate;}
  9293. input.text {
  9294. color: #cccccc;}
  9295. input.text:focus {
  9296. color: #665544;}
  9297. chapter-12/hover-active-focus.html CSS There are three pseudo-classes
  9298. that allow you to change the
  9299. appearance of elements when a
  9300. user is interacting with them.
  9301. :hover
  9302. This is applied when a user
  9303. hovers over an element with a
  9304. pointing device such as a mouse.
  9305. This has commonly been used
  9306. to change the appearance of
  9307. links and buttons when a user
  9308. places their cursor over them. It
  9309. is worth noting that such events
  9310. do not work on devices that use
  9311. touch screens (such as the iPad)
  9312. because the screen is not able to
  9313. tell when someone is hovering
  9314. their finger over an element.
  9315. :active
  9316. This is applied when an element
  9317. is being activated by a user; for
  9318. example, when a button is being
  9319. pressed or a link being clicked.
  9320. Sometimes this is used to make
  9321. a button or link feel more like it
  9322. is being pressed by changing the
  9323. style or position of the element
  9324. slightly.
  9325. :focus
  9326. This is applied when an element
  9327. has focus. Any element that
  9328. you can interact with, such as a
  9329. link you can click on or any form
  9330. control can have focus.
  9331. Responding to Users
  9332. :hover, :active, :focus
  9333. Focus occurs when a browser
  9334. discovers that you are ready to
  9335. interact with an element on the
  9336. page. For example, when your
  9337. cursor is in a form input ready
  9338. to accept typing, that element
  9339. is said to have focus. It is also
  9340. possible to use the tab key on
  9341. your keyboard to move through
  9342. the interactive items on a page.
  9343. When pseudo-classes are
  9344. used, they should appear in this
  9345. order: :link, :visited, :hover,
  9346. :focus, :active.
  9347. TEXT 292
  9348. You met the most popular CSS selectors on page 238. There are also
  9349. a set of attribute selectors that allow you to create rules that apply to
  9350. elements that have an attribute with a specific value.
  9351. Attribute Selectors
  9352. Selector Meaning Example
  9353. p[class]
  9354. Targets any <p> element with an
  9355. attribute called class
  9356. p[class="dog"]
  9357. Targets any <p> element with
  9358. an attribute called class whose
  9359. value is dog
  9360. p[class~="dog"]
  9361. Targets any <p> element with
  9362. an attribute called class whose
  9363. value is a list of space-separated
  9364. words, one of which is dog
  9365. p[attr^"d"]
  9366. Targets any <p> element with
  9367. an attribute whose value begins
  9368. with the letter "d"
  9369. p[attr*"do"]
  9370. Targets any <p> element with an
  9371. attribute whose value contains
  9372. the letters "do"
  9373. p[attr$"g"]
  9374. Targets any <p> element with an
  9375. attribute whose value ends with
  9376. the letter "g"
  9377. []
  9378. Matches a specific attribute
  9379. (whatever its value)
  9380. [=]
  9381. Matches a specific attribute with
  9382. a specific value
  9383. [~=]
  9384. Matches a specific attribute
  9385. whose value appears in a spaceseparated
  9386. list of words
  9387. [^=]
  9388. Matches a specific attribute
  9389. whose value begins with a
  9390. specific string
  9391. [*=]
  9392. Matches a specific attribute
  9393. whose value contains a specific
  9394. substring
  9395. [$=]
  9396. Matches a specific attribute
  9397. whose value ends with a specific
  9398. string
  9399. Existence
  9400. Equality
  9401. Space
  9402. Prefix
  9403. SubString
  9404. Suffix
  9405. 293 TEXT
  9406. Example
  9407. TEXT
  9408. TEXT 294
  9409. This example combines many of the techniques
  9410. shown in this chapter.
  9411. The sizes of fonts are controlled using the font-size property. The
  9412. headings are changed from bold to normal using the font-weight
  9413. property. We have also specified different choices of font using the
  9414. font-family property.
  9415. The <h1> element uses the CSS3 text-shadow property to create the
  9416. drop shadow behind it. The <h2> element is converted to uppercase
  9417. using the text-transform property, and to make the uppercase text
  9418. easier to read, we have increased the space between each letter using
  9419. the letter-spacing property.
  9420. For the main body text, we have increased the line-height property so
  9421. there is a bigger gap between each line of text, thereby making it easier
  9422. to read. In the first paragraph, the first-line pseudo-element allows
  9423. us to style the first line of the introduction in bold. Finally, the credit is
  9424. italicized and aligned to the right-hand side of the page.
  9425. 295 TEXT
  9426. Example
  9427. TEXT
  9428. <!DOCTYPE html>
  9429. <html>
  9430. <head>
  9431. <title>Text</title>
  9432. <style type="text/css">
  9433. body {
  9434. padding: 20px;}
  9435. h1, h2, h3, a {
  9436. font-weight: normal;
  9437. color: #0088dd;
  9438. margin: 0px;}
  9439. h1 {
  9440. font-family: Georgia, Times, serif;
  9441. font-size: 250%;
  9442. text-shadow: 2px 2px 3px #666666;
  9443. padding-bottom: 10px;}
  9444. h2 {
  9445. font-family: "Gill Sans", Arial, sans-serif;
  9446. font-size: 90%;
  9447. text-transform: uppercase;
  9448. letter-spacing: 0.2em;}
  9449. h3 {
  9450. font-size: 150%;}
  9451. p {
  9452. font-family: Arial, Verdana, sans-serif;
  9453. line-height: 1.4em;
  9454. color: #665544;}
  9455. p.intro:first-line {
  9456. font-weight: bold;}
  9457. .credits {
  9458. font-style: italic;
  9459. text-align: right;}
  9460. a {
  9461. text-decoration: none;}
  9462. a:hover {
  9463. text-decoration: underline;}
  9464. </style>
  9465. </head>
  9466. TEXT 296
  9467. Example
  9468. TEXT
  9469. <body>
  9470. <h1>Briards</h1>
  9471. <h2>A Heart wrapped in fur</h2>
  9472. <p class="intro">The <a class="breed" href="http://en.wikipedia.org/wikiBriard">
  9473. briard</a>, or berger de brie, is a large breed of dog traditionally used as a
  9474. herder and guardian of sheep.</p>
  9475. <h3>Breed History</h3>
  9476. <p>The briard, which is believed to have originated in France, has been bred for
  9477. centuries to herd and to protect sheep. The breed was used by the French Army as
  9478. sentries, messengers and to search for wounded soldiers because of its fine sense
  9479. of hearing. Briards were used in the First World War almost to the point of
  9480. extinction. Currently the population of briards is slowly recovering.
  9481. Charlemagne, Napoleon, Thomas Jefferson and Lafayette all owned briards.</p>
  9482. <p class="credits">by Ivy Duckett</p>
  9483. </body>
  9484. </html>
  9485.  
  9486. Summary
  9487. TEXT
  9488. X There are properties to control the choice of font, size,
  9489. weight, style, and spacing.
  9490. X There is a limited choice of fonts that you can assume
  9491. most people will have installed.
  9492. X If you want to use a wider range of typefaces there are
  9493. several options, but you need to have the right license
  9494. to use them.
  9495. X You can control the space between lines of text,
  9496. individual letters, and words. Text can also be aligned
  9497. to the left, right, center, or justified. It can also be
  9498. indented.
  9499. X You can use pseudo-classes to change the style of an
  9500. element when a user hovers over or clicks on text, or
  9501. when they have visited a link.
  9502.  
  9503. Boxes
  9504. X Controlling size of boxes
  9505. X Box model for borders, margin and padding
  9506. X Displaying and hiding boxes
  9507. 13
  9508. 301 BOXES
  9509. At the beginning of this section on CSS,
  9510. you saw how CSS treats each HTML
  9511. element as if it lives in its own box.
  9512. You can set several properties that affect the appearance of
  9513. these boxes. In this chapter you will see how to:
  9514. ● Control the dimensions of your boxes
  9515. ● Create borders around boxes
  9516. ● Set margins and padding for boxes
  9517. ● Show and hide boxes
  9518. Once you have learned how to control the appearance of each
  9519. box, you will see how to position these boxes on your pages in
  9520. Chapter 15 when we look at page layout.
  9521. BOXES 302
  9522. 303 BOXES
  9523. Article
  9524. Result
  9525. div.box {
  9526. height: 300px;
  9527. width: 300px;
  9528. background-color: #bbbbaa;}
  9529. p {
  9530. height: 75%;
  9531. width: 75%;
  9532. background-color: #0088dd;}
  9533. <div>
  9534. <p>The Moog company pioneered the commercial
  9535. manufacture of modular voltage-controlled
  9536. analog synthesizer systems in the early
  9537. 1950s.</p>
  9538. </div>
  9539. chapter-13/width-height.html HTML By default a box is sized just big
  9540. enough to hold its contents. To
  9541. set your own dimensions for a
  9542. box you can use the height and
  9543. width properties.
  9544. The most popular ways to
  9545. specify the size of a box are
  9546. to use pixels, percentages, or
  9547. ems. Traditionally, pixels have
  9548. been the most popular method
  9549. because they allow designers to
  9550. accurately control their size.
  9551. When you use percentages,
  9552. the size of the box is relative to
  9553. the size of the browser window
  9554. or, if the box is encased within
  9555. another box, it is a percentage of
  9556. the size of the containing box.
  9557. When you use ems, the size
  9558. of the box is based on the size
  9559. of text within it. Designers
  9560. have recently started to use
  9561. percentages and ems more for
  9562. measurements as they try to
  9563. create designs that are flexible
  9564. across devices which have
  9565. different-sized screens.
  9566. In the example on the right, you
  9567. can see that a containing <div>
  9568. element is used which is 300
  9569. pixels wide by 300 pixels high.
  9570. Inside of this is a paragraph
  9571. that is 75% of the width and
  9572. height of the containing element.
  9573. This means that the size of the
  9574. paragraph is 225 pixels wide by
  9575. 225 pixels high.
  9576. Box Dimensions
  9577. width, height
  9578. CSS
  9579. Article
  9580. BOXES 304
  9581. Some page designs expand and
  9582. shrink to fit the size of the user's
  9583. screen. In such designs, the
  9584. min-width property specifies
  9585. the smallest size a box can be
  9586. displayed at when the browser
  9587. window is narrow, and the
  9588. max-width property indicates
  9589. the maximum width a box can
  9590. stretch to when the browser
  9591. window is wide.
  9592. These are very helpful properties
  9593. to ensure that the content of
  9594. pages are legible (especially on
  9595. the smaller screens of handheld
  9596. devices). For example, you can
  9597. use the max-width property to
  9598. ensure that lines of text do not
  9599. appear too wide within a big
  9600. browser window and you can
  9601. use the min-width property
  9602. to make sure that they do not
  9603. appear too narrow.
  9604. You may find it helpful to try this
  9605. example out in your browser so
  9606. that you can see what happens
  9607. when you increase or decrease
  9608. the size of the browser window.
  9609. Please note that these properties
  9610. were first supported in IE7 and
  9611. Firefox 2 so they will not work in
  9612. older versions of these browsers.
  9613. Result
  9614. td.description {
  9615. min-width: 450px;
  9616. max-width: 650px;
  9617. text-align: left;
  9618. padding: 5px;
  9619. margin: 0px;}
  9620. CSS
  9621. <tr>
  9622. <td><img src="images/rhodes.jpg" width="200"
  9623. height="100" alt="Fender Rhodes" /></td>
  9624. <td class="description">The Rhodes piano is an
  9625. electro-mechanical piano, invented by Harold
  9626. Rhodes during the fifties and later
  9627. manufactured in a number of models ...</td>
  9628. <td>$1400</td>
  9629. </tr>
  9630. HTML chapter-13/min-width-max-width.html
  9631. Limiting Width
  9632. min-width, max-width
  9633. 305 BOXES
  9634. Article
  9635. Result
  9636. h2, p {
  9637. width: 400px;
  9638. font-size: 90%;
  9639. line-height: 1.2em;}
  9640. h2 {
  9641. color: #0088dd;
  9642. border-bottom: 1px solid #0088dd;}
  9643. p {
  9644. min-height: 10px;
  9645. max-height: 30px;}
  9646. In the same way that you might
  9647. want to limit the width of a box
  9648. on a page, you may also want
  9649. to limit the height of it. This is
  9650. achieved using the min-height
  9651. and max-height properties.
  9652. The example on this page
  9653. demonstrates these properties
  9654. in action. It also shows you what
  9655. happens when the content of the
  9656. box takes up more space than
  9657. the size specified for the box.
  9658. If the box is not big enough to
  9659. hold the content, and the content
  9660. expands outside the box it can
  9661. look very messy. To control
  9662. what happens when there is not
  9663. enough space for the content of
  9664. a box, you can use the overflow
  9665. property, which is discussed on
  9666. the next page.
  9667. <h2>Fender Mustang</h2>
  9668. <p>The Fender Mustang was introduced in 1964 as the
  9669. basis of a major redesign of Fender's ...</p>
  9670. <h2>Fender Stratocaster</h2>
  9671. <p>The Fender Stratocaster or "Strat" is one of the
  9672. most popular electric guitars of all time ...</p>
  9673. <h2>Gibson Les Paul</h2>
  9674. <p>The Gibson Les Paul is a solid body electric
  9675. guitar that was first sold in 1952 ...</p>
  9676. chapter-13/min-height-max-height.html HTML
  9677. Limiting Height
  9678. min-height, max-height
  9679. CSS
  9680. Article
  9681. BOXES 306
  9682. The overflow property tells the
  9683. browser what to do if the content
  9684. contained within a box is larger
  9685. than the box itself. It can have
  9686. one of two values:
  9687. hidden
  9688. This property simply hides any
  9689. extra content that does not fit in
  9690. the box.
  9691. scroll
  9692. This property adds a scrollbar to
  9693. the box so that users can scroll
  9694. to see the missing content.
  9695. On the left, you can see two
  9696. boxes whose contents expand
  9697. beyond their set dimensions. The
  9698. first example has the overflow
  9699. property with a value of hidden.
  9700. The second example has the
  9701. overflow property with a value
  9702. of scroll.
  9703. The overflow property is
  9704. particularly handy because some
  9705. browsers allow users to adjust
  9706. the size of the text to appear as
  9707. large or as small as they want. If
  9708. the text is set too large then the
  9709. page can become an unreadable
  9710. mess. Hiding the overflow on
  9711. such boxes helps prevent items
  9712. overlapping on the page.
  9713. Result
  9714. p.one {
  9715. overflow: hidden;}
  9716. p.two {
  9717. overflow: scroll;}
  9718. CSS
  9719. Overflowing Content
  9720. overflow
  9721. <h2>Fender Stratocaster</h2>
  9722. <p class="one">The Fender Stratocaster or "Strat"
  9723. is one of the most popular electric guitars of
  9724. all time, and its design has been copied by many
  9725. guitar makers. It was designed by Leo... </p>
  9726. <h2>Gibson Les Paul</h2>
  9727. <p class="two">The Gibson Les Paul is a solid body
  9728. electric guitar that was first sold in 1952.
  9729. The Les Paul was designed by Ted McCarty... </p>
  9730. HTML chapter-13/overflow.html
  9731. 307 BOXES
  9732. If you specify a width
  9733. for a box, then the
  9734. borders, margin, and
  9735. padding are added to
  9736. its width and height.
  9737. Every box has three available properties that
  9738. can be adjusted to control its appearance:
  9739. Border, Margin
  9740. & Padding
  9741. 1
  9742. Border
  9743. Every box has a border (even if
  9744. it is not visible or is specified to
  9745. be 0 pixels wide). The border
  9746. separates the edge of one box
  9747. from another.
  9748. 2
  9749. Margin
  9750. Margins sit outside the edge
  9751. of the border. You can set the
  9752. width of a margin to create a
  9753. gap between the borders of two
  9754. adjacent boxes.
  9755. 3
  9756. Padding
  9757. Padding is the space between
  9758. the border of a box and any
  9759. content contained within it.
  9760. Adding padding can increase the
  9761. readability of its contents.
  9762. hello
  9763. BOXES 308
  9764. Designers refer to the space
  9765. between items on a page as
  9766. white space. Imagine you had
  9767. a border around a box. You
  9768. would not want the text to touch
  9769. this border or it would become
  9770. harder to read.
  9771. Or, imagine you had two boxes
  9772. sitting side by side (each with
  9773. a black border). You would not
  9774. necessarily want the boxes to
  9775. touch edges as this would make
  9776. the line look twice as thick on
  9777. the facing sides.
  9778. If the bottom margin of any
  9779. box touches the top margin of
  9780. another, the browser will render
  9781. it differently than you might
  9782. expect. It will only show the
  9783. larger of the two margins. If both
  9784. margins are the same size, it will
  9785. only show one.
  9786. The padding and
  9787. margin properties
  9788. are very helpful
  9789. in adding space
  9790. between various
  9791. items on the page.
  9792. White space &
  9793. Vertical Margin
  9794. With
  9795. Margin & Padding
  9796. Without
  9797. Margin & Padding
  9798. 309 BOXES
  9799. Article
  9800. Result
  9801. p.one {
  9802. border-width: 2px;}
  9803. p.two {
  9804. border-width: thick;}
  9805. p.three {
  9806. border-width: 1px 4px 12px 4px;}
  9807. <p class="one">Hohner's "Clavinet" is essentially an
  9808. electric clavichord.</p>
  9809. <p class="two">Hohner's "Clavinet" is essentially an
  9810. electric clavichord.</p>
  9811. <p class="three">Hohner's "Clavinet" is essentially
  9812. an electric clavichord.</p>
  9813. chapter-13/border-width.html HTML
  9814. The border-width property
  9815. is used to control the width
  9816. of a border. The value of this
  9817. property can either be given
  9818. in pixels or using one of the
  9819. following values:
  9820. thin
  9821. medium
  9822. thick
  9823. (You cannot use percentages
  9824. with this property.)
  9825. You can control the individual
  9826. size of borders using four
  9827. separate properties:
  9828. border-top-width
  9829. border-right-width
  9830. border-bottom-width
  9831. border-left-width
  9832. You can also specify different
  9833. widths for the four border values
  9834. in one property, like so:
  9835. border-width: 2px 1px 1px
  9836. 2px;
  9837. The values here appear in
  9838. clockwise order: top, right,
  9839. bottom, left.
  9840. Border Width
  9841. border-width
  9842. CSS
  9843. Article
  9844. BOXES 310
  9845. You can control the style of a
  9846. border using the border-style
  9847. property. This property can take
  9848. the following values:
  9849. solid a single solid line
  9850. dotted a series of square dots
  9851. (if your border is 2px wide, then
  9852. the dots are 2px squared with a
  9853. 2px gap between each dot)
  9854. dashed a series of short lines
  9855. double two solid lines (the
  9856. value of the border-width
  9857. property creates the sum of the
  9858. two lines)
  9859. groove appears to be carved
  9860. into the page
  9861. ridge appears to stick out from
  9862. the page
  9863. inset appears embedded into
  9864. the page
  9865. outset looks like it is coming
  9866. out of the screen
  9867. hidden / none no border is
  9868. shown
  9869. You can individually change the
  9870. styles of different borders using:
  9871. border-top-style
  9872. border-left-style
  9873. border-right-style
  9874. border-bottom-style
  9875. Result
  9876. p.one {border-style: solid;}
  9877. p.two {border-style: dotted;}
  9878. p.three {border-style: dashed;}
  9879. p.four {border-style: double;}
  9880. p.five {border-style: groove;}
  9881. p.six {border-style: ridge;}
  9882. p.seven {border-style: inset;}
  9883. p.eight {border-style: outset;}
  9884. CSS
  9885. <p class="one">Wurlitzer Electric Piano</p>
  9886. <p class="two">Wurlitzer Electric Piano</p>
  9887. <p class="three">Wurlitzer Electric Piano</p>
  9888. <p class="four">Wurlitzer Electric Piano</p>
  9889. <p class="five">Wurlitzer Electric Piano</p>
  9890. <p class="six">Wurlitzer Electric Piano</p>
  9891. <p class="seven">Wurlitzer Electric Piano</p>
  9892. <p class="eight">Wurlitzer Electric Piano</p>
  9893. HTML chapter-13/border-style.html
  9894. Border Style
  9895. border-style
  9896. 311 BOXES
  9897. Article
  9898. Result
  9899. p.one {
  9900. border-color: #0088dd;}
  9901. p.two {
  9902. border-color: #bbbbaa #111111 #ee3e80 #0088dd;}
  9903. CSS
  9904. <p class="one">The ARP Odyssey was introduced in
  9905. 1972.</p>
  9906. <p class="two">The ARP Odyssey was introduced in
  9907. 1972.</p>
  9908. chapter-13/border-color.html HTML You can specify the color of a
  9909. border using either RGB values,
  9910. hex codes or CSS color names
  9911. (as you saw on pages 251-252).
  9912. It is possible to individually
  9913. control the colors of the borders
  9914. on different sides of a box using:
  9915. border-top-color
  9916. border-right-color
  9917. border-bottom-color
  9918. border-left-color
  9919. It is also possible to use a
  9920. shorthand to control all four
  9921. border colors in the one
  9922. property:
  9923. border-color: darkcyan
  9924. deeppink darkcyan
  9925. deeppink;
  9926. The values here appear in
  9927. clockwise order: top, right,
  9928. bottom, left.
  9929. You could also use HSL values
  9930. to specify the color as shown
  9931. on pages 255-256. However,
  9932. these were only introduced in
  9933. CSS3 and will not work in older
  9934. browsers.
  9935. Border Color
  9936. border-color
  9937. Article
  9938. BOXES 312
  9939. The border property allows you
  9940. to specify the width, style and
  9941. color of a border in one property
  9942. (and the values should be coded
  9943. in that specific order).
  9944. Result
  9945. p {
  9946. width: 250px;
  9947. border: 3px dotted #0088dd;}
  9948. CSS
  9949. <p>Here is a simple chord sequence played on a
  9950. Hammond organ through a Leslie speaker.</p>
  9951. HTML chapter-13/border-shorthand.html
  9952. Shorthand
  9953. border
  9954. 313 BOXES
  9955. Article
  9956. Result
  9957. p {
  9958. width: 275px;
  9959. border: 2px solid #0088dd;}
  9960. p.example {
  9961. padding: 10px;}
  9962. CSS
  9963. The padding property allows
  9964. you to specify how much space
  9965. should appear between the
  9966. content of an element and its
  9967. border.
  9968. The value of this property is
  9969. most often specified in pixels
  9970. (although it is also possible to
  9971. use percentages or ems). If a
  9972. percentage is used, the padding
  9973. is a percentage of the browser
  9974. window (or of the containing box
  9975. if it is inside another box).
  9976. Please note: If a width is
  9977. specified for a box, padding is
  9978. added onto the width of the box.
  9979. As you can see, the second
  9980. paragraph here is much easier
  9981. to read because there is a space
  9982. between the text and the border
  9983. of the box. The box is also wider
  9984. because it has padding.
  9985. You can specify different values
  9986. for each side of a box using:
  9987. padding-top
  9988. padding-right
  9989. padding-bottom
  9990. padding-left
  9991. Or you can use a shorthand
  9992. (where the values are in
  9993. clockwise order: top, right,
  9994. bottom, left):
  9995. padding: 10px 5px 3px 1px;
  9996. <p>Analog synths produce a wave sound, whereas the
  9997. sounds stored on a digital synth have been
  9998. sampled and then turned into numbers.</p>
  9999. <p class="example">Analog synths produce a wave
  10000. sound, whereas the sounds stored on a digital
  10001. synth have been sampled and then ... </p>
  10002. chapter-13/padding.html HTML
  10003. Padding
  10004. padding
  10005. The value of the padding property is not inherited by child elements in
  10006. the same way that the color value of the font-family property is; so
  10007. you need to specify the padding for every element that needs to use it.
  10008. Up until Internet Explorer 6, the width of the box would include the
  10009. padding and margins. You can see more about this on page 316.
  10010. Article
  10011. BOXES 314
  10012. The margin property controls
  10013. the gap between boxes. Its value
  10014. is commonly given in pixels,
  10015. although you may also use
  10016. percentages or ems.
  10017. If one box sits on top of another,
  10018. margins are collapsed , which
  10019. means the larger of the two
  10020. margins will be used and the
  10021. smaller will be disregarded.
  10022. Please note: If the width of a box
  10023. is specified then the margin is
  10024. added to the width of the box.
  10025. You can specify values for each
  10026. side of a box using:
  10027. margin-top
  10028. margin-right
  10029. margin-bottom
  10030. margin-left
  10031. You can also use the shorthand
  10032. (where the values are in
  10033. clockwise order: top, right,
  10034. bottom, left):
  10035. margin: 1px 2px 3px 4px;
  10036. Sometimes you might see the
  10037. following, which means that the
  10038. left and right margins should be
  10039. 10 pixels and the top and bottom
  10040. margins should be 20 pixels:
  10041. margin: 10px 20px;
  10042. (This same shorthand shown
  10043. above can also be applied to
  10044. padding.)
  10045. Result
  10046. p {
  10047. width: 200px;
  10048. border: 2px solid #0088dd;
  10049. padding: 10px;}
  10050. p.example {
  10051. margin: 20px;}
  10052. CSS
  10053. <p>Analog synthesizers are often said to have a
  10054. "warmer" sound than their digital counterparts.
  10055. </p>
  10056. <p class="example">Analog synthesizers are often
  10057. said to have a "warmer" sound than their digital
  10058. counterparts.</p>
  10059. HTML chapter-13/margin.html
  10060. Margin
  10061. margin
  10062. The value of the margin property is not inherited by child elements in
  10063. the same way that the color value of the font-family property is, so
  10064. you need to specify the margin for every element that needs to use it.
  10065. Up until Internet Explorer 6, the width of the box would include the
  10066. padding and margins. You can see more about this on page 316.
  10067. 315 BOXES
  10068. Article
  10069. Result
  10070. body {
  10071. text-align: center;}
  10072. p {
  10073. width: 300px;
  10074. padding: 50px;
  10075. border: 20px solid #0088dd;}
  10076. p.example {
  10077. margin: 10px auto 10px auto;
  10078. text-align: left;}
  10079. <body>
  10080. <p>Analog synthesizers are often said to have a
  10081. "warmer" sound than their digital
  10082. counterparts.</p>
  10083. <p class="example">Analog synthesizers are often
  10084. said to have a "warmer" sound than their
  10085. digital counterparts.</p>
  10086. </body>
  10087. chapter-13/centering-content.html HTML If you want to center a box on
  10088. the page (or center it inside
  10089. the element that it sits in), you
  10090. can set the left-margin and
  10091. right-margin to auto.
  10092. In order to center a box on the
  10093. page, you need to set a width
  10094. for the box (otherwise it will take
  10095. up the full width of the page).
  10096. Once you have specified the
  10097. width of the box, setting the left
  10098. and right margins to auto will
  10099. make the browser put an equal
  10100. gap on each side of the box. This
  10101. centers the box on the page (or
  10102. within the element that the box
  10103. sits inside).
  10104. In order for this to work in older
  10105. browsers (particularly IE6), the
  10106. element that the box sits inside
  10107. should have a text-align
  10108. property with its value set to
  10109. center.
  10110. The text-align property is
  10111. inherited by child elements. You
  10112. therefore also need to specify
  10113. the text-align property on the
  10114. centered box if you do not want
  10115. the text inside it to be centered.
  10116. Centering Content
  10117. CSS
  10118. Article
  10119. BOXES 316
  10120. When you specify the width of
  10121. a box, any padding or margin
  10122. should be added to the width of
  10123. it. Internet Explorer 6, however,
  10124. has a quirk whereby it includes
  10125. the padding and margins in the
  10126. width of the box.
  10127. The way around this is to ensure
  10128. that you provide a DOCTYPE
  10129. declaration for the HTML page.
  10130. (DOCTYPE declarations were
  10131. covered on page 181.) You can
  10132. use either the HTML5, HTML
  10133. 4 strict, or HTML 4 transitional
  10134. DOCTYPE declarations to
  10135. ensure that IE6 follows the
  10136. correct box model.
  10137. To demonstrate this, you can
  10138. see the example from the left
  10139. hand page shown in IE6, first
  10140. without a DOCTYPE declaration
  10141. and then again with the HTML5
  10142. DOCTYPE declaration.
  10143. IE6 Box Model
  10144. Result IN IE6 Without Doctype
  10145. RESULT IN ie6 WITH DOCTYPE
  10146. 317 BOXES
  10147. Article
  10148. The display property allows
  10149. you to turn an inline element
  10150. into a block-level element or vice
  10151. versa, and can also be used to
  10152. hide an element from the page.
  10153. The values this property can
  10154. take are:
  10155. inline
  10156. This causes a block-level
  10157. element to act like an inline
  10158. element.
  10159. block
  10160. This causes an inline element to
  10161. act like a block-level element.
  10162. inline-block
  10163. This causes a block-level
  10164. element to flow like an inline
  10165. element, while retaining other
  10166. features of a block-level element.
  10167. none
  10168. This hides an element from the
  10169. page. In this case, the element
  10170. acts as though it is not on the
  10171. page at all (although a user could
  10172. still see the content of the box if
  10173. they used the view source option
  10174. in their browser).
  10175. If you use this property, it is
  10176. important to note that inline
  10177. boxes are not supposed to create
  10178. block-level elements.
  10179. Result
  10180. li {
  10181. display: inline;
  10182. margin-right: 10px;}
  10183. li.coming-soon {
  10184. display: none;}
  10185. CSS
  10186. <ul>
  10187. <li>Home</li>
  10188. <li>Products</li>
  10189. <li class="coming-soon">Services</li>
  10190. <li>About</li>
  10191. <li>Contact</li>
  10192. </ul>
  10193. chapter-13/display.html HTML
  10194. Change Inline/Block
  10195. display
  10196. In this example you can see
  10197. a list. Each item in the list is
  10198. usually treated as a block-level
  10199. element, but the rule for the
  10200. <li> elements indicates that
  10201. they should be treated as inline
  10202. elements, which means they will
  10203. sit alongside each other rather
  10204. than appearing on new lines.
  10205. This technique is often used to
  10206. create navigation for a site, and
  10207. in this example a margin has
  10208. been added to the right of each
  10209. of the items to separate them
  10210. out. The rule that applies to the
  10211. <li> element whose class is
  10212. coming-soon has been hidden
  10213. as if it were not in the page at all.
  10214. Article
  10215. BOXES 318
  10216. The visibility property allows
  10217. you to hide boxes from users
  10218. but It leaves a space where the
  10219. element would have been.
  10220. This property can take two
  10221. values:
  10222. hidden
  10223. This hides the element.
  10224. visible
  10225. This shows the element.
  10226. If the visibility of an element
  10227. is set to hidden, a blank space
  10228. will appear in its place.
  10229. If you do not want a blank space
  10230. to appear, then you should use
  10231. the display property with
  10232. a value of none instead (as
  10233. covered on the previous page).
  10234. Please note that anyone can view
  10235. the contents of any elements
  10236. whose visibility property has
  10237. been set to hidden by viewing
  10238. the source in their browser.
  10239. <ul>
  10240. <li>Home</li>
  10241. <li>Products</li>
  10242. <li class="coming-soon">Services</li>
  10243. <li>About</li>
  10244. <li>Contact</li>
  10245. </ul>
  10246. HTML chapter-13/visibility.html
  10247. li {
  10248. display: inline;
  10249. margin-right: 10px;}
  10250. li.coming-soon {
  10251. visibility: hidden;}
  10252. CSS
  10253. Result
  10254. Hiding Boxes
  10255. visibility
  10256. 319 BOXES
  10257. Article
  10258. Result
  10259. p.one {
  10260. -moz-border-image: url("images/dots.gif")
  10261. 11 11 11 11 stretch;
  10262. -webkit-border-image: url("images/dots.gif")
  10263. 11 11 11 11 stretch;
  10264. border-image: url("images/dots.gif")
  10265. 11 11 11 11 stretch;}
  10266. p.two {
  10267. -moz-border-image: url("images/dots.gif")
  10268. 11 11 11 11 round;
  10269. -webkit-border-image: url("images/dots.gif")
  10270. 11 11 11 11 round;
  10271. border-image: url("images/dots.gif")
  10272. 11 11 11 11 round;}
  10273. <p class="one"></p>
  10274. <p class="two"></p>
  10275. <p class="three"></p>
  10276. chapter-13/border-image.html HTML
  10277. The border-image property
  10278. applies an image to the border of
  10279. any box. It takes a background
  10280. image and slices it into nine
  10281. pieces.
  10282. Here is the image. I have
  10283. added marks where it is
  10284. sliced in the example,
  10285. taking 18 pixels from each corner
  10286. to place an entire circle in each
  10287. corner. The corner slices are
  10288. always placed in the four corners
  10289. of the box, but we have a choice
  10290. whether the sides are stretched
  10291. or repeated.
  10292. This property requires three
  10293. pieces of information:
  10294. 1: The URL of the image
  10295. 2: Where to slice the image
  10296. 3: What to do with the straight
  10297. edges; the possible values are:
  10298. stretch stretches the image
  10299. repeat repeats the image
  10300. round like repeat but if the
  10301. tiles do not fit exactly, scales
  10302. the tile image so they will
  10303. The box must also have a border
  10304. width for the image to be shown.
  10305. The -moz-border-image
  10306. and -webkit-border-image
  10307. properties are not in the CSS
  10308. specification but help earlier
  10309. versions of Chrome, Firefox, and
  10310. Safari display this effect.
  10311. CSS3: Border Images
  10312. border-image
  10313. CSS
  10314. Article
  10315. BOXES 320
  10316. The box-shadow property
  10317. allows you to add a drop shadow
  10318. around a box. It works just like
  10319. the text-shadow property that
  10320. you met on page 288. It must
  10321. use at least the first of these two
  10322. values as well as a color:
  10323. Horizontal offset
  10324. Negative values position the
  10325. shadow to the left of the box.
  10326. Vertical offset
  10327. Negative values position the
  10328. shadow to the top of the box.
  10329. Blur distance
  10330. If omitted, the shadow is a solid
  10331. line like a border.
  10332. Spread of shadow
  10333. If used, a positive value will
  10334. cause the shadow to expand in
  10335. all directions, and a negative
  10336. value will make it contract.
  10337. The inset keyword can also
  10338. be used before these values to
  10339. create an inner-shadow.
  10340. Chrome, Firefox, and Safari were
  10341. quick to support this property
  10342. using the -moz-box-shadow
  10343. and -webkit-box-shadow
  10344. properties. These are not in the
  10345. CSS specification but using them
  10346. can help this style to work in
  10347. these browsers.
  10348. Result
  10349. p.one {
  10350. -moz-box-shadow: -5px -5px #777777;
  10351. -webkit-box-shadow: -5px -5px #777777;
  10352. box-shadow: -5px -5px #777777;}
  10353. p.two {
  10354. -moz-box-shadow: 5px 5px 5px #777777;
  10355. -webkit-box-shadow: 5px 5px 5px #777777;
  10356. box-shadow: 5px 5px 5px #777777;}
  10357. p.three {
  10358. -moz-box-shadow: 5px 5px 5px 5px #777777;
  10359. -webkit-box-shadow: 5px 5px 5px 5px #777777;
  10360. box-shadow: 5px 5px 5px 5px #777777;}
  10361. p.four {
  10362. -moz-box-shadow: 0 0 10px #777777;
  10363. -webkit-box-shadow: 0 0 10px #777777;
  10364. box-shadow: 0 0 10px #777777;}
  10365. p.five {
  10366. -moz-box-shadow: inset 0 0 10px #777777;
  10367. -webkit-box-shadow: inset 0 0 10px #777777;
  10368. box-shadow: inset 0 0 10px #777777;}
  10369. CSS
  10370. CSS3: Box Shadows
  10371. box-shadow
  10372. chapter-13/box-shadow.html
  10373. 321 BOXES
  10374. Article
  10375. Result
  10376. p {
  10377. border: 5px solid #cccccc;
  10378. padding: 20px;
  10379. width: 275px;
  10380. text-align: center;
  10381. border-radius: 10px;
  10382. -moz-border-radius: 10px;
  10383. -webkit-border-radius: 10px;}
  10384. CSS
  10385. <p>Pet Sounds featured a number of unconventional
  10386. instruments such as bicycle bells, buzzing
  10387. organs, harpsichords, flutes, Electro-Theremin,
  10388. dog whistles, trains, Hawaiian-sounding string
  10389. instruments, Coca-Cola cans and barking dogs.</p>
  10390. chapter-13/border-radius.html HTML CSS3 introduces the ability to
  10391. create rounded corners on any
  10392. box, using a property called
  10393. border-radius. The value
  10394. indicates the size of the radius
  10395. in pixels.
  10396. Older browsers that do not
  10397. support this property will show a
  10398. box with right-angled corners.
  10399. The -moz-border-radius
  10400. and -webkit-border-radius
  10401. properties are not in the CSS
  10402. specification. However, they
  10403. are used in some versions of
  10404. Chrome, Firefox, and Safari to
  10405. offer early support for this style
  10406. (and therefore can be used
  10407. to achieve this effect in more
  10408. browsers).
  10409. You can specify individual values
  10410. for each corner of a box using:
  10411. border-top-right-radius
  10412. border-bottom-right-radius
  10413. border-bottom-left-radius
  10414. border-top-left-radius
  10415. You can also use a shorthand
  10416. of these four properties (in
  10417. clockwise order: top, right,
  10418. bottom, left). For example:
  10419. border-radius: 5px, 10px,
  10420. 5px, 10px;
  10421. CSS3: Rounded Corners
  10422. border-radius
  10423. Article
  10424. BOXES 322
  10425. To create more complex shapes,
  10426. you can specify different
  10427. distances for the horizontal and
  10428. the vertical parts of the rounded
  10429. corners.
  10430. For example, this will create a
  10431. radius that is wider than it is tall:
  10432. border-radius: 80px 50px;
  10433. You can target just one corner
  10434. using the individual properties
  10435. for that corner:
  10436. border-top-left-radius:
  10437. 80px 50px;
  10438. There is also a shorthand for
  10439. targetting all four corners at
  10440. once; first you specify the four
  10441. horizontal values, then the four
  10442. vertical values, as shown in the
  10443. second shape on the left.
  10444. You can even create a circle by
  10445. taking a square box and making
  10446. the border-radius the same
  10447. height as the square, as shown in
  10448. the third shape on the left.
  10449. Result
  10450. p.one {
  10451. border-top-left-radius: 80px 50px;
  10452. -moz-border-radius-top-left: 80px 50px;
  10453. -webkit-border-radius-top-left: 80px 50px;}
  10454. p.two {
  10455. border-radius: 1em 4em 1em 4em / 2em 1em 2em 1em;
  10456. -moz-border-radius: 1em 4em 1em 4em
  10457. / 2em 1em 2em 1em;
  10458. -webkit-border-radius: 1em 4em 1em 4em
  10459. / 2em 1em 2em 1em;}
  10460. p.three {
  10461. padding: 0px;
  10462. border-radius: 100px;
  10463. -moz-border-radius: 100px;
  10464. -webkit-border-radius: 100px;}
  10465. CSS
  10466. <p class="one"></p>
  10467. <p class="two"></p>
  10468. <p class="three"></p>
  10469. HTML chapter-13/elliptical-shapes.html
  10470. CSS3: Elliptical Shapes
  10471. border-radius
  10472. 80px
  10473. 50px
  10474. 323 BOXES
  10475. Example
  10476. BOXES
  10477. BOXES 324
  10478. In this example, you can see a simple
  10479. homepage for a music shop.
  10480. The whole page sits inside a <div> element with an id of page. This is
  10481. centered using the margin property, with a value of auto for the left and
  10482. right margins. The logo and other content are centered using this same
  10483. technique.
  10484. The main <div> has a double-lined border around it, and the size of
  10485. this box will expand and contract if the browser window is resized. To
  10486. prevent the page from becoming too narrow or too wide, the min-width
  10487. and max-width properties are used.
  10488. The navigation is created using an unordered list. There are borders
  10489. set to the top and bottom of this list to make it stand out. The display
  10490. property has been applied to each of the items in the list so they behave
  10491. like inline (rather than block-level) elements. This enables the navigation
  10492. links to sit next to each other horizontally. The padding property has
  10493. been used to create space between each of the links.
  10494. The width property for the <ul> element is set to 570 pixels, and the
  10495. width property for the <p> elements beneath them is set to 600 pixels.
  10496. They actually end up the same width as each other because the <ul>
  10497. element also uses padding to create a gap between the border of the box
  10498. it creates and the links inside of it, and any padding, borders, or margins
  10499. are added to the width and height of the box.
  10500. If we had not included a DOCTYPE declaration at the start of this page,
  10501. the sizes of the boxes would be different to each other in Internet
  10502. Explorer 6 because this browser did not implement the box model in the
  10503. correct way.
  10504. 325 BOXES
  10505. Example
  10506. BOXES
  10507. <!DOCTYPE html>
  10508. <html>
  10509. <head>
  10510. <title>Boxes</title>
  10511. <style type="text/css">
  10512. body {
  10513. font-size: 80%;
  10514. font-family: "Courier New", Courier, monospace;
  10515. letter-spacing: 0.15em;
  10516. background-color: #efefef;}
  10517. #page {
  10518. max-width: 940px;
  10519. min-width: 720px;
  10520. margin: 10px auto 10px auto;
  10521. padding: 20px;
  10522. border: 4px double #000;
  10523. background-color: #ffffff;}
  10524. #logo {
  10525. width: 150px;
  10526. margin: 10px auto 25px auto;}
  10527. ul {
  10528. width: 570px;
  10529. padding: 15px;
  10530. margin: 0px auto 0px auto;
  10531. border-top: 2px solid #000;
  10532. border-bottom: 1px solid #000;
  10533. text-align: center;}
  10534. li {
  10535. display: inline;
  10536. margin: 0px 3px;}
  10537. p {
  10538. text-align: center;
  10539. width: 600px;
  10540. margin: 20px auto 20px auto;
  10541. font-weight: normal;}
  10542. BOXES 326
  10543. Example
  10544. BOXES
  10545. a {
  10546. color: #000000;
  10547. text-transform: uppercase;
  10548. text-decoration: none;
  10549. padding: 6px 18px 5px 18px;}
  10550. a:hover, a.on {
  10551. color: #cc3333;
  10552. background-color: #ffffff;}
  10553. </style>
  10554. </head>
  10555. <body>
  10556. <div id="page">
  10557. <div id="logo">
  10558. <img src="images/logo.gif" alt="The Analog Specialists" />
  10559. </div>
  10560. <ul id="navigation">
  10561. <li><a href="#" class="on">Home</a></li>
  10562. <li><a href="#">For Sale</a></li>
  10563. <li><a href="#">Repairs</a></li>
  10564. <li><a href="#">About</a></li>
  10565. <li><a href="#">Contact</a></li>
  10566. </ul>
  10567. <p>
  10568. <img src="images/keys.jpg" alt="Fender Rhodes, Hohner Clavinet,
  10569. and Wurlitzer EP200" />
  10570. </p>
  10571. <p>
  10572. We specialise in the sales and repair of classic keyboards, in particular
  10573. the Fender Rhodes, Wurlitzer EP200, and Hohner Clavinet.
  10574. </p>
  10575. </div>
  10576. </body>
  10577. </html>
  10578.  
  10579. Summary
  10580. BOXES
  10581. X CSS treats each HTML element as if it has its own box.
  10582. X You can use CSS to control the dimensions of a box.
  10583. X You can also control the borders, margin and padding
  10584. for each box with CSS.
  10585. X It is possible to hide elements using the display and
  10586. visibility properties.
  10587. X Block-level boxes can be made into inline boxes, and
  10588. inline boxes made into block-level boxes.
  10589. X Legibility can be improved by controlling the width of
  10590. boxes containing text and the leading.
  10591. X CSS3 has introduced the ability to create image
  10592. borders and rounded borders.
  10593.  
  10594. X Specifying bullet point styles
  10595. X Adding borders and backgrounds to tables
  10596. X Changing the appearance of form elements
  10597. Lists, Tables
  10598. and Forms
  10599. 14
  10600. 331 LISTS, TABLES AND FORMS
  10601. There are several CSS properties that
  10602. were created to work with specific types
  10603. of HTML elements, such as lists, tables,
  10604. and forms.
  10605. In this chapter you will learn how to:
  10606. ● Specify the type of bullet point or numbering on lists
  10607. ● Add borders and backgrounds to table cells
  10608. ● Control the appearance of form controls
  10609. Together, these properties allow you to take finer control over
  10610. specific parts of your pages.
  10611. LISTS, TABLES AND FORMS 332
  10612. 333 LISTS, TABLES AND FORMS
  10613. Article
  10614. 333 LISTS, TABLES AND FORMS
  10615. Result
  10616. ol {
  10617. list-style-type: lower-roman;}
  10618. The list-style-type property
  10619. allows you to control the shape
  10620. or style of a bullet point (also
  10621. known as a marker).
  10622. It can be used on rules that
  10623. apply to the <ol>, <ul>, and <li>
  10624. elements.
  10625. Unordered Lists
  10626. For an unordered list you can use
  10627. the following values:
  10628. none
  10629. disc
  10630. circle
  10631. square
  10632. Ordered Lists
  10633. For an ordered (numbered) list
  10634. you can use the following values:
  10635. decimal
  10636. 1 2 3
  10637. decimal-leading-zero
  10638. 01 02 03
  10639. lower-alpha
  10640. a b c
  10641. upper-alpha
  10642. A B C
  10643. lower-roman
  10644. i. ii. iii.
  10645. upper-roman
  10646. I II III
  10647. <h1>The Complete Poems</h1>
  10648. <h2>Emily Dickinson</h2>
  10649. <ol>
  10650. <li>Life</li>
  10651. <li>Nature</li>
  10652. <li>Love</li>
  10653. <li>Time and Eternity</li>
  10654. <li>The Single Hound</li>
  10655. </ol>
  10656. chapter-14/list-style-type.html HTML
  10657. Bullet Point Styles
  10658. list-style-type
  10659. CSS
  10660. Article
  10661. LISTS, TABLES AND FORMS 334
  10662. Result
  10663. You can specify an image to act
  10664. as a bullet point using the
  10665. list-style-image property.
  10666. The value starts with the letters
  10667. url and is followed by a pair
  10668. of parentheses. Inside the
  10669. parentheses, the path to the
  10670. image is given inside double
  10671. quotes.
  10672. This property can be used on
  10673. rules that apply to the <ul> and
  10674. <li> elements.
  10675. The example on this page also
  10676. shows the use of the margin
  10677. property to increase the vertical
  10678. gap between each item in the
  10679. list.
  10680. ul {
  10681. list-style-image: url("images/star.png");}
  10682. li {
  10683. margin: 10px 0px 0px 0px;}
  10684. CSS
  10685. <h1>Index of Translated Poems</h1>
  10686. <h2>Arthur Rimbaud</h2>
  10687. <ul>
  10688. <li>Ophelia</li>
  10689. <li>To Music</li>
  10690. <li>A Dream for Winter</li>
  10691. <li>Vowels</li>
  10692. <li>The Drunken Boat</li>
  10693. </ul>
  10694. HTML chapter-14/list-style-image.html
  10695. Images for Bullets
  10696. list-style-image
  10697. 335 LISTS, TABLES AND FORMS
  10698. Article
  10699. 335 LISTS, TABLES AND FORMS
  10700. ul {
  10701. width: 150px;}
  10702. li {
  10703. margin: 10px;}
  10704. ul.illuminations {
  10705. list-style-position: outside;}
  10706. ul.season {
  10707. list-style-position: inside;}
  10708. <ul class="illuminations">
  10709. <li>That idol, black eyes and ...</li>
  10710. <li>Gracious son of Pan! ...</li>
  10711. <li>When the world is reduced ...</li>
  10712. </ul>
  10713. <ul class="season">
  10714. <li>Once, if my memory serves ...</li>
  10715. <li>Hadn't I once a youth ...</li>
  10716. <li>Autumn already! ...</li>
  10717. </ul>
  10718. chapter-14/list-style-position.html HTML Lists are indented into the page
  10719. by default and the list-styleposition
  10720. property indicates
  10721. whether the marker should
  10722. appear on the inside or the
  10723. outside of the box containing the
  10724. main points.
  10725. This property can take one of
  10726. two values:
  10727. outside
  10728. The marker sits to the left of the
  10729. block of text. (This is the default
  10730. behaviour if this property is not
  10731. used.)
  10732. inside
  10733. The marker sits inside the box of
  10734. text (which is indented).
  10735. In the example shown, the width
  10736. of the list has been limited to 150
  10737. pixels. This ensures that the text
  10738. wraps onto a new line so you can
  10739. see how the value of inside sits
  10740. the bullet inside the first line of
  10741. text.
  10742. A margin has been added to
  10743. each list item so that there is a
  10744. clear gap between each.
  10745. Positioning the Marker
  10746. list-style-position
  10747. CSS
  10748. Result Result
  10749. Article
  10750. LISTS, TABLES AND FORMS 336
  10751. As with several of the other CSS
  10752. properties, there is a property
  10753. that acts as a shorthand for list
  10754. styles. It is called list-style,
  10755. and it allows you to express
  10756. the markers' style, image and
  10757. position properties in any order.
  10758. Result
  10759. ul {
  10760. list-style: inside circle;
  10761. width: 300px;}
  10762. li {
  10763. margin: 10px 0px 0px 0px;}
  10764. CSS
  10765. <h1>Quotes from Edgar Allan Poe</h1>
  10766. <ul>
  10767. <li> I have great faith in fools; self-confidence
  10768. my friends call it.</li>
  10769. <li>All that we see or seem is but a dream within
  10770. a dream.</li>
  10771. <li>I would define, in brief, the poetry of words
  10772. as the rhythmical creation of Beauty.</li>
  10773. </ul>
  10774. HTML chapter-14/list-style.html
  10775. List Shorthand
  10776. list-style
  10777. 337 LISTS, TABLES AND FORMS
  10778. Article
  10779. 337 LISTS, TABLES AND FORMS
  10780. <h1>First Edition Auctions</h1>
  10781. <table>
  10782. <tr>
  10783. <th>Author</th>
  10784. <th>Title</th>
  10785. <th class="money">Reserve Price</th>
  10786. <th class="money">Current Bid</th>
  10787. </tr>
  10788. <tr>
  10789. <td>E.E. Cummings</td>
  10790. <td>Tulips & Chimneys</td>
  10791. <td class="money">$2,000.00</td>
  10792. <td class="money">$2,642.50</td>
  10793. </tr>
  10794. <tr class="even">
  10795. <td>Charles d'Orleans</td>
  10796. <td>Poemes</td>
  10797. <td class="money"></td>
  10798. <td class="money">$5,866.00</td>
  10799. </tr>
  10800. <tr>
  10801. <td>T.S. Eliot</td>
  10802. <td>Poems 1909 - 1925</td>
  10803. <td class="money">$1,250.00</td>
  10804. <td class="money">$8,499.35</td>
  10805. </tr>
  10806. <tr class="even">
  10807. <td>Sylvia Plath</td>
  10808. <td>The Colossus</td>
  10809. <td class="money"></td>
  10810. <td class="money">$1031.72</td>
  10811. </tr>
  10812. </table>
  10813. chapter-14/table-properties.html HTML You have already met several
  10814. properties that are commonly
  10815. used with tables. Here we will
  10816. put them together in a single
  10817. example using the following:
  10818. width to set the width of the
  10819. table
  10820. padding to set the space
  10821. between the border of each table
  10822. cell and its content
  10823. text-transform to convert the
  10824. content of the table headers to
  10825. uppercase
  10826. letter-spacing, font-size
  10827. to add additional styling to the
  10828. content of the table headers
  10829. border-top, border-bottom
  10830. to set borders above and below
  10831. the table headers
  10832. text-align to align the writing
  10833. to the left of some table cells and
  10834. to the right of the others
  10835. background-color to change
  10836. the background color of the
  10837. alternating table rows
  10838. :hover to highlight a table row
  10839. when a user's mouse goes over it
  10840. Table Properties
  10841. Article
  10842. LISTS, TABLES AND FORMS 338
  10843. Result
  10844. body {
  10845. font-family: Arial, Verdana, sans-serif;
  10846. color: #111111;}
  10847. table {
  10848. width: 600px;}
  10849. th, td {
  10850. padding: 7px 10px 10px 10px;}
  10851. th {
  10852. text-transform: uppercase;
  10853. letter-spacing: 0.1em;
  10854. font-size: 90%;
  10855. border-bottom: 2px solid #111111;
  10856. border-top: 1px solid #999;
  10857. text-align: left;}
  10858. tr.even {
  10859. background-color: #efefef;}
  10860. tr:hover {
  10861. background-color: #c3e6e5;}
  10862. .money {
  10863. text-align: right;}
  10864. CSS Here are some tips for styling
  10865. tables to ensure they are clean
  10866. and easy to follow:
  10867. Give cells padding
  10868. If the text in a table cell either
  10869. touches a border (or another
  10870. cell), it becomes much harder to
  10871. read. Adding padding helps to
  10872. improve readability.
  10873. Distinguish headings
  10874. Putting all table headings in
  10875. bold (the default style for the
  10876. <th> element) makes them
  10877. easier to read. You can also
  10878. make headings uppercase and
  10879. then either add a background
  10880. color or an underline to clearly
  10881. distinguish them from content.
  10882. Shade alternate rows
  10883. Shading every other row can
  10884. help users follow along the lines.
  10885. Use a subtle distinction from the
  10886. normal color of the rows to keep
  10887. the table looking clean.
  10888. Align numerals
  10889. You can use the text-align
  10890. property to align the content
  10891. of any column that contains
  10892. numbers to the right, so that
  10893. large numbers are clearly
  10894. distinguished from smaller ones.
  10895. Online extra
  10896. There are more examples of
  10897. using CSS to style tables in the
  10898. tools section of the website.
  10899. 339 LISTS, TABLES AND FORMS
  10900. Article
  10901. 339 LISTS, TABLES AND FORMS
  10902. Result
  10903. td {
  10904. border: 1px solid #0088dd;
  10905. padding: 15px;}
  10906. table.one {
  10907. empty-cells: show;}
  10908. table.two {
  10909. empty-cells: hide;}
  10910. CSS
  10911. <table class="one">
  10912. <tr>
  10913. <td>1</td>
  10914. <td>2</td>
  10915. </tr>
  10916. <tr>
  10917. <td>3</td>
  10918. <td></td>
  10919. </tr>
  10920. </table>
  10921. chapter-14/empty-cells.html HTML If you have empty cells in
  10922. your table, then you can use
  10923. the empty-cells property to
  10924. specify whether or not their
  10925. borders should be shown.
  10926. Since browsers treat empty cells
  10927. in different ways, if you want to
  10928. explicitly show or hide borders
  10929. on any empty cells then you
  10930. should use this property.
  10931. It can take one of three values:
  10932. show
  10933. This shows the borders of any
  10934. empty cells.
  10935. hide
  10936. This hides the borders of any
  10937. empty cells.
  10938. inherit
  10939. If you have one table nested
  10940. inside another, the inherit
  10941. value instructs the table cells to
  10942. obey the rules of the containing
  10943. table.
  10944. In the first table on the left, you
  10945. can see that the border of the
  10946. empty cell is showing. In the
  10947. second table, it is hidden.
  10948. Border on Empty Cells
  10949. empty-cells
  10950. Article
  10951. LISTS, TABLES AND FORMS 340
  10952. The border-spacing property
  10953. allows you to control the
  10954. distance between adjacent cells.
  10955. By default, browsers often leave
  10956. a small gap between each table
  10957. cell, so if you want to increase
  10958. or decrease this space then
  10959. the border-spacing property
  10960. allows you to control the gap.
  10961. The value of this property is
  10962. usually specified in pixels. You
  10963. can specify two values if desired
  10964. to specify separate numbers for
  10965. horizontal and vertical spacing.
  10966. When a border has been used
  10967. on table cells, where two cells
  10968. meet, the width of lines would be
  10969. twice that of the outside edges.
  10970. It is possible to collapse adjacent
  10971. borders to prevent this using the
  10972. border-collapse property.
  10973. Possible values are:
  10974. collapse
  10975. Borders are collapsed into a
  10976. single border where possible.
  10977. (border-spacing will be
  10978. ignored and cells pushed
  10979. together, and empty-cells
  10980. properties will be ignored.)
  10981. separate
  10982. Borders are detached from each
  10983. other. (border-spacing and
  10984. empty-cells will be obeyed.)
  10985. Gaps Between Cells
  10986. border-spacing, border-collapse
  10987. Result
  10988. td {
  10989. background-color: #0088dd;
  10990. padding: 15px;
  10991. border: 2px solid #000000;}
  10992. table.one {
  10993. border-spacing: 5px 15px;}
  10994. table.two {
  10995. border-collapse: collapse;}
  10996. CSS
  10997. <table class="one">
  10998. <tr>
  10999. <td>1</td>
  11000. <td>2</td>
  11001. </tr>
  11002. <tr>
  11003. <td>3</td>
  11004. <td>4</td>
  11005. </tr>
  11006. </table>
  11007. HTML chapter-14/gaps-between-cells.html
  11008. 341 LISTS, TABLES AND FORMS
  11009. Styling Forms
  11010. Nobody I know enjoys filling
  11011. in forms, so if you can make
  11012. yours look more attractive and
  11013. easier to use, more people are
  11014. likely to fill it in. Also, when you
  11015. come to look at a form in a few
  11016. different browsers (as shown
  11017. on the right), you will see that
  11018. each browser displays them
  11019. differently.
  11020. CSS is commonly used to
  11021. control the appearance of form
  11022. elements. This is both to make
  11023. them more attractive and to
  11024. make them more consistent
  11025. across different browsers
  11026. It is most common to style:
  11027. ● Text inputs and text areas
  11028. ● Submit buttons
  11029. ● Labels on forms, to get the
  11030. form controls to align nicely
  11031. In the coming pages you will see
  11032. how to control these with CSS.
  11033. Mac: Safari Mac: Firefox
  11034. Pc: Chrome Pc: IE
  11035. Styling text inputs and submit
  11036. buttons is fairly easy. It is
  11037. harder to get select boxes, radio
  11038. buttons, and checkboxes to look
  11039. consistent across all browsers.
  11040. To achieve this, you might like to
  11041. download the CSS files available
  11042. at http://formalize.me.
  11043. The author of this website has
  11044. done the hard work of making
  11045. forms look consistent across
  11046. browsers. Although the solution
  11047. incorporates JavaScript, no prior
  11048. knowledge of this is needed in
  11049. order to implement the code.
  11050. Article
  11051. LISTS, TABLES AND FORMS 342
  11052. Result
  11053. input {
  11054. font-size: 120%;
  11055. color: #5a5854;
  11056. background-color: #f2f2f2;
  11057. border: 1px solid #bdbdbd;
  11058. border-radius: 5px;
  11059. padding: 5px 5px 5px 30px;
  11060. background-repeat: no-repeat;
  11061. background-position: 8px 9px;
  11062. display: block;
  11063. margin-bottom: 10px;}
  11064. input:focus {
  11065. background-color: #ffffff;
  11066. border: 1px solid #b1e1e4;}
  11067. input#email {
  11068. background-image: url("images/email.png");}
  11069. input#twitter {
  11070. background-image: url("images/twitter.png");}
  11071. input#web {
  11072. background-image: url("images/web.png");}
  11073. CSS chapter-14/styling-text-inputs.html This example demonstrates the
  11074. CSS properties commonly used
  11075. with text inputs, most of which
  11076. you have already met.
  11077. font-size sets the size of the
  11078. text entered by the user.
  11079. color sets the text color, and
  11080. background-color sets the
  11081. background color of the input.
  11082. border adds a border around
  11083. the edge of the input box, and
  11084. border-radius can be used
  11085. to create rounded corners (for
  11086. browsers that support this
  11087. property).
  11088. The :focus pseudo-class is
  11089. used to change the background
  11090. color of the text input when it
  11091. is being used, and the :hover
  11092. psuedo-class applies the same
  11093. styles when the user hovers over
  11094. them.
  11095. background-image adds a
  11096. background image to the box.
  11097. Because there is a different
  11098. image for each input, we are
  11099. using an attribute selector
  11100. looking for the value of the id
  11101. attribute on each input.
  11102. You will learn more about
  11103. background images and how to
  11104. position them in Chapter 16.
  11105. Styling Text Inputs
  11106. 343 LISTS, TABLES AND FORMS
  11107. Article
  11108. 343 LISTS, TABLES AND FORMS
  11109. Result
  11110. input#submit {
  11111. color: #444444;
  11112. text-shadow: 0px 1px 1px #ffffff;
  11113. border-bottom: 2px solid #b2b2b2;
  11114. background-color: #b9e4e3;
  11115. background: -webkit-gradient(linear, left top,
  11116. left bottom, from(#beeae9), to(#a8cfce));
  11117. background:
  11118. -moz-linear-gradient(top, #beeae9, #a8cfce);
  11119. background:
  11120. -o-linear-gradient(top, #beeae9, #a8cfce);
  11121. background:
  11122. -ms-linear-gradient(top, #beeae9, #a8cfce);}
  11123. input#submit:hover {
  11124. color: #333333;
  11125. border: 1px solid #a4a4a4;
  11126. border-top: 2px solid #b2b2b2;
  11127. background-color: #a0dbc4;
  11128. background: -webkit-gradient(linear, left top,
  11129. left bottom, from(#a8cfce), to(#beeae9));
  11130. background:
  11131. -moz-linear-gradient(top, #a8cfce, #beeae9);
  11132. background:
  11133. -o-linear-gradient(top, #a8cfce, #beeae9);
  11134. background:
  11135. -ms-linear-gradient(top, #a8cfce, #beeae9);}
  11136. chapter-14/styling-submit-buttons.html CSS Here are some properties that
  11137. can be used to style submit
  11138. buttons. This example builds
  11139. on the one in the previous page,
  11140. and the submit button inherits
  11141. the styles set for the <input>
  11142. element on the last page.
  11143. color is used to change the
  11144. color of the text on the button.
  11145. text-shadow can give a 3D
  11146. look to the text in browsers that
  11147. support this property.
  11148. border-bottom has been used
  11149. to make the bottom border of
  11150. the button slightly thicker, which
  11151. gives it a more 3D feel.
  11152. background-color can make
  11153. the submit button stand out
  11154. from other items around it.
  11155. (Creating a consistent style
  11156. for all buttons helps users
  11157. understand how they should
  11158. interact with the site.) A gradient
  11159. background has been added for
  11160. browsers that support gradients.
  11161. Gradients are covered on
  11162. page 419.
  11163. The :hover pseudo-class
  11164. has been used to change the
  11165. appearance of the button when
  11166. the user hovers over it. In this
  11167. case, the background changes,
  11168. the text gets darker, and the
  11169. thicker border is applied to the
  11170. top of the button.
  11171. Styling Submit Buttons
  11172. Article
  11173. LISTS, TABLES AND FORMS 344
  11174. Result
  11175. fieldset {
  11176. width: 350px;
  11177. border: 1px solid #dcdcdc;
  11178. border-radius: 10px;
  11179. padding: 20px;
  11180. text-align: right;}
  11181. legend {
  11182. background-color: #efefef;
  11183. border: 1px solid #dcdcdc;
  11184. border-radius: 10px;
  11185. padding: 10px 20px;
  11186. text-align: left;
  11187. text-transform: uppercase;}
  11188. CSS chapter-14/styling-fieldsets-and-legends.html Fieldsets are particularly helpful
  11189. in determining the edges of a
  11190. form. In a long form they can
  11191. help group together related
  11192. information within it.
  11193. The legend is used to indicate
  11194. what information is required in
  11195. the fieldset.
  11196. Properties commonly used with
  11197. these two elements include:
  11198. width is used to control
  11199. the width of the fieldset. In
  11200. this example, the width of
  11201. the fieldset forces the form
  11202. elements to wrap onto a new line
  11203. in the correct place. (If it were
  11204. wider, the items might sit on one
  11205. line.)
  11206. color is used to control the
  11207. color of text.
  11208. background-color is used to
  11209. change the color behind these
  11210. items.
  11211. border is used to control the
  11212. appearance of the border around
  11213. the fieldset and/or legend.
  11214. border-radius is used to
  11215. soften the edges of these
  11216. elements in browsers that
  11217. support this property.
  11218. padding can be used to add
  11219. space inside these elements.
  11220. Styling Fieldsets
  11221. & Legends
  11222. 345 LISTS, TABLES AND FORMS
  11223. Article
  11224. 345 LISTS, TABLES AND FORMS
  11225. <form action="example.php" method="post">
  11226. <div>
  11227. <label for="name" class="title">Name:</label>
  11228. <input type="text" id="name" name="name" />
  11229. </div>
  11230. <div>
  11231. <label for="email" class="title">Email:</label>
  11232. <input type="email" id="email" name="email" />
  11233. </div>
  11234. <div>
  11235. <span class="title">Gender:</span>
  11236. <input type="radio" name="gender" id="male"
  11237. value="M" />
  11238. <label for="male">Male</label>
  11239. <input type="radio" name="gender" id="female"
  11240. value="F" />
  11241. <label for="female">Female</label><br />
  11242. </div>
  11243. <div>
  11244. <input type="submit" value="Register"
  11245. id="submit" />
  11246. </div>
  11247. </form>
  11248. chapter-14/aligning-form-controls-problem.html HTML
  11249. Labels for form elements are
  11250. often different lengths, which
  11251. means that the form controls will
  11252. not appear in a straight line. This
  11253. is demonstrated in the example
  11254. on the right (without CSS applied
  11255. to the form controls).
  11256. In this form, each topic we ask
  11257. the user about is placed inside
  11258. a <div> element to ensure that
  11259. each question appears on a new
  11260. line. It is easier for users to fill in
  11261. a form if the form controls are
  11262. aligned in a straight vertical line.
  11263. The CSS on the opposite page
  11264. addresses this.
  11265. If you look at where we ask
  11266. users their gender, the two
  11267. radio buttons each have their
  11268. own <label> (one saying male
  11269. and another saying female). A
  11270. <span> element has been added
  11271. to the title which will help align
  11272. these controls.
  11273. On the previous page we saw
  11274. another technique to align form
  11275. elements. When the form only
  11276. contains text inputs, by setting
  11277. all of the text inputs to be the
  11278. same width, as well as aligning
  11279. all of the form content to the
  11280. right, the fields line up and the
  11281. labels are in a consistent place.
  11282. For more complex forms, you
  11283. will need a solution more like the
  11284. one shown on these pages.
  11285. Aligning Form
  11286. Controls: Problem
  11287. Result Without CSS
  11288. Article
  11289. LISTS, TABLES AND FORMS 346
  11290. Each row of the form has a title
  11291. telling users what they need to
  11292. enter. For the text inputs, the
  11293. title is in the <label> element.
  11294. For the radio buttons, the title is
  11295. in a <span> element. Both have
  11296. a class attribute with a value of
  11297. title.
  11298. We can use a property called
  11299. float to move the titles to the
  11300. left of the page. (The float
  11301. property is covered in greater
  11302. detail on pages 370-376.)
  11303. By setting the width property
  11304. on those elements, we know that
  11305. the titles will each take up the
  11306. same width. Therefore, the form
  11307. controls next to them will line up.
  11308. The text-align property is
  11309. used to align the titles to the
  11310. right, and padding is used
  11311. to make sure there is a gap
  11312. between the text in the title
  11313. boxes and the form controls.
  11314. Styles are also applied to the
  11315. <div> elements that contain
  11316. each row of the form (fixing
  11317. their width and creating vertical
  11318. space between each row). The
  11319. submit button is also aligned to
  11320. the right.
  11321. Result
  11322. Aligning Form
  11323. Controls: Solution
  11324. div {
  11325. border-bottom: 1px solid #efefef;
  11326. margin: 10px;
  11327. padding-bottom: 10px;
  11328. width: 260px;}
  11329. .title {
  11330. float: left;
  11331. width: 100px;
  11332. text-align: right;
  11333. padding-right: 10px;}
  11334. .radio-buttons label {
  11335. float: none;}
  11336. .submit {
  11337. text-align: right;}
  11338. CSS chapter-14/aligning-form-controls-solution.html
  11339. 347 LISTS, TABLES AND FORMS
  11340. Article
  11341. 347 LISTS, TABLES AND FORMS
  11342. a {
  11343. cursor: move;}
  11344. CSS
  11345. Result
  11346. <a href="http://www.whitmanarchive.org">
  11347. Walt Whitman</a>
  11348. chapter-14/cursor.html HTML
  11349. The cursor property allows
  11350. you to control the type of mouse
  11351. cursor that should be displayed
  11352. to users.
  11353. For example, on a form you
  11354. might set the cursor to be a hand
  11355. when the user hovers over it.
  11356. Here are the most commonly
  11357. used values for this property:
  11358. auto
  11359. crosshair
  11360. default
  11361. pointer
  11362. move
  11363. text
  11364. wait
  11365. help
  11366. url("cursor.gif");
  11367. You should only use these values
  11368. to add helpful information for
  11369. users in places they would
  11370. expect to see that cursor. (For
  11371. example, using a crosshair on a
  11372. link might confuse users because
  11373. they are not used to seeing it.)
  11374. Cursor Styles
  11375. cursor
  11376. LISTS, TABLES AND FORMS 348
  11377. This helpful extension for Firefox and Chrome
  11378. provides tools to show you the CSS styles that
  11379. apply to an element when you hover over it,
  11380. along with the structure of the HTML.
  11381. Web Developer
  11382. Toolbar
  11383. Download this tool from:
  11384. www.chrispederick.com/
  11385. work/web-developer
  11386. To see the CSS styles and HTML
  11387. structure of a web page, go
  11388. to the CSS menu of the Web
  11389. Developer Toolbar and pick View
  11390. Style Information.
  11391. 1: Outlines
  11392. When you hover over an
  11393. element, a red outline will be
  11394. drawn around it, showing you
  11395. how much space the element
  11396. takes up.
  11397. This tool also allows you to change the screen size, validate your HTML and CSS code, and turn off images.
  11398. 2: Structure
  11399. While you are hovering over
  11400. an element, the structure will
  11401. be shown at the top of the
  11402. window. Here you can see the
  11403. <li> element has a class of
  11404. completed, inside a <ul> with
  11405. a class called to-do. The list
  11406. is inside a <div> element with
  11407. an id of page, and this sits
  11408. inside the <body> and <html>
  11409. elements.
  11410. This can be very helpful when
  11411. writing CSS selectors to help you
  11412. target the right element.
  11413. 3: CSS styles
  11414. When hovering over an element,
  11415. click with your mouse to display
  11416. the CSS. You will be shown the
  11417. rules that apply to that element
  11418. (and the line they are on). Above
  11419. the rules, you can see the name
  11420. of the style sheet (and the path
  11421. to it).
  11422. This helps check which styles
  11423. are being applied to an element.
  11424. You can use it on code for your
  11425. own site or when you want to
  11426. see what styles someone else is
  11427. using on their site.
  11428. 1
  11429. 2
  11430. 3
  11431. 349 LISTS, TABLES AND FORMS
  11432. Example
  11433. LISTS, TABLES AND FORMS
  11434. LISTS, TABLES AND FORMS 350
  11435. For the list of free poetry events near the start of the page, the bullet
  11436. points are styled with an image. The space between each list item is
  11437. increased using the line-height property.
  11438. For the table, the gaps between cells are removed using the borderspacing
  11439. property. Font size is set for the <td> and <th> elements as
  11440. they do not inherit their size from parent elements.
  11441. The head of the table has a darker background, light text, and a dark
  11442. 2-pixel line between it and the table content. Rounded corners on the
  11443. table header are created using the :first-child and :last-child
  11444. pseudo classes (for browsers that support rounded corners).
  11445. Alternate rows of the table have different shading, and texture is added
  11446. with different borders on each side of the cell.
  11447. For the form, the related form controls are put in a <fieldset> element.
  11448. The labels of the form controls on the left also use the float property to
  11449. ensure the form controls are vertically aligned.
  11450. When the text boxes of the form receive focus, or the user hovers over it,
  11451. the background color and border colors change. The submit button has
  11452. also been styled to make it clear where people should submit the form.
  11453. This example demonstrates several of the
  11454. CSS properties we have met in this chapter to
  11455. control the presentation of lists, tables, and
  11456. forms.
  11457. 351 LISTS, TABLES AND FORMS
  11458. Example
  11459. LISTS, TABLES AND FORMS
  11460. <!DOCTYPE html>
  11461. <html>
  11462. <head>
  11463. <title>Lists, Tables and Forms</title>
  11464. <style type="text/css">
  11465. body {
  11466. font-family: Arial, Verdana, sans-serif;
  11467. font-size: 90%;
  11468. color: #666;
  11469. background-color: #f8f8f8;}
  11470. li {
  11471. list-style-image: url("images/icon-plus.png");
  11472. line-height: 1.6em;}
  11473. table {
  11474. border-spacing: 0px;}
  11475. th, td {
  11476. padding: 5px 30px 5px 10px;
  11477. border-spacing: 0px;
  11478. font-size: 90%;
  11479. margin: 0px;}
  11480. th, td {
  11481. text-align: left;
  11482. background-color: #e0e9f0;
  11483. border-top: 1px solid #f1f8fe;
  11484. border-bottom: 1px solid #cbd2d8;
  11485. border-right: 1px solid #cbd2d8;}
  11486. tr.head th {
  11487. color: #fff;
  11488. background-color: #90b4d6;
  11489. border-bottom: 2px solid #547ca0;
  11490. border-right: 1px solid #749abe;
  11491. border-top: 1px solid #90b4d6;
  11492. text-align: center;
  11493. text-shadow: -1px -1px 1px #666;
  11494. letter-spacing: 0.15em;}
  11495. td {
  11496. text-shadow: 1px 1px 1px #fff;}
  11497. LISTS, TABLES AND FORMS 352
  11498. Example
  11499. LISTS, TABLES AND FORMS
  11500. tr.even td, tr.even th {
  11501. background-color: #e8eff5;}
  11502. tr.head th:first-child {
  11503. -webkit-border-top-left-radius: 5px;
  11504. -moz-border-radius-topleft: 5px;
  11505. border-top-left-radius: 5px;}
  11506. tr.head th:last-child {
  11507. -webkit-border-top-right-radius: 5px;
  11508. -moz-border-radius-topright: 5px;
  11509. border-top-right-radius: 5px;}
  11510. fieldset {
  11511. width: 310px;
  11512. margin-top: 20px;
  11513. border: 1px solid #d6d6d6;
  11514. background-color: #ffffff;
  11515. line-height: 1.6em;}
  11516. legend {
  11517. font-style:italic;
  11518. color:#666666;}
  11519. input[type="text"] {
  11520. width: 120px;
  11521. border: 1px solid #d6d6d6;
  11522. padding: 2px;
  11523. outline: none;}
  11524. input[type="text"]:focus,
  11525. input[type="text"]:hover {
  11526. background-color: #d0e2f0;
  11527. border: 1px solid #999;}
  11528. input[type="submit"] {
  11529. border: 1px solid #006633;
  11530. background-color: #009966;
  11531. color: #FFFFFF;
  11532. border-radius: 5px;
  11533. padding: 5px;
  11534. margin-top: 10px;}
  11535. input[type="submit"]:hover {
  11536. border: 1px solid #006633;
  11537. 353 LISTS, TABLES AND FORMS
  11538. Example
  11539. LISTS, TABLES AND FORMS
  11540. background-color: #00CC33;
  11541. color: #FFFFFF;
  11542. cursor: pointer;}
  11543. .title {
  11544. float: left;
  11545. width: 160px;
  11546. clear: left;}
  11547. .submit {
  11548. width: 310px;
  11549. text-align: right;}
  11550. </style>
  11551. </head>
  11552. <body>
  11553. <h1>Poetry Workshops</h1>
  11554. <p>We will be conducting a number of poetry workshops
  11555. and symposiums throughout the year.</p>
  11556. <p>Please note that the following events are free to
  11557. members:</p>
  11558. <ul>
  11559. <li>A Poetic Perspective</li>
  11560. <li>Walt Whitman at War</li>
  11561. <li>Found Poems and Outsider Poetry</li>
  11562. </ul>
  11563. <table>
  11564. <tr class="head">
  11565. <th></th>
  11566. <th>New York</th>
  11567. <th>Chicago</th>
  11568. <th>San Francisco</th>
  11569. </tr>
  11570. <tr>
  11571. <th>A Poetic Perspective</th>
  11572. <td>Sat, 4 Feb 2012<br />11am - 2pm</td>
  11573. <td>Sat, 3 Mar 2012<br />11am - 2pm</td>
  11574. <td>Sat, 17 Mar 2012<br />11am - 2pm</td>
  11575. </tr>
  11576. <tr class="even">
  11577. <th>Walt Whitman at War</th>
  11578. LISTS, TABLES AND FORMS 354
  11579. Example
  11580. LISTS, TABLES AND FORMS
  11581. <td>Sat, 7 Apr 2012<br />11am - 1pm</td>
  11582. <td>Sat, 5 May 2012<br />11am - 1pm</td>
  11583. <td>Sat, 19 May 2012<br />11am - 1pm</td>
  11584. </tr>
  11585. <tr>
  11586. <th>Found Poems &amp; Outsider Poetry</th>
  11587. <td>Sat, 9 Jun 2012<br />11am - 2pm</td>
  11588. <td>Sat, 7 Jul 2012<br />11am - 2pm</td>
  11589. <td>Sat, 21 Jul 2012<br />11am - 2pm</td>
  11590. </tr>
  11591. <tr class="even">
  11592. <th>Natural Death: An Exploration</th>
  11593. <td>Sat, 4 Aug 2012<br />11am - 4pm</td>
  11594. <td>Sat, 8 Sep 2012<br />11am - 4pm</td>
  11595. <td>Sat, 15 Sep 2012<br />11am - 4pm</td>
  11596. </tr>
  11597. </table>
  11598. <form action="http://www.example.com/form.php" method="get">
  11599. <fieldset>
  11600. <legend>Register your interest</legend>
  11601. <p><label class="title" for="name">Your name:</label>
  11602. <input type="text" name="name" id="name"><br />
  11603. <label class="title" for="email">Your email:</label>
  11604. <input type="text" name="email" id="email"></p>
  11605. <p><label for="location" class="title">Your closest center:</label>
  11606. <select name="location" id="location">
  11607. <option value="ny">New York</option>
  11608. <option value="il">Chicago</option>
  11609. <option value="ca">San Francisco</option>
  11610. </select></p>
  11611. <span class="title">Are you a member?</span>
  11612. <label><input type="radio" name="member" value="yes" /> Yes</label>
  11613. <label><input type="radio" name="member" value="no" /> No</label></p>
  11614. </fieldset>
  11615. <div class="submit"><input type="submit" value="Register" /></div>
  11616. </form>
  11617. </body>
  11618. </html>
  11619.  
  11620. Summary
  11621. LISTS, TABLES AND FORMS
  11622. X In addition to the CSS properties covered in other
  11623. chapters which work with the contents of all elements,
  11624. there are several others that are specifically used to
  11625. control the appearance of lists, tables, and forms.
  11626. X List markers can be given different appearances
  11627. using the list-style-type and list-style image
  11628. properties.
  11629. X Table cells can have different borders and spacing in
  11630. different browsers, but there are properties you can
  11631. use to control them and make them more consistent.
  11632. X Forms are easier to use if the form controls are
  11633. vertically aligned using CSS.
  11634. X Forms benefit from styles that make them feel more
  11635. interactive.
  11636.  
  11637. X Controlling the position of elements
  11638. X Creating site layouts
  11639. X Designing for different sized screens
  11640. Layout
  11641. 15
  11642. 359 LAYOUT
  11643. In this chapter we are going to look at
  11644. how to control where each element sits
  11645. on a page and how to create attractive
  11646. page layouts.
  11647. This involves learning about how designing for a screen can be
  11648. different to designing for other mediums (such as print). In this
  11649. chapter we will:
  11650. ● Explore different ways to position elements using normal
  11651. flow, relative positioning, absolute positioning and floats.
  11652. ● Discover how various devices have different screen sizes
  11653. and resolution, and how this affects the design process.
  11654. ● Learn the difference between fixed width and liquid layouts,
  11655. and how they are created.
  11656. ● Find out how designers use grids to make their page
  11657. designs look more professional.
  11658. LAYOUT 360
  11659. 361 LAYOUT
  11660. Key Concepts in
  11661. Positioning Elements
  11662. Building Blocks
  11663. CSS treats each HTML element as if it is in its
  11664. own box. This box will either be a block-level
  11665. box or an inline box.
  11666. Block-level boxes start on a new line and act as the main building blocks
  11667. of any layout, while inline boxes flow between surrounding text. You can
  11668. control how much space each box takes up by setting the width of the
  11669. boxes (and sometimes the height, too). To separate boxes, you can use
  11670. borders, margins, padding, and background colors.
  11671. Block-level elements
  11672. start on a new line
  11673. Examples include:
  11674. <h1> <p> <ul> <li>
  11675. Inline elements
  11676. flow in between
  11677. surrounding text
  11678. Examples include:
  11679. <img> <b> <i>
  11680. Lorem Ipsum
  11681. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
  11682. eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
  11683. enim ad minim veniam, quis nostrud exercitation ullamco laboris
  11684. nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
  11685. reprehenderit in voluptate velit.
  11686. • Lorem ipsum dolor sit
  11687. • Consectetur adipisicing
  11688. • Elit, sed do eiusmod
  11689. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
  11690. eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
  11691. enim ad minim veniam, quis nostrud exercitation ullamco laboris
  11692. nisi ut aliquip ex ea commodo consequat.
  11693. Duis aute irure dolor in reprehenderit in voluptate
  11694. velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
  11695. sint occaecat cupidatat non proident, sunt in culpa qui officia
  11696. deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet,
  11697. consectetur adipisicing elit, sed do eiusmod tempor incididunt ut
  11698. labore et dolore magna aliqua.
  11699. LAYOUT 362
  11700. Lorem • Ipsum • Dolor • Consectetur Lorem Ipsum
  11701. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
  11702. tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
  11703. veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
  11704. commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
  11705. velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat.
  11706. Lorem ipsum dolor sit amet, consectetur
  11707. adipisicing elit, sed do eiusmod tempor incididunt
  11708. ut labore et dolore magna aliqua. Ut enim ad
  11709. minim veniam, quis nostrud exercitation ullamco
  11710. laboris nisi ut aliquip ex ea commodo consequat.
  11711. Duis aute.
  11712. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
  11713. Containing Elements
  11714. If one block-level element sits inside another
  11715. block-level element then the outer box is
  11716. known as the containing or parent element.
  11717. It is common to group a number of elements together inside a <div>
  11718. (or other block-level) element. For example, you might group together
  11719. all of the elements that form the header of a site (such as the logo and
  11720. the main navigation). The <div> element that contains this group of
  11721. elements is then referred to as the containing element.
  11722. A box may be nested inside
  11723. several other block-level
  11724. elements. The containing
  11725. element is always the direct
  11726. parent of that element.
  11727. The orange lines in this diagram represent <div> elements. The
  11728. header (containing the logo and navigation) are in one <div> element,
  11729. the main content of the page is in another, and the footer is in a third.
  11730. The <body> element is the containing element for these three <div>
  11731. elements. The second <div> element is the containing element for two
  11732. paragraphs of Latin text and images (represented by crossed squares).
  11733. 363 LAYOUT
  11734. Controlling the
  11735. Position of Elements
  11736. Lorem Ipsum
  11737. Lorem ipsum dolor sit amet,
  11738. consectetur adipisicing elit, sed do
  11739. eiusmod tempor incididunt ut labore et
  11740. dolore magna aliqua.
  11741. Ut enim ad minim veniam, quis nostrud
  11742. exercitation ullamco laboris nisi ut
  11743. aliquip ex ea commodo consequat.
  11744. Duis aute irure dolor in reprehenderit
  11745. in voluptate velit.
  11746. Lorem Ipsum
  11747. Lorem ipsum dolor sit amet,
  11748. consectetur adipisicing elit, sed do
  11749. eiusmod tempor incididunt ut.
  11750. Ut enim ad minim veniam, quis
  11751. nostrud exercitation ullamco
  11752. laboris nisi ut aliquip ex ea.
  11753. Duis aute irure dolor in reprehenderit
  11754. in voluptate velit.
  11755. Lorem ipsum dolor sit amet,
  11756. consectetur adipisicing elit, sed do
  11757. eiusmod tempor incididunt ut labore et
  11758. dolore magna aliqua.
  11759. Ut enim ad minim veniam, quis nostrud
  11760. exercitation ullamco laboris nisi ut
  11761. aliquip ex ea commodo consequat.
  11762. Duis aute irure dolor in reprehenderit
  11763. in voluptate velit.
  11764. Lorem Ipsum
  11765. CSS has the following positioning schemes that allow you to control
  11766. the layout of a page: normal flow, relative positioning, and absolute
  11767. positioning. You specify the positioning scheme using the position
  11768. property in CSS. You can also float elements using the float property.
  11769. Normal flow
  11770. Every block-level element
  11771. appears on a new line, causing
  11772. each item to appear lower down
  11773. the page than the previous one.
  11774. Even if you specify the width
  11775. of the boxes and there is space
  11776. for two elements to sit side-byside,
  11777. they will not appear next
  11778. to each other. This is the default
  11779. behavior (unless you tell the
  11780. browser to do something else).
  11781. Relative Positioning
  11782. This moves an element from the
  11783. position it would be in normal
  11784. flow, shifting it to the top, right,
  11785. bottom, or left of where it
  11786. would have been placed. This
  11787. does not affect the position of
  11788. surrounding elements; they stay
  11789. in the position they would be in
  11790. in normal flow.
  11791. Absolute positioning
  11792. This positions the element
  11793. in relation to its containing
  11794. element. It is taken out of
  11795. normal flow, meaning that it
  11796. does not affect the position
  11797. of any surrounding elements
  11798. (as they simply ignore the
  11799. space it would have taken up).
  11800. Absolutely positioned elements
  11801. move as users scroll up and
  11802. down the page.
  11803. The paragraphs appear one
  11804. after the other, vertically down
  11805. the page.
  11806. The second paragraph has been
  11807. pushed down and right from
  11808. where it would otherwise have
  11809. been in normal flow.
  11810. The heading is positioned to the
  11811. top right, and the paragraphs
  11812. start at the top of the screen (as
  11813. if the heading were not there).
  11814. See page 365 See page 366 See page 367
  11815. LAYOUT 364
  11816. Lorem ipsum dolor sit amet,
  11817. consectetur adipisicing elit, sed do
  11818. eiusmod tempor incididunt ut labore et
  11819. dolore magna aliqua.
  11820. Ut enim ad minim veniam, quis nostrud
  11821. exercitation ullamco laboris nisi ut
  11822. aliquip ex ea commodo consequat.
  11823. Duis aute irure dolor in reprehenderit
  11824. in voluptate velit.
  11825. Lorem Ipsum
  11826. Lorem ipsum dolor sit
  11827. amet, consectetur
  11828. adipisicing elit, sed do
  11829. eiusmod tempor incididunt ut labore et
  11830. dolore magna aliqua.
  11831. Ut enim ad minim veniam, quis nostrud
  11832. exercitation ullamco laboris nisi ut
  11833. aliquip ex ea commodo consequat.
  11834. Duis aute irure dolor in reprehenderit
  11835. in voluptate velit.
  11836. Lorem
  11837. Ipsum
  11838. To indicate where a box should be positioned, you may also need to use
  11839. box offset properties to tell the browser how far from the top or bottom
  11840. and left or right it should be placed. (You will meet these when we
  11841. introduce the positioning schemes on the following pages.)
  11842. Fixed Positioning
  11843. This is a form of absolute
  11844. positioning that positions
  11845. the element in relation to the
  11846. browser window, as opposed
  11847. to the containing element.
  11848. Elements with fixed positioning
  11849. do not affect the position of
  11850. surrounding elements and they
  11851. do not move when the user
  11852. scrolls up or down the page.
  11853. Floating Elements
  11854. Floating an element allows
  11855. you to take that element out
  11856. of normal flow and position
  11857. it to the far left or right of a
  11858. containing box. The floated
  11859. element becomes a block-level
  11860. element around which other
  11861. content can flow.
  11862. When you move
  11863. any element from
  11864. normal flow, boxes
  11865. can overlap. The
  11866. z-index property
  11867. allows you to control
  11868. which box appears
  11869. on top. The heading has been placed in
  11870. the center of the page and 25%
  11871. from the top of the screen. (The
  11872. rest appears in normal flow.)
  11873. The heading has been floated to
  11874. the left, allowing the paragraphs
  11875. of text to flow around it.
  11876. See page 368 See page 370-376
  11877. 365 LAYOUT
  11878. Article
  11879. 365 LAYOUT
  11880. Result
  11881. body {
  11882. width: 750px;
  11883. font-family: Arial, Verdana, sans-serif;
  11884. color: #665544;}
  11885. h1 {
  11886. background-color: #efefef;
  11887. padding: 10px;}
  11888. p {
  11889. width: 450px;}
  11890. In normal flow, each block-level
  11891. element sits on top of the next
  11892. one. Since this is the default
  11893. way in which browsers treat
  11894. HTML elements, you do not
  11895. need a CSS property to indicate
  11896. that elements should appear
  11897. in normal flow, but the syntax
  11898. would be:
  11899. position: static;
  11900. I have not specified a width
  11901. property for the heading
  11902. element, so you can see how it
  11903. stretches the width of the entire
  11904. browser window by default.
  11905. The paragraphs are restricted
  11906. to 450 pixels wide. This shows
  11907. how the elements in normal flow
  11908. start on a new line even if they
  11909. do not take up the full width of
  11910. the browser window.
  11911. All of the examples that
  11912. demonstrate positioning will use
  11913. a similar HTML structure.
  11914. CSS
  11915. <body>
  11916. <h1>The Evolution of the Bicycle</h1>
  11917. <p>In 1817 Baron von Drais invented a walking
  11918. machine that would help him get around the
  11919. royal gardens faster...</p>
  11920. </body>
  11921. chapter-15/normal-flow.html HTML
  11922. Normal Flow
  11923. position:static
  11924. Article
  11925. LAYOUT 366
  11926. Relative positioning moves an
  11927. element in relation to where it
  11928. would have been in normal flow.
  11929. For example, you can move it 10
  11930. pixels lower than it would have
  11931. been in normal flow or 20% to
  11932. the right.
  11933. You can indicate that an element
  11934. should be relatively positioned
  11935. using the position property
  11936. with a value of relative.
  11937. You then use the offset
  11938. properties (top or bottom and
  11939. left or right) to indicate how
  11940. far to move the element from
  11941. where it would have been in
  11942. normal flow.
  11943. To move the box up or down,
  11944. you can use either the top or
  11945. bottom properties.
  11946. To move the box horizontally,
  11947. you can use either the left or
  11948. right properties.
  11949. The values of the box offset
  11950. properties are usually given in
  11951. pixels, percentages or ems.
  11952. Result
  11953. p.example {
  11954. position: relative;
  11955. top: 10px;
  11956. left: 100px;}
  11957. CSS
  11958. <body>
  11959. <h1>The Evolution of the Bicycle</h1>
  11960. <p>In 1817 Baron von Drais invented a walking
  11961. machine that would help him get around the
  11962. royal gardens faster...</p>
  11963. </body>
  11964. HTML chapter-15/position-relative.html
  11965. Relative Positioning
  11966. position:relative
  11967. 367 LAYOUT
  11968. Article
  11969. 367 LAYOUT
  11970. When the position property
  11971. is given a value of absolute,
  11972. the box is taken out of normal
  11973. flow and no longer affects the
  11974. position of other elements on
  11975. the page. (They act like it is not
  11976. there.)
  11977. The box offset properties (top
  11978. or bottom and left or right)
  11979. specify where the element
  11980. should appear in relation to its
  11981. containing element.
  11982. In this example, the heading has
  11983. been positioned at the top of the
  11984. page and 500 pixels from its left
  11985. edge. The width of the heading is
  11986. set to be 250 pixels wide.
  11987. The width property has
  11988. also been applied to the <p>
  11989. elements in this example
  11990. to prevent the text from
  11991. overlapping and becoming
  11992. unreadable.
  11993. By default, most browsers add
  11994. a margin to the top of the <h1>
  11995. element. This is why there is
  11996. a gap between the top of the
  11997. browser and the box containing
  11998. the <h1> element. If you wanted
  11999. to remove this margin, you could
  12000. add the following code to the
  12001. <h1> element's style rules:
  12002. margin: 0px;
  12003. Result
  12004. h1 {
  12005. position: absolute;
  12006. top: 0px;
  12007. left: 500px;
  12008. width: 250px;}
  12009. p {
  12010. width: 450px;}
  12011. CSS
  12012. <body>
  12013. <h1>The Evolution of the Bicycle</h1>
  12014. <p>In 1817 Baron von Drais invented a walking
  12015. machine that would help him get around the
  12016. royal gardens faster...</p>
  12017. </body>
  12018. chapter-15/position-absolute.html HTML
  12019. Absolute Positioning
  12020. position:absolute
  12021. Article
  12022. LAYOUT 368
  12023. Fixed positioning is a type
  12024. of absolute positioning that
  12025. requires the position property
  12026. to have a value of fixed.
  12027. It positions the element in
  12028. relation to the browser window.
  12029. Therefore, when a user scrolls
  12030. down the page, it stays in the
  12031. exact same place. It is a good
  12032. idea to try this example in your
  12033. browser to see the effect.
  12034. To control where the fixed
  12035. position box appears in relation
  12036. to the browser window, the box
  12037. offset properties are used.
  12038. In this example, the heading
  12039. has been positioned to the top
  12040. left hand corner of the browser
  12041. window. When the user scrolls
  12042. down the page, the paragraphs
  12043. disappear behind the heading.
  12044. The <p> elements are in normal
  12045. flow and ignore the space that
  12046. the <h1> element would have
  12047. taken up. Therefore, the
  12048. margin-top property has
  12049. been used to push the first <p>
  12050. element below where the fixed
  12051. position <h1> element is sitting.
  12052. Result
  12053. h1 {
  12054. position: fixed;
  12055. top: 0px;
  12056. left: 50px;
  12057. padding: 10px;
  12058. margin: 0px;
  12059. width: 100%;
  12060. background-color: #efefef;}
  12061. p.example {
  12062. margin-top: 100px;}
  12063. CSS
  12064. <body>
  12065. <h1>The Evolution of the Bicycle</h1>
  12066. <p class="example">In 1817 Baron von Drais
  12067. invented a walking machine that would help him
  12068. get around the royal gardens faster...</p>
  12069. </body>
  12070. HTML chapter-15/position-fixed.html
  12071. Fixed Positioning
  12072. position:fixed
  12073. 369 LAYOUT
  12074. Article
  12075. 369 LAYOUT
  12076. h1 {
  12077. position: fixed;
  12078. top: 0px;
  12079. left: 0px;
  12080. margin: 0px;
  12081. padding: 10px;
  12082. width: 100%;
  12083. background-color: #efefef;
  12084. z-index: 10;}
  12085. p {
  12086. position: relative;
  12087. top: 70px;
  12088. left: 70px;}
  12089. chapter-15/z-index.html CSS When you use relative, fixed, or
  12090. absolute positioning, boxes can
  12091. overlap. If boxes do overlap, the
  12092. elements that appear later in the
  12093. HTML code sit on top of those
  12094. that are earlier in the page.
  12095. If you want to control which
  12096. element sits on top, you can use
  12097. the z-index property. Its value
  12098. is a number, and the higher the
  12099. number the closer that element
  12100. is to the front. For example, an
  12101. element with a z-index of 10
  12102. will appear over the top of one
  12103. with a z-index of 5.
  12104. This example looks similar to
  12105. the one on page 368, but it
  12106. uses relative positioning for
  12107. the <p> elements. Because
  12108. the paragraphs are relatively
  12109. positioned, by default they
  12110. would appear over the top of the
  12111. heading as the user scrolls down
  12112. the page. To ensure that the
  12113. <h1> element stays on top, we
  12114. use the z-index property on the
  12115. rule for the <h1> element.
  12116. The z-index is sometimes
  12117. referred to as the stacking
  12118. context (as if the blocks have
  12119. been stacked on top of each
  12120. other on a z axis). If you are
  12121. familiar with desktop publishing
  12122. packages, it is the equivalent
  12123. of using the 'bring to front' and
  12124. 'send to back' features.
  12125. Overlapping Elements
  12126. z-index
  12127. Result without z-index
  12128. Result with z-index
  12129. Article
  12130. LAYOUT 370
  12131. The float property allows you
  12132. to take an element in normal
  12133. flow and place it as far to the
  12134. left or right of the containing
  12135. element as possible.
  12136. Anything else that sits inside
  12137. the containing element will
  12138. flow around the element that is
  12139. floated.
  12140. When you use the float
  12141. property, you should also use the
  12142. width property to indicate how
  12143. wide the floated element should
  12144. be. If you do not, results can be
  12145. inconsistent but the box is likely
  12146. to take up the full width of the
  12147. containing element (just like it
  12148. would in normal flow).
  12149. In this example, a
  12150. <blockquote> element is
  12151. used to hold a quotation. It's
  12152. containing element is the
  12153. <body> element.
  12154. The <blockquote> element
  12155. is floated to the right, and the
  12156. paragraphs that follow the quote
  12157. flow around the floated element.
  12158. blockquote {
  12159. float: right;
  12160. width: 275px;
  12161. font-size: 130%;
  12162. font-style: italic;
  12163. font-family: Georgia, Times, serif;
  12164. margin: 0px 0px 10px 10px;
  12165. padding: 10px;
  12166. border-top: 1px solid #665544;
  12167. border-bottom: 1px solid #665544;}
  12168. CSS
  12169. <h1>The Evolution of the Bicycle</h1>
  12170. <blockquote>"Life is like riding a bicycle.
  12171. To keep your balance you must keep moving." -
  12172. Albert Einstein</blockquote>
  12173. <p>In 1817 Baron von Drais invented a walking
  12174. machine that would help him get around the royal
  12175. gardens faster: two same-size in-line wheels, the
  12176. front one steerable, mounted in a frame ... </p>
  12177. HTML chapter-15/float.html
  12178. Floating Elements
  12179. float
  12180. Result
  12181. 371 LAYOUT
  12182. Article
  12183. 371 LAYOUT
  12184. Result
  12185. body {
  12186. width: 750px;
  12187. font-family: Arial, Verdana, sans-serif;
  12188. color: #665544;}
  12189. p {
  12190. width: 230px;
  12191. float: left;
  12192. margin: 5px;
  12193. padding: 5px;
  12194. background-color: #efefef;}
  12195. CSS
  12196. <body>
  12197. <h1>The Evolution of the Bicycle</h1>
  12198. <p>In 1817 Baron von Drais invented a walking
  12199. machine that would help him get around...</p>
  12200. </body>
  12201. chapter-15/using-float.html HTML A lot of layouts place boxes
  12202. next to each other. The float
  12203. property is commonly used to
  12204. achieve this.
  12205. When elements are floated, the
  12206. height of the boxes can affect
  12207. where the following elements sit.
  12208. In this example, you can see six
  12209. paragraphs, each of which has a
  12210. width and a float property set.
  12211. The fourth paragraph does not
  12212. go across to the left hand edge
  12213. of the page as one might expect.
  12214. Rather it sits right under the
  12215. third paragraph.
  12216. The reason for this is that the
  12217. fourth paragraph has space to
  12218. start under the third paragraph,
  12219. but it cannot go any further to
  12220. the left because the second
  12221. paragraph is in the way.
  12222. Setting the height of the
  12223. paragraphs to be the same
  12224. height as the tallest paragraph
  12225. would solve this issue, but it
  12226. is rarely suited to real world
  12227. designs where the amount of
  12228. text in a paragraph or column
  12229. may vary. It is more common
  12230. to use the clear property
  12231. (discussed on the next page) to
  12232. solve this issue.
  12233. Using Float to Place
  12234. Elements Side-by-Side
  12235. Article
  12236. LAYOUT 372
  12237. The clear property allows you
  12238. to say that no element (within
  12239. the same containing element)
  12240. should touch the left or righthand
  12241. sides of a box. It can take
  12242. the following values:
  12243. left
  12244. The left-hand side of the box
  12245. should not touch any other
  12246. elements appearing in the same
  12247. containing element.
  12248. right
  12249. The right-hand side of the
  12250. box will not touch elements
  12251. appearing in the same containing
  12252. element.
  12253. both
  12254. Neither the left nor right-hand
  12255. sides of the box will touch
  12256. elements appearing in the same
  12257. containing element.
  12258. none
  12259. Elements can touch either side.
  12260. In this example, the fourth
  12261. paragraph has a class called
  12262. clear. The CSS rule for this
  12263. class uses the clear property
  12264. to indicate that nothing should
  12265. touch the left-hand side of it. The
  12266. fourth paragraph is therefore
  12267. moved further down the page
  12268. so no other element touches its
  12269. left-hand side.
  12270. Clearing Floats
  12271. clear
  12272. <p class="clear">In 1865, the velocipede (meaning
  12273. "fast foot") attached pedals to the front wheel,
  12274. but its wooden structure made it extremely
  12275. uncomfortable.</p>
  12276. HTML chapter-15/clear.html
  12277. body {
  12278. width: 750px;
  12279. font-family: Arial, Verdana, sans-serif;
  12280. color: #665544;}
  12281. p {
  12282. width: 230px;
  12283. float: left;
  12284. margin: 5px;
  12285. padding: 5px;
  12286. background-color: #efefef;}
  12287. .clear {
  12288. clear: left;}
  12289. CSS
  12290. Result
  12291. 373 LAYOUT
  12292. Article
  12293. 373 LAYOUT
  12294. Result
  12295. div {
  12296. border: 1px solid #665544;}
  12297. CSS
  12298. <body>
  12299. <h1>The Evolution of the Bicycle</h1>
  12300. <div>
  12301. <p>In 1817 Baron von Drais invented a walking
  12302. machine that would help him get around the
  12303. royal gardens faster...</p>
  12304. </div>
  12305. </body>
  12306. chapter-15/float-problem.html HTML If a containing element only
  12307. contains floated elements, some
  12308. browsers will treat it as if it is
  12309. zero pixels tall.
  12310. As you can see in this example,
  12311. the one pixel border assigned
  12312. to the containing element has
  12313. collapsed, so the box looks like a
  12314. two pixel line.
  12315. Parents of Floated
  12316. Elements: Problem
  12317. Article
  12318. LAYOUT 374
  12319. div {
  12320. border: 1px solid #665544;
  12321. overflow: auto;
  12322. width: 100%;}
  12323. CSS
  12324. Result
  12325. <body>
  12326. <h1>The Evolution of the Bicycle</h1>
  12327. <div>
  12328. <p>In 1817 Baron von Drais invented a walking
  12329. machine that would help him get around the
  12330. royal gardens faster...</p>
  12331. </div>
  12332. </body>
  12333. HTML chapter-15/float-solution.html Traditionally, developers got
  12334. around this problem by adding
  12335. an extra element after the
  12336. last floated box (inside the
  12337. containing element). A CSS
  12338. rule would be applied to this
  12339. additional element setting the
  12340. clear property to have a value
  12341. of both. But this meant that an
  12342. extra element was added to the
  12343. HTML just to fix the height of the
  12344. containing element.
  12345. More recently, developers have
  12346. opted for a purely CSS-based
  12347. solution because it means that
  12348. there is no need to add an extra
  12349. element to the HTML page after
  12350. the floated elements. The pure
  12351. CSS solution adds two CSS rules
  12352. to the containing element (in this
  12353. example the <div> element):
  12354. ● The overflow property is
  12355. given a value auto.
  12356. ● The width property is set to
  12357. 100%.
  12358. Parents of Floated
  12359. Elements: Solution
  12360. 375 LAYOUT
  12361. Article
  12362. 375 LAYOUT
  12363. Result
  12364. .column1of2 {
  12365. float: left;
  12366. width: 620px;
  12367. margin: 10px;}
  12368. .column2of2 {
  12369. float: left;
  12370. width: 300px;
  12371. margin: 10px;}
  12372. CSS
  12373. <h1>The Evolution of the Bicycle</h1>
  12374. <div class="column1of2">
  12375. <h3>The First Bicycle</h3>
  12376. <p>In 1817 Baron von Drais invented a walking
  12377. machine that would help him get around the
  12378. royal gardens faster: two same-size ...</p>
  12379. </div>
  12380. <div class="column2of2">
  12381. <h3>Bicycle Timeline</h3> ...
  12382. </div>
  12383. chapter-15/columns-two.html HTML Many web pages use multiple
  12384. columns in their design. This
  12385. is achieved by using a <div>
  12386. element to represent each
  12387. column. The following three CSS
  12388. properties are used to position
  12389. the columns next to each other:
  12390. width
  12391. This sets the width of the
  12392. columns.
  12393. float
  12394. This positions the columns next
  12395. to each other.
  12396. margin
  12397. This creates a gap between the
  12398. columns.
  12399. A two-column layout like the one
  12400. shown on this page would need
  12401. two <div> elements, one for the
  12402. main content of the page and
  12403. one for the sidebar.
  12404. Inside each of the <div>
  12405. elements there can be headings,
  12406. paragraphs, images, and even
  12407. other <div> elements.
  12408. Creating Multi-Column
  12409. Layouts with Floats
  12410. Article
  12411. LAYOUT 376
  12412. Result
  12413. .column1of3, .column2of3, .column3of3 {
  12414. width: 300px;
  12415. float: left;
  12416. margin: 10px;}
  12417. CSS
  12418. <h1>The Evolution of the Bicycle</h1>
  12419. <div class="column1of3">
  12420. <h3>The First Bicycle</h3> ...
  12421. </div>
  12422. <div class="column2of3">
  12423. <h3>Further Innovations</h3> ...
  12424. </div>
  12425. <div class="column3of3">
  12426. <h3>Bicycle Timeline</h3> ...
  12427. </div>
  12428. HTML chapter-15/columns-three.html Similarly, a three column layout
  12429. could be created by floating
  12430. three <div> elements next to
  12431. each other, as shown on this
  12432. page.
  12433. 377 LAYOUT
  12434. Different visitors to your site will have different sized screens that show
  12435. different amounts of information, so your design needs to be able to
  12436. work on a range of different sized screens.
  12437. Screen Sizes
  12438. When designing for print, you
  12439. always know the size of the
  12440. piece of paper that your design
  12441. will be printed on. However,
  12442. when it comes to designing for
  12443. the web, you are faced with the
  12444. unique challenge that different
  12445. users will have different sized
  12446. screens.
  12447. Since computers have been sold
  12448. to the public, the size of screens
  12449. has been steadily increasing.
  12450. This means that some people
  12451. viewing your site might have 13
  12452. inch monitors while others may
  12453. have 27+ inch monitors.
  12454. The size of a user's screen
  12455. affects how big they can open
  12456. their windows and how much
  12457. of the page they will see. There
  12458. are also an increasing number
  12459. of handheld devices (mobile
  12460. phones and tablets) that have
  12461. smaller screens.
  12462. iPhone 4
  12463. Size: 3.5 inches
  12464. Resolution: 960 x 640 pixels
  12465. iPad 2
  12466. Size: 9.7 inches
  12467. Resolution: 1024 x 768 pixels
  12468. LAYOUT 378
  12469. Resolution refers to the number of dots a screen shows per inch. Some
  12470. devices have a higher resolution than desktop computers and most
  12471. operating systems allow users to adjust the resolution of their screens.
  12472. Screen Resolution
  12473. Most computers will allow
  12474. owners to adjust the resolution
  12475. of the display or the number
  12476. of pixels that are shown on the
  12477. screen. For example, here you
  12478. can see the options to change
  12479. the screen size from 720 x 480
  12480. pixels up to 1280 x 800 pixels.
  12481. It is interesting to note that
  12482. the higher the resolution, the
  12483. smaller the text appears. Many
  12484. mobile devices have screens
  12485. that are higher resolution than
  12486. their desktop counterparts.
  12487. 13" MacBook
  12488. Size: 13.3 inches
  12489. Resolution: 1280 x 800 pixels
  12490. 27" iMac
  12491. Size: 27 inches
  12492. Resolution: 2560 x 1440 pixels
  12493. 379 LAYOUT
  12494. Judging the height that people
  12495. are likely to see on the screen
  12496. without scrolling down the page
  12497. is much harder. For several
  12498. years, designers assumed that
  12499. users would see the top 570-
  12500. 600 pixels of a page without
  12501. having to scroll and some tried
  12502. to fit all of the key messages in
  12503. this area (fearing that people
  12504. would not scroll down the page).
  12505. As screen sizes have increased
  12506. and handheld devices have
  12507. become more popular, the
  12508. area users will see is far more
  12509. variable.
  12510. The area of the page that users
  12511. would see without scrolling was
  12512. often referred as being “above
  12513. the fold” (a term newspapers
  12514. had originally coined to describe
  12515. the area of the front page you
  12516. would see if the paper were
  12517. folded in half).
  12518. It is now recognized that if
  12519. someone is interested in the
  12520. content of the page, they are
  12521. likely to scroll down to see more.
  12522. Having said which, usability
  12523. studies have shown that visitors
  12524. can judge a page in under a
  12525. second so it is still important to
  12526. let new visitors know that the
  12527. site is relevant to them and their
  12528. interests.
  12529. As a result, many designs still
  12530. try to let the user know what the
  12531. site is about within the top 570-
  12532. 600 pixels, as well as hint at
  12533. more content below this point.
  12534. But do not try to cram too much
  12535. into that top area.
  12536. Because screen sizes and display resolutions vary so much, web
  12537. designers often try to create pages of around 960-1000 pixels wide
  12538. (since most users will be able to see designs this wide on their screens).
  12539. Page Sizes
  12540. At the time of writing, there was a growing trend for people to create
  12541. adaptive or responsive designs that could change depending on the size
  12542. of the screen.
  12543. LAYOUT 380
  12544. The shaded area is hidden by
  12545. the constraints of the browser
  12546. window, so the user must scroll
  12547. in order to view the lower region.
  12548. However, the user gets a taste
  12549. for what is lower on the page
  12550. and can tell that there will be
  12551. more to see if they scroll down.
  12552. 570 px
  12553. 1000 px
  12554. 381 LAYOUT
  12555. Fixed width layout
  12556. designs do not
  12557. change size as the
  12558. user increases
  12559. or decreases
  12560. the size of their
  12561. browser window.
  12562. Measurements tend
  12563. to be given in pixels.
  12564. Fixed Width Layouts
  12565. Lorem • Ipsum • Dolor • Consectetur Lorem Ipsum
  12566. Lorem ipsum dolor sit amet, consectetur
  12567. adipisicing elit, sed do eiusmod tempor
  12568. incididunt ut labore et dolore magna aliqua.
  12569. Ut enim ad minim veniam, quis nostrud
  12570. exercitation ullamco laboris nisi ut aliquip ex
  12571. ea commodo consequat. Duis aute irure dolor
  12572. in reprehenderit in voluptate velit esse cillum
  12573. dolore eu fugiat nulla pariatur. Excepteur sint
  12574. occaecat.
  12575. Lorem ipsum dolor
  12576. sit amet, consectetur
  12577. adipisicing elit, sed
  12578. do eiusmod tempor
  12579. incididunt ut labore et
  12580. Advantages
  12581. ● Pixel values are accurate
  12582. at controlling size and
  12583. positioning of elements.
  12584. ● The designer has far greater
  12585. control over the appearance
  12586. and position of items on the
  12587. page than with liquid layouts.
  12588. ● You can control the lengths
  12589. of lines of text regardless of
  12590. the size of the user's window.
  12591. ● The size of an image will
  12592. always remain the same
  12593. relative to the rest of the
  12594. page.
  12595. Disadvantages
  12596. ● You can end up with big gaps
  12597. around the edge of a page.
  12598. ● If the user's screen is a much
  12599. higher resolution than the
  12600. designer's screen, the page
  12601. can look smaller and text can
  12602. be harder to read.
  12603. ● If a user increases font sizes,
  12604. text might not fit into the
  12605. allotted spaces.
  12606. ● The design works best on
  12607. devices that have a site or
  12608. resolution similar to that of
  12609. desktop or laptop computers.
  12610. ● The page will often take up
  12611. more vertical space than a
  12612. liquid layout with the same
  12613. content.
  12614. LAYOUT 382
  12615. Liquid layout designs
  12616. stretch and contract
  12617. as the user increases
  12618. or decreases the
  12619. size of their browser
  12620. window. They tend to
  12621. use percentages.
  12622. Liquid Layouts
  12623. Lorem • Ipsum • Dolor • Consectetur Lorem Ipsum
  12624. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
  12625. tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
  12626. veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
  12627. commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit
  12628. esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat.
  12629. Lorem ipsum dolor sit amet, consectetur adipisicing
  12630. elit, sed do eiusmod tempor incididunt ut labore et
  12631. dolore magna aliqua. Ut enim ad minim veniam, quis
  12632. nostrud exercitation ullamco laboris nisi ut aliquip ex
  12633. ea commodo consequat. Duis aute.
  12634. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
  12635. Advantages
  12636. ● Pages expand to fill the entire
  12637. browser window so there are
  12638. no spaces around the page
  12639. on a large screen.
  12640. ● If the user has a small
  12641. window, the page can
  12642. contract to fit it without the
  12643. user having to scroll to the
  12644. side.
  12645. ● The design is tolerant of
  12646. users setting font sizes larger
  12647. than the designer intended
  12648. (because the page can
  12649. stretch).
  12650. Disadvantages
  12651. ● If you do not control the
  12652. width of sections of the page
  12653. then the design can look very
  12654. different than you intended,
  12655. with unexpected gaps around
  12656. certain elements or items
  12657. squashed together.
  12658. ● If the user has a wide
  12659. window, lines of text can
  12660. become very long, which
  12661. makes them harder to read.
  12662. ● If the user has a very narrow
  12663. window, words may be
  12664. squashed and you can end up
  12665. with few words on each line.
  12666. ● If a fixed width item (such as
  12667. an image) is in a box that is
  12668. too small to hold it (because
  12669. the user has made the
  12670. window smaller) the image
  12671. can overflow over the text.
  12672. Because liquid layouts can
  12673. stretch the entire width of the
  12674. browser, resulting in long lines
  12675. of text that are hard to read,
  12676. some liquid layouts only let part
  12677. of the page expand and contract.
  12678. Other parts of the page have
  12679. minimum and maximum widths.
  12680. 383 LAYOUT
  12681. Article
  12682. 383 LAYOUT
  12683. To create a fixed width layout,
  12684. the width of the main boxes on
  12685. a page will usually be specified
  12686. in pixels (and sometimes their
  12687. height, too).
  12688. Here you can see several <div>
  12689. elements, each of which uses an
  12690. id or class attribute to indicate
  12691. its purpose on the page.
  12692. In a book like this, the result of
  12693. both the fixed and liquid layouts
  12694. look similar. To get a real feel for
  12695. them, you need to view them in
  12696. your browser and see how they
  12697. react when you adjust the size of
  12698. the browser window.
  12699. The fixed width layout will stay
  12700. the same width no matter what
  12701. size the browser window is,
  12702. whereas the liquid layout will
  12703. stretch (or shrink) to fill the
  12704. screen.
  12705. The HTML is the same for both
  12706. the fixed width layout example
  12707. on this page and the liquid layout
  12708. example you see next.
  12709. A Fixed Width Layout
  12710. <body>
  12711. <div id="header">
  12712. <h1>Logo</h1>
  12713. <div id="nav">
  12714. <ul>
  12715. <li><a href="">Home</a></li>
  12716. <li><a href="">Products</a></li>
  12717. <li><a href="">Services</a></li>
  12718. <li><a href="">About</a></li>
  12719. <li><a href="">Contact</a></li>
  12720. </ul>
  12721. </div>
  12722. </div>
  12723. <div id="content">
  12724. <div id="feature">
  12725. <p>Feature</p>
  12726. </div>
  12727. <div class="article column1">
  12728. <p>Column One</p>
  12729. </div>
  12730. <div class="article column2">
  12731. <p>Column Two</p>
  12732. </div>
  12733. <div class="article column3">
  12734. <p>Column Three</p>
  12735. </div>
  12736. </div>
  12737. <div id="footer">
  12738. <p>&copy; Copyright 2011</p>
  12739. </div>
  12740. </body>
  12741. chapter-15/fixed-width-layout.html HTML
  12742. Article
  12743. LAYOUT 384
  12744. The rule for the <body> element
  12745. is used to fix the width of the
  12746. page at 960 pixels, and it is
  12747. centered by setting the left and
  12748. right margins to auto.
  12749. The main boxes on the page
  12750. have a margin of 10 pixels to
  12751. create a gap between them.
  12752. The navigation, feature, and
  12753. footer panels stretch to the
  12754. width of the containing element
  12755. (which in this instance is the
  12756. <body> element), so we do not
  12757. need to specify a width for them.
  12758. The three columns are each 300
  12759. pixels wide and use the float
  12760. property, which allows them to
  12761. sit next to each other.
  12762. Sometimes an extra HTML
  12763. element is used to contain the
  12764. page, rather than fixing the
  12765. width of the <body>. This allows
  12766. the background of the browser
  12767. window to have a different color
  12768. than the background of the
  12769. content.
  12770. Result
  12771. body {
  12772. width: 960px;
  12773. margin: 0 auto;}
  12774. #content {
  12775. overflow: auto;
  12776. height: 100%;}
  12777. #nav, #feature, #footer {
  12778. background-color: #efefef;
  12779. padding: 10px;
  12780. margin: 10px;}
  12781. .column1, .column2, .column3 {
  12782. background-color: #efefef;
  12783. width: 300px;
  12784. float: left;
  12785. margin: 10px;}
  12786. li {
  12787. display: inline;
  12788. padding: 5px;}
  12789. CSS
  12790. 385 LAYOUT
  12791. Article
  12792. 385 LAYOUT
  12793. The liquid layout uses
  12794. percentages to specify the width
  12795. of each box so that the design
  12796. will stretch to fit the size of the
  12797. screen.
  12798. When trying this in your
  12799. browser, remember to make the
  12800. window smaller and larger.
  12801. A Liquid Layout
  12802. <body>
  12803. <div id="header">
  12804. <h1>Logo</h1>
  12805. <div id="nav">
  12806. <ul>
  12807. <li><a href="">Home</a></li>
  12808. <li><a href="">Products</a></li>
  12809. <li><a href="">Services</a></li>
  12810. <li><a href="">About</a></li>
  12811. <li><a href="">Contact</a></li>
  12812. </ul>
  12813. </div>
  12814. </div>
  12815. <div id="content">
  12816. <div id="feature">
  12817. <p>Feature</p>
  12818. </div>
  12819. <div class="article column1">
  12820. <p>Column One</p>
  12821. </div>
  12822. <div class="article column2">
  12823. <p>Column Two</p>
  12824. </div>
  12825. <div class="article column3">
  12826. <p>Column Three</p>
  12827. </div>
  12828. </div>
  12829. <div id="footer">
  12830. <p>&copy; Copyright 2011</p>
  12831. </div>
  12832. </body>
  12833. chapter-15/liquid-layout.html HTML
  12834. Article
  12835. LAYOUT 386
  12836. There is a rule on the <body>
  12837. element to set the width of the
  12838. page to 90% so that there is a
  12839. small gap between the left and
  12840. right-hand sides of the browser
  12841. window and the main content.
  12842. The three columns are all given
  12843. a margin of 1% and a width of
  12844. 31.3%. This adds up to 99.9%
  12845. of the width of the <body>
  12846. element, so some browsers
  12847. might not perfectly align the
  12848. right-hand side of the third
  12849. column with other elements on
  12850. the page.
  12851. The <div> elements that hold
  12852. the navigation, feature, and
  12853. footer will stretch to fill the
  12854. width of the containing <body>
  12855. element. They are given a 1%
  12856. margin to help them align with
  12857. the columns.
  12858. If you imagine the browser
  12859. window to be very wide or very
  12860. narrow, you can see how lines of
  12861. text could become very long or
  12862. very short.
  12863. This is where the min-width
  12864. and max-width properties help
  12865. create boundaries within which
  12866. the layout can stretch (although
  12867. Internet Explorer 7 was the first
  12868. version of IE to support these
  12869. properties).
  12870. Result
  12871. body {
  12872. width: 90%;
  12873. margin: 0 auto;}
  12874. #content {overflow: auto;}
  12875. #nav, #feature, #footer {
  12876. margin: 1%;}
  12877. .column1, .column2, .column3 {
  12878. width: 31.3%;
  12879. float: left;
  12880. margin: 1%;}
  12881. .column3 {margin-right: 0%;}
  12882. li {
  12883. display: inline;
  12884. padding: 0.5em;}
  12885. #nav, #footer {
  12886. background-color: #efefef;
  12887. padding: 0.5em 0;}
  12888. #feature, .article {
  12889. height: 10em;
  12890. margin-bottom: 1em;
  12891. background-color: #efefef;}
  12892. CSS
  12893. 387 LAYOUT
  12894. On the right, you can see a set of
  12895. thick vertical lines superimposed
  12896. over the top of a newspaper
  12897. website to show you how the
  12898. page was designed according to
  12899. a grid. This grid is called the 960
  12900. pixel grid and is widely used by
  12901. web designers.
  12902. Grids set consistent proportions
  12903. and spaces between items which
  12904. helps to create a professional
  12905. looking design.
  12906. If you flick back through the
  12907. pages of this book you will see
  12908. that it, too, has been constructed
  12909. according to a grid (comprising
  12910. three columns).
  12911. As you will see on pages 389-
  12912. 390, it is possible to create many
  12913. different layouts using this one
  12914. versatile grid.
  12915. While a grid might seem like a
  12916. restriction, in actual fact it:
  12917. ● Creates a continuity between
  12918. different pages which may
  12919. use different designs
  12920. ● Helps users predict where to
  12921. find information on various
  12922. pages
  12923. ● Makes it easier to add new
  12924. content to the site in a
  12925. consistent way
  12926. ● Helps people collaborate
  12927. on the design of a site in a
  12928. consistent way
  12929. Composition in any visual art (such as design, painting, or photography)
  12930. is the placement or arrangement of visual elements — how they are
  12931. organized on a page. Many designers use a grid structure to help them
  12932. position items on a page, and the same is true for web designers.
  12933. Layout Grids
  12934. LAYOUT 388
  12935. Example Grid
  12936. 389 LAYOUT
  12937. Possible Layouts:
  12938. 960 Pixel wide
  12939. 12 Column Grid
  12940. 940 px
  12941. 460 px
  12942. 300 px
  12943. 220 px
  12944. 140 px
  12945. 460 px
  12946. 300 px 300 px
  12947. 220 px 220 px 220 px
  12948. 140 px 140 px 140 px 140 px 140 px
  12949. LAYOUT 390
  12950. These two pages illustrate a 960
  12951. pixel wide, 12 column grid. They
  12952. demonstrate how it is possible
  12953. to create a wide range of column
  12954. layouts using this one grid.
  12955. The page is 960 pixels wide and
  12956. there are 12 equal sized columns
  12957. (shown in gray), each of which is
  12958. is 60 pixels wide.
  12959. Each column has a margin set
  12960. to 10 pixels, which creates a a
  12961. gap of 20 pixels between each
  12962. column and 10 pixels to the left
  12963. and right-hand sides of the page.
  12964. 620 px
  12965. 220 px
  12966. 460 px
  12967. 300 px
  12968. 220 px
  12969. 700 px
  12970. 220 px 220 px
  12971. 300 px 140 px 140 px
  12972. 220 px 140 px 140 px 140 px
  12973. 300 px
  12974. 391 LAYOUT
  12975. CSS frameworks aim to make your life easier by providing the code for
  12976. common tasks, such as creating layout grids, styling forms, creating
  12977. printer-friendly versions of pages and so on. You can include the CSS
  12978. framework code in your projects rather than writing the CSS from scratch.
  12979. CSS Frameworks
  12980. ADVANTAGES
  12981. ● They save you from
  12982. repeatedly writing code for
  12983. the same tasks.
  12984. ● They will have been tested
  12985. across different browser
  12986. versions (which helps avoid
  12987. browser bugs).
  12988. DISADVANTAGES
  12989. ● They often require that you
  12990. use class names in your
  12991. HTML code that only control
  12992. the presentation of the page
  12993. (rather than describe its
  12994. content).
  12995. ● In order to satisfy a wide
  12996. variety of needs, they often
  12997. contain more code than you
  12998. need for your particular web
  12999. page (commonly referred to
  13000. as code “bloat”).
  13001. One of the most popular uses of
  13002. CSS frameworks is in creating
  13003. grids to layout pages. There
  13004. are several grid frameworks
  13005. out there, but the one we will
  13006. be looking at over the next few
  13007. pages is the 960 Grid System
  13008. (available at www.960.gs).
  13009. 960.gs provides a style sheet
  13010. that you can include in your
  13011. HTML pages. Once our page
  13012. links to this style sheet, you can
  13013. provide the appropriate classes
  13014. to your HTML code and it will
  13015. create multiple column layouts
  13016. for you. The 960.gs website
  13017. also provides templates you can
  13018. download to help design your
  13019. pages using a 12 column grid. (In
  13020. addition, there is a variation on
  13021. the grid that uses 16 columns.)
  13022. To create a 12 column grid, an
  13023. element that contains the entire
  13024. page is given a class attibute
  13025. whose value is container_12.
  13026. This sets the content of the
  13027. page to be 960 pixels wide and
  13028. indicates that we are using a 12
  13029. column grid.
  13030. There are different classes for
  13031. blocks that take up 1, 2, 3, 4,
  13032. and up to 12 columns of the grid.
  13033. Each block uses class names
  13034. such as grid_3 (for a block that
  13035. stretches over three columns),
  13036. grid_4 (for a block that
  13037. stretches over 4 columns) and
  13038. and so on through to grid_12
  13039. (for a box that is the full width
  13040. of the page). These columns all
  13041. float to the left, and there is a 10
  13042. pixel margin to the left and the
  13043. right of each one.
  13044. There are several other gridbased
  13045. CSS frameworks available
  13046. online, such as those at:
  13047. blueprintcss.org
  13048. lessframework.com
  13049. developer.yahoo.com/yui/
  13050. grids/
  13051. Introducing the 960.GS CSS Framework
  13052. LAYOUT 392
  13053. Below you can see a sample layout of a page just like the fixed width
  13054. page example. On the next page, we will recreate this using the 960.gs
  13055. stylesheet. Instead of writing our own CSS to control layout, we will need
  13056. to add classes to the HTML indicating how wide each section should be.
  13057. Using the 960.GS Grid
  13058. 940 px
  13059. 300 px
  13060. 940 px
  13061. 940 px
  13062. 300 px 300 px
  13063. 940 px
  13064. 393 LAYOUT
  13065. Article
  13066. 393 LAYOUT
  13067. <head>
  13068. <title>Grid Layout</title>
  13069. <link rel="stylesheet" type="text/css"
  13070. href="css/960_12_col.css" />
  13071. <style>See the right hand page</style>
  13072. </head>
  13073. <body>
  13074. <div class="container_12 clearfix">
  13075. <div id="header" class="grid_12">
  13076. <h1>Logo</h1>
  13077. <div id="nav">
  13078. <ul>
  13079. <li><a href="">Home</a></li>
  13080. <li><a href="">Products</a></li>
  13081. <li><a href="">Services</a></li>
  13082. <li><a href="">About</a></li>
  13083. <li><a href="">Contact</a></li>
  13084. </ul>
  13085. </div>
  13086. </div>
  13087. <div id="feature" class="grid_12">
  13088. <p>Feature</p>
  13089. </div>
  13090. <div class="article grid_4">
  13091. <p>Column One</p>
  13092. </div>
  13093. <div class="article grid_4">
  13094. <p>Column Two</p>
  13095. </div>
  13096. <div class="article grid_4">
  13097. <p>Column Three</p>
  13098. </div>
  13099. <div id="footer" class="grid_12">
  13100. <p>&copy; Copyright 2011</p>
  13101. </div>
  13102. </div><!-- .container_12 -->
  13103. </body>
  13104. chapter-15/grid-layout.html HTML
  13105. Let's take a look at an HTML
  13106. page and how it has been
  13107. marked up to use the 960.gs grid
  13108. system.
  13109. You can see that we include
  13110. the CSS for the grid using the
  13111. <link> element inside the
  13112. <head> of the page.
  13113. The styles we are writing
  13114. ourselves are shown on the right
  13115. hand page.
  13116. The 960_12_col.css stylesheet
  13117. contains all of the rules we need
  13118. to control the grid layout. The
  13119. HTML uses the class names:
  13120. container_12 to act as a
  13121. container for the whole page and
  13122. indicate that we are using a 12
  13123. column grid
  13124. clearfix to ensure that
  13125. browsers know the height of the
  13126. containing box, because it only
  13127. contains floated elements (this
  13128. addresses the issue you met on
  13129. pages 371-372)
  13130. grid_12 to create a block that is
  13131. twelve columns wide
  13132. grid_4 to create a block that is
  13133. four columns wide
  13134. A Grid-Based Layout
  13135. Using 960.GS
  13136. Article
  13137. LAYOUT 394
  13138. Result
  13139. * {
  13140. font-family: Arial, Verdana, sans-serif;
  13141. color: #665544;
  13142. text-align: center;}
  13143. #nav, #feature, .article, #footer {
  13144. background-color: #efefef;
  13145. margin-top: 20px;
  13146. padding: 10px 0px 5px 0px;}
  13147. #feature, .article {
  13148. height: 100px;}
  13149. li {
  13150. display: inline;
  13151. padding: 5px;}
  13152. CSS The 960.gs style sheet has taken
  13153. care of the layout, creating the
  13154. correct width for the columns
  13155. and setting the spaces between
  13156. them. Therefore, the only rules
  13157. we needed to add are shown on
  13158. this page. These rules:
  13159. ● Control the font and the
  13160. position of the text in the
  13161. boxes
  13162. ● Set the background colors for
  13163. the boxes
  13164. ● Set the height of the feature
  13165. and article boxes
  13166. ● Add a margin to the top and
  13167. bottom of each box
  13168. 395 LAYOUT
  13169. Article
  13170. 395 LAYOUT
  13171. <!DOCTYPE html>
  13172. <html>
  13173. <head>
  13174. <title>Multiple Style Sheets - Import</title>
  13175. <link rel="stylesheet" type="text/css"
  13176. href="css/styles.css" />
  13177. </head>
  13178. <body>
  13179. <!-- HTML page content here -->
  13180. </body>
  13181. </html>
  13182. chapter-15/multiple-style-sheets-import.html HTML Some web page authors split
  13183. up their CSS style rules into
  13184. separate style sheets. For
  13185. example, they might use one
  13186. style sheet to control the layout
  13187. and another to control fonts,
  13188. colors and so on.
  13189. Some authors take an even
  13190. more modular approach
  13191. to stylesheets, creating
  13192. separate stylesheets to control
  13193. typography, layout, forms,
  13194. tables, even different styles for
  13195. each sub-section of a site.
  13196. There are two ways to add
  13197. multiple style sheets to a page:
  13198. 1: Your HTML page can link
  13199. to one style sheet and that
  13200. stylesheet can use the @import
  13201. rule to import other style sheets.
  13202. 2: In the HTML you can use a
  13203. separate <link> element for
  13204. each style sheet.
  13205. The example on this page
  13206. uses one <link> element in
  13207. the HTML to link to a style
  13208. sheet called styles.css. This
  13209. stylesheet then uses the
  13210. @import rule to import the
  13211. typography.css and
  13212. tables.css files.
  13213. If a styesheet uses the @import
  13214. rule, it should appear before the
  13215. other rules.
  13216. Multiple Style Sheets
  13217. @import
  13218. @import url("tables.css");
  13219. @import url("typography.css");
  13220. body {
  13221. color: #666666;
  13222. background-color: #f8f8f8;
  13223. text-align: center;}
  13224. #page {
  13225. width: 600px;
  13226. text-align: left;
  13227. margin-left: auto;
  13228. margin-right: auto;
  13229. border: 1px solid #d6d6d6;
  13230. padding: 20px;}
  13231. h3 {
  13232. color: #547ca0;}
  13233. chapter-15/styles.css CSS
  13234. Article
  13235. LAYOUT 396
  13236. On this page you can see the
  13237. other technique for including
  13238. multiple style sheets. Inside the
  13239. <head> element is a separate
  13240. <link> element for each style
  13241. sheet.
  13242. The contents of site.css are
  13243. identical to styles.css on the
  13244. left hand page, except the code
  13245. does not contain @import rules.
  13246. As with all style sheets, if two
  13247. rules apply to the same element
  13248. then rules that appear later in a
  13249. document will take precedence
  13250. over previous rules.
  13251. In the example on this page,
  13252. any rules in typography.css
  13253. would take precedence over
  13254. rules in site.css (because the
  13255. typography rules are included
  13256. after the other rules).
  13257. In the example on the previous
  13258. page, the rules in styles.css
  13259. would take precedence over the
  13260. rules in typography.css. This
  13261. is because when the @import
  13262. rule is used, that is the point at
  13263. which the browser considers the
  13264. rules live.
  13265. Result
  13266. Multiple Style Sheets
  13267. link
  13268. <!DOCTYPE html>
  13269. <html>
  13270. <head>
  13271. <title>Multiple Style Sheets - Link</title>
  13272. <link rel="stylesheet" type="text/css"
  13273. href="css/site.css" />
  13274. <link rel="stylesheet" type="text/css"
  13275. href="css/tables.css" />
  13276. <link rel="stylesheet" type="text/css"
  13277. href="css/typography.css" />
  13278. </head>
  13279. <body>
  13280. <!-- HTML page content here -->
  13281. </body>
  13282. </html>
  13283. HTML chapter-15/multiple-style-sheets-link.html
  13284. 397 LAYOUT
  13285. Example
  13286. LAYOUT
  13287. LAYOUT 398
  13288. Several classes from the 960.gs style sheet have been added to the code
  13289. to indicate how many columns of the grid each element should stretch
  13290. across. As you saw in this chapter, the 960.gs stylesheet uses the float
  13291. property to position the blocks next to each other.
  13292. At the start of the page, the header uses fixed positioning (meaning that
  13293. it does not move when the user scrolls down the page). The z-index
  13294. property is added to the header to keep it on top of the remaining
  13295. content as the user scrolls down the page.
  13296. Both the header and footer are contained within <div> elements which
  13297. stretch the entire width of the page. Inside those container elements sit
  13298. other elements that use classes from the 960.gs style sheet to ensure
  13299. that the items in the header and footer align with the rest of the content.
  13300. The feature article takes up the entire width of the page. The push_7
  13301. and push_9 classes are part of the 960.gs style sheet and are used in
  13302. the feature article to move the header and the content for this article
  13303. over to the right.
  13304. Under the main article you can see four blocks, each of which is 3
  13305. columns wide. These contain images followed by links to more articles.
  13306. This example also uses background images to create a textured
  13307. background for the page and header, and also to contain the images for
  13308. the feature article. You will learn more about these in the next chapter.
  13309. Please note: If you view this example in Internet Explorer 6, the
  13310. transparent PNGs used in this design may have a gray background. To
  13311. learn more about this issue, visit the website accompanying this book
  13312. where you can find a simple JavaScript that fixes this problem.
  13313. This example demonstrates a modern
  13314. magazine-style layout using the 960.gs grid.
  13315. Using this style sheet saves us from having to
  13316. create all of the CSS code ourselves.
  13317. 399 LAYOUT
  13318. Example
  13319. LAYOUT
  13320. <!DOCTYPE html
  13321. <html>
  13322. <head>
  13323. <title>Layout</title>
  13324. <link rel="stylesheet" type="text/css" href="css/960_12_col.css" />
  13325. <style type="text/css">
  13326. @font-face {
  13327. font-family: 'QuicksandBook';
  13328. src: url('fonts/Quicksand_Book-webfont.eot');
  13329. src: url('fonts/Quicksand_Book-webfont.eot?#iefix') format('embedded-opentype'),
  13330. url('fonts/Quicksand_Book-webfont.woff') format('woff'),
  13331. url('fonts/Quicksand_Book-webfont.ttf') format('truetype'),
  13332. url('fonts/Quicksand_Book-webfont.svg#QuicksandBook') format('svg');
  13333. font-weight: normal;
  13334. font-style: normal;}
  13335. body {
  13336. color: #ffffff;
  13337. background: #413f3b url("images/bg.jpg");
  13338. font-family: Georgia, "Times New Roman", Times, serif;
  13339. font-size: 90%;
  13340. margin: 0px;
  13341. text-align: center;}
  13342. a {
  13343. color: #b5c1ad;
  13344. text-decoration: none;}
  13345. a:hover {
  13346. color: #ffffff;}
  13347. .header {
  13348. background-image: url("images/bg-header.jpg");
  13349. padding: 0px 0px 0px 0px;
  13350. height: 100px;
  13351. position: fixed;
  13352. top: 0px;
  13353. width: 100%;
  13354. z-index: 50;}
  13355. .nav {
  13356. float: right;
  13357. font-family: QuicksandBook, Helvetica, Arial, sans-serif;
  13358. LAYOUT 400
  13359. Example
  13360. LAYOUT
  13361. padding: 45px 0px 0px 0px;
  13362. text-align: right;}
  13363. .wrapper {
  13364. width: 960px;
  13365. margin: 0px auto;
  13366. background-image: url("images/bg-triangle.png");
  13367. background-repeat: no-repeat;
  13368. background-position: 0px 0px;
  13369. text-align: left;}
  13370. .logo {
  13371. margin-bottom: 20px;}
  13372. h1, h2 {
  13373. font-family: QuicksandBook, Helvetica, Arial, sans-serif;
  13374. font-weight: normal;
  13375. text-transform: uppercase;}
  13376. h1 {
  13377. font-size: 240%;
  13378. margin-top: 140px;}
  13379. .date {
  13380. font-family: Arial, Helvetica, sans-serif;
  13381. font-size: 75%;
  13382. color: #b5c1ad;}
  13383. .intro {
  13384. clear: left;
  13385. font-size: 90%;
  13386. line-height: 1.4em;}
  13387. .main-story {
  13388. background-image: url("images/triangles.png");
  13389. background-repeat: no-repeat;
  13390. background-position: 122px 142px;
  13391. height: 570px;}
  13392. .more-articles {
  13393. border-top: 1px solid #ffffff;
  13394. padding: 10px;}
  13395. .more-articles p {
  13396. border-bottom: 1px solid #807c72;
  13397. padding: 5px 0px 15px 0px;
  13398. font-size: 80%;}
  13399. 401 LAYOUT
  13400. Example
  13401. LAYOUT
  13402. .more-articles p:last-child {
  13403. border-bottom: none;}
  13404. .footer {
  13405. clear: both;
  13406. background: rgba(0, 0, 0, 0.2);
  13407. padding: 5px 10px;}
  13408. .footer p {
  13409. font-family: Helvetica, Arial, sans-serif;
  13410. font-size: 75%;
  13411. text-align: right;}
  13412. .footer a {
  13413. color: #807c72;}
  13414. </style>
  13415. </head>
  13416. <body>
  13417. <div class="header">
  13418. <div class="container_12">
  13419. <div class="grid_5">
  13420. <img src="images/logo.png" alt="Pedal Faster - The modern bicycle magazine"
  13421. width="216" height="37" class="logo" />
  13422. <img src="images/header-triangle.png" alt="" width="116" height="100" />
  13423. </div>
  13424. <div class="nav grid_7">
  13425. <a href="">home</a> / <a href="">news</a> / <a href="">archives</a> /
  13426. <a href="">about</a> / <a href="">contact</a>
  13427. </div>
  13428. </div>
  13429. </div>
  13430. <div class="wrapper">
  13431. <div class="main-story container_12">
  13432. <div class="grid_6 push_6">
  13433. <h1><a href="">Fixed Gear Forever</a></h1>
  13434. </div>
  13435. <div class="intro grid_3 push_9">
  13436. <p class="date">16 APRIL 2011</p>
  13437. <p>The veloheld combines minimalist design with superb quality. Devoid of
  13438. excessive graphics and gear shift components, the veloheld product range
  13439. delights us with its beauty and simplicity ... </p>
  13440. LAYOUT 402
  13441. Example
  13442. LAYOUT
  13443. </div>
  13444. </div><!-- .main-story -->
  13445. <div class="more-articles container_12">
  13446. <h2 class="grid_12"><a href="">More Articles</a></h2>
  13447. <div class="grid_3">
  13448. <img src="images/more1.jpg" alt="The road ahead" width="220" height="125" />
  13449. <p><a href="">On the Road: from the fixed gear fanatic's point of view</a></p>
  13450. <p><a href="">Brand History: Pashley Cycles - hand-built in England</a></p>
  13451. <p><a href="">Frame Wars: Innovations in cycle manufacture and repair</a></p>
  13452. </div>
  13453. <div class="grid_3">
  13454. <img src="images/more2.jpg" alt="Sketchbook" width="220" height="125" />
  13455. <p><a href="">Touring Diary: A sketchbook in your basket</a></p>
  13456. <p><a href="">Top Ten Newcomers for 2012: A peek at what's to come</a></p>
  13457. <p><a href="">InnerTube: The best cycling videos on the web</a></p>
  13458. </div>
  13459. <div class="grid_3">
  13460. <img src="images/more3.jpg" alt="Repair shop sign" width="220" height="125" />
  13461. <p><a href="">Product Review: All baskets were not created equal</a></p>
  13462. <p><a href="">Going Public: Out &amp; About with the founder of Public</a></p>
  13463. <p><a href="">Cycle Lane Defence: Know your rights</a></p>
  13464. </div>
  13465. <div class="grid_3">
  13466. <img src="images/more4.jpg" alt="Schwinn Spitfire" width="220" height="125" />
  13467. <p><a href="">Bicyle Hall of Fame: The 1958 Schwinn Spitfire</a></p>
  13468. <p><a href="">Reader Survey: Share your thoughts with us!</a></p>
  13469. <p><a href="">Chain Gang: The evolution of the humble bike chain</a></p>
  13470. </div>
  13471. </div><!-- .more-articles -->
  13472. </div><!-- .wrapper -->
  13473. <div class="footer clearfix">
  13474. <div class="container_12">
  13475. <p class="grid_12"><a href="">Legal Information</a> | <a href="">Privacy
  13476. Policy</a> | <a href="">Copyright &copy; Pedal Faster 2011</a></p>
  13477. </div>
  13478. </div>
  13479. </body>
  13480. </html>
  13481.  
  13482. Summary
  13483. LAYOUT
  13484. X <div> elements are often used as containing elements
  13485. to group together sections of a page.
  13486. X Browsers display pages in normal flow unless you
  13487. specify relative, absolute, or fixed positioning.
  13488. X The float property moves content to the left or right
  13489. of the page and can be used to create multi-column
  13490. layouts. (Floated items require a defined width.)
  13491. X Pages can be fixed width or liquid (stretchy) layouts.
  13492. X Designers keep pages within 960-1000 pixels wide,
  13493. and indicate what the site is about within the top 600
  13494. pixels (to demonstrate its relevance without scrolling).
  13495. X Grids help create professional and flexible designs.
  13496. X CSS Frameworks provide rules for common tasks.
  13497. X You can include multiple CSS files in one page.
  13498.  
  13499. X Controlling size of images in CSS
  13500. X Aligning images in CSS
  13501. X Adding background images
  13502. Images
  13503. 16
  13504. 407 IMAGES
  13505. Controlling the size and alignment of
  13506. your images using CSS keeps rules that
  13507. affect the presentation of your page in
  13508. the CSS and out of the HTML markup.
  13509. You can also achieve several interesting effects using
  13510. background images. In this chapter you will learn how to:
  13511. ● Specify the size and alignment of an image using
  13512. ● Add background images to boxes
  13513. ● Create image rollovers in CSS
  13514. IMAGES 408
  13515. 409 IMAGES
  13516. Article
  13517. 409 IMAGES
  13518. img.large {
  13519. width: 500px;
  13520. height: 500px;}
  13521. img.medium {
  13522. width: 250px;
  13523. height: 250px;}
  13524. img.small {
  13525. width: 100px;
  13526. height: 100px;}
  13527. CSS
  13528. <img src="images/magnolia-large.jpg"
  13529. class="large" alt="Magnolia" />
  13530. <img src="images/magnolia-medium.jpg"
  13531. class="medium" alt="Magnolia" />
  13532. <img src="images/magnolia-small.jpg"
  13533. class="small" alt="Magnolia" />
  13534. chapter-16/image-sizes.html HTML
  13535. You can control the size of an
  13536. image using the width and
  13537. height properties in CSS, just
  13538. like you can for any other box.
  13539. Specifying image sizes helps
  13540. pages to load more smoothly
  13541. because the HTML and CSS
  13542. code will often load before the
  13543. images, and telling the browser
  13544. how much space to leave for an
  13545. image allows it to render the rest
  13546. of the page without waiting for
  13547. the image to download.
  13548. You might think that your site
  13549. is likely to have images of all
  13550. different sizes, but a lot of sites
  13551. use the same sized image across
  13552. many of their pages.
  13553. For example, an e-commerce site
  13554. tends to show product photos
  13555. at the same size. Or, if your site
  13556. is designed on a grid, then you
  13557. might have a selection of image
  13558. sizes that are commonly used on
  13559. all pages, such as:
  13560. Small portrait: 220 x 360
  13561. Small landscape: 330 x 210
  13562. Feature photo: 620 x 400
  13563. Whenever you use consistently
  13564. sized images across a site,
  13565. you can use CSS to control
  13566. the dimensions of the
  13567. images, instead of putting the
  13568. dimensions in the HTML.
  13569. Controlling sizes of
  13570. images in CSS
  13571. Article
  13572. IMAGES 410
  13573. R esult First you need to determine the
  13574. sizes of images that will be used
  13575. commonly throughout the site,
  13576. then give each size a name.
  13577. For example:
  13578. small
  13579. medium
  13580. large
  13581. Where the <img> elements
  13582. appear in the HTML, rather
  13583. than using width and height
  13584. attributes you can use these
  13585. names as values for the class
  13586. attribute.
  13587. In the CSS, you add selectors for
  13588. each of the class names, then
  13589. use the CSS width and height
  13590. properties to control the image
  13591. dimensions.
  13592. 411 IMAGES
  13593. Article
  13594. 411 IMAGES
  13595. img.align-left {
  13596. float: left;
  13597. margin-right: 10px;}
  13598. img.align-right {
  13599. float: right;
  13600. margin-left: 10px;}
  13601. img.medium {
  13602. width: 250px;
  13603. height: 250px;}
  13604. R esult
  13605. CSS
  13606. <p><img src="images/magnolia-medium.jpg"
  13607. alt="Magnolia" class="align-left medium" />
  13608. <b><i>Magnolia</i></b> is a large genus that
  13609. contains over 200 flowering plant species...</p>
  13610. <p><img src="images/magnolia-medium.jpg"
  13611. alt="Magnolia" class="align-right medium" />
  13612. Some magnolias, such as <i>Magnolia stellata</i>
  13613. and <i>Magnolia soulangeana</i>, flower quite
  13614. early in the spring before the leaves open...</p>
  13615. chapter-16/aligning-images.html HTML
  13616. AligNing images
  13617. Using CSS
  13618. In the last chapter, you saw how
  13619. the float property can be used
  13620. to move an element to the left or
  13621. the right of its containing block,
  13622. allowing text to flow around it.
  13623. Rather than using the <img>
  13624. element's align attribute, web
  13625. page authors are increasingly
  13626. using the float property to align
  13627. images. There are two ways that
  13628. this is commonly achieved:
  13629. 1: The float property is added
  13630. to the class that was created to
  13631. represent the size of the image
  13632. (such as the small class in our
  13633. example).
  13634. 2: New classes are created with
  13635. names such as align-left or
  13636. align-right to align the images
  13637. to the left or right of the page.
  13638. These class names are used in
  13639. addition to classes that indicate
  13640. the size of the image.
  13641. In this example you can see the
  13642. align-left and align-right
  13643. classes used to align the image.
  13644. It is also common to add a
  13645. margin to the image to ensure
  13646. that the text does not touch their
  13647. edges.
  13648. Article
  13649. IMAGES 412
  13650. R esult
  13651. img.align-center {
  13652. display: block;
  13653. margin: 0px auto;}
  13654. img.medium {
  13655. width: 250px;
  13656. height: 250px;}
  13657. CSS
  13658. <p><img src="images/magnolia-medium.jpg"
  13659. alt="Magnolia" class="align-center medium" />
  13660. <b><i>Magnolia</i></b> is a large genus that
  13661. contains over 200 flowering plant species. It
  13662. is named after French botanist Pierre Magnol and,
  13663. having evolved before bees appeared, the
  13664. flowers were developed to encourage pollination
  13665. by beetle.</p>
  13666. HTML chapter-16/centering-images.html By default, images are inline
  13667. elements. This means that they
  13668. flow within the surrounding text.
  13669. In order to center an image, it
  13670. should be turned into a blocklevel
  13671. element using the display
  13672. property with a value of block.
  13673. Once it has been made into a
  13674. block-level element, there are
  13675. two common ways in which you
  13676. can horizontally center an image:
  13677. 1: On the containing element,
  13678. you can use the text-align
  13679. property with a value of center.
  13680. 2: On the image itself, you can
  13681. use the use the margin property
  13682. and set the values of the left and
  13683. right margins to auto.
  13684. You can specify class names
  13685. that allow any element to be
  13686. centered, in the same way that
  13687. you can for the dimensions or
  13688. alignment of images.
  13689. The techniques for specifying
  13690. image size and alignment of
  13691. images can also be used with
  13692. the HTML5 <figure> element,
  13693. which you met on page 119.
  13694. Centering images
  13695. Using CSS
  13696. 413 IMAGES
  13697. The background-image
  13698. property allows you to place
  13699. an image behind any HTML
  13700. element. This could be the entire
  13701. page or just part of the page. By
  13702. default, a background image will
  13703. repeat to fill the entire box.
  13704. The path to the image follows
  13705. the letters url, and it is put
  13706. inside parentheses and quotes.
  13707. Here is the image
  13708. tile used in this
  13709. example.
  13710. In the first example, you can
  13711. see a background image being
  13712. applied to an entire page
  13713. (because the CSS selector
  13714. applies to the <body> element).
  13715. In the second example, the
  13716. background image just applies to
  13717. a paragraph.
  13718. If you search online, you will
  13719. find lots of resources that offer
  13720. background textures that you
  13721. can use on your pages.
  13722. Background images are often
  13723. the last thing on the page to
  13724. load (which can make a website
  13725. seem slow to load). As with any
  13726. images you use online, if the
  13727. size of the file is large it will take
  13728. longer to download.
  13729. Background Images
  13730. background-image
  13731. p {
  13732. background-image: url("images/pattern.gif");}
  13733. chapter-16/background-image-element.html CSS
  13734. R esult
  13735. body {
  13736. background-image: url("images/pattern.gif");}
  13737. chapter-16/background-image-body.html CSS
  13738. R esult
  13739. Article
  13740. IMAGES 414
  13741. The background-repeat
  13742. property can have four values:
  13743. repeat
  13744. The background image is
  13745. repeated both horizontally and
  13746. vertically (the default way it
  13747. is shown if the backgroundrepeat
  13748. property isn't used).
  13749. repeat-x
  13750. The image is repeated
  13751. horizontally only (as shown in
  13752. the first example on the left).
  13753. repeat-y
  13754. The image is repeated vertically
  13755. only.
  13756. no-repeat
  13757. The image is only shown once.
  13758. The background-attachment
  13759. property specifies whether a
  13760. background image should stay in
  13761. one position or move as the user
  13762. scrolls up and down the page. It
  13763. can have one of two values:
  13764. fixed
  13765. The background image stays in
  13766. the same position on the page.
  13767. scroll
  13768. The background image moves
  13769. up and down as the user scrolls
  13770. up and down the page.
  13771. Repeating Images
  13772. background-repeat
  13773. background-attachment
  13774. body {
  13775. background-image: url("images/tulip.gif");
  13776. background-repeat: no-repeat;
  13777. background-attachment: fixed;}
  13778. CSS chapter-16/background-attachment.html
  13779. R esult
  13780. body {
  13781. background-image: url("images/header.gif");
  13782. background-repeat: repeat-x;}
  13783. CSS chapter-16/background-repeat.html
  13784. R esult
  13785. 415 IMAGES
  13786. When an image is not being
  13787. repeated, you can use the
  13788. background-position
  13789. property to specify where in the
  13790. browser window the background
  13791. image should be placed.
  13792. This property usually has a pair
  13793. of values. The first represents
  13794. the horizontal position and the
  13795. second represents the vertical.
  13796. left top
  13797. left center
  13798. left bottom
  13799. center top
  13800. center center
  13801. center bottom
  13802. right top
  13803. right center
  13804. right bottom
  13805. If you only specify one value,
  13806. the second value will default to
  13807. center.
  13808. You can also use a pair of pixels
  13809. or percentages. These represent
  13810. the distance from the top left
  13811. corner of the browser window
  13812. (or containing box). The top left
  13813. corner is equal to 0% 0%. The
  13814. example shown, with values of
  13815. 50% 50%, centers the image
  13816. horizontally and vertically.
  13817. Background Position
  13818. background-position
  13819. body {
  13820. background-image: url("images/tulip.gif");
  13821. background-repeat: no-repeat;
  13822. background-position: 50% 50%;}
  13823. chapter-16/background-position-percentage.html CSS
  13824. R esult
  13825. body {
  13826. background-image: url("images/tulip.gif");
  13827. background-repeat: no-repeat;
  13828. background-position: center top;}
  13829. chapter-16/background-position.html CSS
  13830. R esult
  13831. Article
  13832. IMAGES 416
  13833. The background property acts
  13834. like a shorthand for all of the
  13835. other background properties
  13836. you have just seen, and also the
  13837. background-color property.
  13838. The properties must be specified
  13839. in the following order, but you
  13840. can miss any value if you do not
  13841. want to specify it.
  13842. 1: background-color
  13843. 2: background-image
  13844. 3: background-repeat
  13845. 4: background-attachment
  13846. 5: background-position
  13847. CSS3 will also support the use
  13848. of multiple background images
  13849. by repeating the background
  13850. shorthand. Because few
  13851. browsers supported this
  13852. property at the time of writing, it
  13853. was not commonly used.
  13854. div {
  13855. background:
  13856. url(example-1.jpg)
  13857. top left no-repeat,
  13858. url(example-2.jpg)
  13859. bottom left no-repeat,
  13860. url(example-3.jpg)
  13861. centre top repeat-x;}
  13862. The first image is shown on top,
  13863. with the last one on the bottom.
  13864. shorthand
  13865. background
  13866. body {
  13867. background: #ffffff url("images/tulip.gif")
  13868. no-repeat top right;}
  13869. CSS chapter-16/background-shorthand.html
  13870. R esult
  13871. 417 IMAGES
  13872. Article
  13873. 417 IMAGES
  13874. a.button {
  13875. height: 36px;
  13876. background-image: url("images/button-sprite.jpg");
  13877. text-indent: -9999px;
  13878. display: inline-block;}
  13879. a#add-to-basket {
  13880. width: 174px;
  13881. background-position: 0px 0px;}
  13882. a#framing-options {
  13883. width: 210px;
  13884. background-position: -175px 0px;}
  13885. a#add-to-basket:hover {
  13886. background-position: 0px -40px;}
  13887. a#framing-options:hover {
  13888. background-position: -175px -40px;}
  13889. a#add-to-basket:active {
  13890. background-position: 0px -80px;}
  13891. a#framing-options:active {
  13892. background-position: -175px -80px;}
  13893. CSS
  13894. Using CSS, it is possible to create
  13895. a link or button that changes to a
  13896. second style when a user moves
  13897. their mouse over it (known as a
  13898. rollover) and a third style when
  13899. they click on it.
  13900. This is achieved by setting a
  13901. background image for the link or
  13902. button that has three different
  13903. styles of the same button (but
  13904. only allows enough space to
  13905. show one of them at a time).
  13906. You can see the image we are
  13907. using in this example on the
  13908. right. It actually features two
  13909. buttons on the one image.
  13910. When the user moves their
  13911. mouse over the element, or
  13912. clicks on it, the position of the
  13913. background image is moved to
  13914. show the relevant image.
  13915. When a single image is used
  13916. for several different parts of an
  13917. interface, it is known as a sprite.
  13918. You can add the logo and other
  13919. interface elements, as well as
  13920. buttons to the image.
  13921. The advantage of using sprites is
  13922. that the web browser only needs
  13923. to request one image rather than
  13924. many images, which can make
  13925. the web page load faster.
  13926. Image Rollovers
  13927. & Sprites
  13928. <a class="button" id="add-to-basket">
  13929. Add to basket</a>
  13930. <a class="button" id="framing-options">
  13931. Framing options</a>
  13932. chapter-16/image-rollovers-and-sprites.html HTML
  13933. Article
  13934. IMAGES 418
  13935. R esult
  13936. In this example, you can see two
  13937. links that look like buttons. Each
  13938. of the buttons has three different
  13939. states. These are all represented
  13940. in a single image.
  13941. Because the <a> element is
  13942. an inline element, we set the
  13943. display property of these links
  13944. to indicate that they should be
  13945. inline-block elements. This
  13946. allows us to specify the width
  13947. and height of each <a> element
  13948. so that it matches the size of its
  13949. corresponding button.
  13950. The background-position
  13951. property is used to move the
  13952. image in order to show the
  13953. button in the right state.
  13954. When the user hovers over a
  13955. link, the :hover pseudo-class
  13956. has a rule that moves the
  13957. background-position of the
  13958. image to show a different state
  13959. for that button.
  13960. Similarly, when the user clicks on
  13961. the link, the :active pseudoclass
  13962. has a rule to show the third
  13963. state for that button.
  13964. Touch screen devices will not
  13965. change a link's state when
  13966. the user hovers over it, as the
  13967. screens do not yet have a way
  13968. to tell when the user is hovering.
  13969. However, they will change their
  13970. appearance when the user
  13971. activates them.
  13972. Complete Image Sprite
  13973. 419 IMAGES
  13974. Article
  13975. 419 IMAGES
  13976. CSS3 is going to introduce the
  13977. ability to specify a gradient for
  13978. the background of a box. The
  13979. gradient is created using the
  13980. background-image property
  13981. and, at the time of writing,
  13982. different browsers required a
  13983. different syntax.
  13984. Since it is not supported by all
  13985. browsers, it is possible to specify
  13986. a background image for the box
  13987. first (which would represent the
  13988. gradient) and then provide the
  13989. CSS alternatives for browsers
  13990. that support gradients.
  13991. On this page, we are focusing
  13992. on linear gradients. You can see
  13993. that in order to create a linear
  13994. gradient, we need to specify
  13995. two colors (that the gradient is
  13996. between).
  13997. Some browsers allow you
  13998. to specify the angle of the
  13999. gradient, or even different types
  14000. of gradients (such as radial
  14001. gradients), but support is not
  14002. as widespread as that for linear
  14003. gradients.
  14004. R esult
  14005. CSS
  14006. #gradient {
  14007. /* fallback color */
  14008. background-color: #66cccc;
  14009. /* fallback image */
  14010. background-image: url(images/fallback-image.png);
  14011. /* Firefox 3.6+ */
  14012. background-image: -moz-linear-gradient(#336666,
  14013. #66cccc);
  14014. /* Safari 4+, Chrome 1+ */
  14015. background-image: -webkit-gradient(linear, 0% 0%,
  14016. 0% 100%, from(#66cccc), to(#336666));
  14017. /* Safari 5.1+, Chrome 10+ */
  14018. background-image: -webkit-linear-gradient(#336666,
  14019. #66cccc);
  14020. /* Opera 11.10+ */
  14021. background-image: -o-linear-gradient(#336666,
  14022. #66cccc);
  14023. height: 150px;
  14024. width: 300px;}
  14025. chapter-16/gradient.html
  14026. CSS3: Gradients
  14027. background-image
  14028. IMAGES 420
  14029. If you want to overlay text on a background image, the image must be low
  14030. contrast in order for the text to be legible.
  14031. Contrast of
  14032. background images
  14033. High Contrast Low Contrast Screen
  14034. A high contrast
  14035. background
  14036. image makes
  14037. the text difficult
  14038. to read.
  14039. A low contrast
  14040. background
  14041. image makes
  14042. the text easier
  14043. to read.
  14044. A screen
  14045. added to a high
  14046. contrast image
  14047. makes the text
  14048. easier to read.
  14049. The majority of photographs
  14050. have quite a high contrast, which
  14051. means that they are not ideal for
  14052. use as a background image.
  14053. Image editing applications such
  14054. as Photoshop and GIMP have
  14055. tools that allow you to manually
  14056. adjust your images to have lower
  14057. contrast.
  14058. To overlay text on an image with
  14059. high contrast, you can place a
  14060. semi-transparent background
  14061. color (or "screen") behind the
  14062. text to improve legibility.
  14063. 421 IMAGES
  14064. Example
  14065. IMAGES
  14066. IMAGES 422
  14067. A background texture is applied to the whole page by repeating an
  14068. image with the texture behind the <body> element. A repeating
  14069. background image is sometimes referred to as wallpaper.
  14070. The content of the page is put inside a <div> element whose class is
  14071. wrapper. This is used to fix the width of the page to 720 pixels. Its left
  14072. and right margins are set to auto to center it in the middle of the screen.
  14073. The images sit inside an HTML5 <figure> element, and their captions
  14074. are provided in the <figcaption> element. CSS is used to set the
  14075. dimensions and background color for each <figure> element. The
  14076. dimensions of the images themselves are also set using CSS, and they
  14077. are given a single pixel gray border.
  14078. For the captions, a background image is used to the left of the text. We
  14079. do not want this image to fill the background so we specify that it should
  14080. not repeat. Padding is used to the left of the text so that the words do
  14081. not go over the background image.
  14082. Each of the <figure> elements is contained within a <div>, which has
  14083. two purposes. Firstly, it is used to create the three-column layout by
  14084. specifying a width and margins for the element and then floating it to
  14085. the left. Secondly, it adds a subtle shadow underneath each image. This
  14086. creates a three-dimensional appearance making it look like a piece of
  14087. card. To ensure that this sits underneath the image, the backgroundposition
  14088. property is used.
  14089. This example demonstrates how to use CSS to
  14090. create a simple image gallery layout.
  14091. 423 IMAGES
  14092. Example
  14093. IMAGES
  14094. <!DOCTYPE html>
  14095. <html>
  14096. <head>
  14097. <title>Images</title>
  14098. <style type="text/css">
  14099. body {
  14100. color: #665544;
  14101. background-color: #d4d0c6;
  14102. background-image: url("images/backdrop.gif");
  14103. font-family: Georgia, "Times New Roman", serif;
  14104. text-align: center;}
  14105. .wrapper {
  14106. width: 720px;
  14107. margin: 0px auto;}
  14108. .header {
  14109. margin: 40px 0px 20px 0px;}
  14110. .entry {
  14111. width: 220px;
  14112. float: left;
  14113. margin: 10px;
  14114. height: 198px;
  14115. background-image: url("images/shadow.png");
  14116. background-repeat: no-repeat;
  14117. background-position: bottom;}
  14118. figure {
  14119. display: block;
  14120. width: 202px;
  14121. height: 170px;
  14122. background-color: #e7e3d8;
  14123. padding: 9px;
  14124. text-align: left;}
  14125. figure img {
  14126. width: 200px;
  14127. height: 150px;
  14128. border: 1px solid #d6d6d6;}
  14129. figcaption {
  14130. background-image: url("images/icon.png");
  14131. padding-left: 20px;
  14132. background-repeat: no-repeat;}
  14133. </style>
  14134. IMAGES 424
  14135. Example
  14136. IMAGES
  14137. </head>
  14138. <body>
  14139. <div class="wrapper">
  14140. <div class="header">
  14141. <img src="images/title.gif" alt="Galerie Botanique" width="456" height="122" />
  14142. <p>Here is a selection of antique botanical prints held in our collection.</p>
  14143. </div>
  14144. <div class="entry">
  14145. <figure><img src="images/print-01.jpg" alt="Helianthus" />
  14146. <figcaption>Helianthus</figcaption>
  14147. </figure>
  14148. </div>
  14149. <div class="entry">
  14150. <figure><img src="images/print-02.jpg" alt="Passiflora" />
  14151. <figcaption>Passiflora</figcaption>
  14152. </figure>
  14153. </div>
  14154. <div class="entry">
  14155. <figure><img src="images/print-03.jpg" alt="Nyctocalos" />
  14156. <figcaption>Nyctocalos</figcaption>
  14157. </figure>
  14158. </div>
  14159. <div class="entry">
  14160. <figure><img src="images/print-04.jpg" alt="Polianthes" />
  14161. <figcaption>Polianthes</figcaption>
  14162. </figure>
  14163. </div>
  14164. <div class="entry">
  14165. <figure><img src="images/print-05.jpg" alt="Ficus" />
  14166. <figcaption>Ficus</figcaption>
  14167. </figure>
  14168. </div>
  14169. <div class="entry">
  14170. <figure><img src="images/print-06.jpg" alt="Dendrobium" />
  14171. <figcaption>Dendrobium</figcaption>
  14172. </figure>
  14173. </div>
  14174. </div>
  14175. </body>
  14176. </html>
  14177.  
  14178. Summary
  14179. IMAGES
  14180. X You can specify the dimensions of images using CSS.
  14181. This is very helpful when you use the same sized
  14182. images on several pages of your site.
  14183. X Images can be aligned both horizontally and vertically
  14184. using CSS.
  14185. X You can use a background image behind the box
  14186. created by any element on a page.
  14187. X Background images can appear just once or be
  14188. repeated across the background of the box.
  14189. X You can create image rollover effects by moving the
  14190. background position of an image.
  14191. X To reduce the number of images your browser has to
  14192. load, you can create image sprites.
  14193.  
  14194. HTML5 Layout
  14195. 17
  14196. X HTML5 layout elements
  14197. X How old browsers understand new elements
  14198. X Styling HTML5 layout elements with CSS
  14199. 429 HTML5 LAYOUT
  14200. HTML5 is introducing a new set of
  14201. elements that help define the structure of
  14202. a page.
  14203. They are covered here (rather than with the other HTML
  14204. elements you met earlier in the book) because you'll find
  14205. it easier to understand how they can be used now that you
  14206. have seen how CSS can control the layout a page. These
  14207. new elements are going to play an important part in creating
  14208. layouts going forward. In this chapter you will see:
  14209. ● The new HTML5 layout elements and their uses
  14210. ● How they offer helpful alternatives to the <div> element
  14211. ● How to ensure older browsers recognize these elements
  14212. As with all HTML5 and CSS3 content, its usage is still
  14213. subject to change but it is already widely being used by web
  14214. developers and it is likely that you will want to use them.
  14215. HTML5 LAYOUT 430
  14216. 431 HTML5 LAYOUT
  14217. On the right you can see a
  14218. layout that is quite common
  14219. (particularly on blog sites).
  14220. At the top of the page is the
  14221. header, containing a logo and the
  14222. primary navigation.
  14223. Under this are one or more
  14224. articles or posts. Sometimes
  14225. these are summaries that link to
  14226. individual posts.
  14227. There is a side bar on the righthand
  14228. side (perhaps featuring
  14229. a search option, links to other
  14230. recent articles, other sections of
  14231. the site, or even ads).
  14232. When coding a site like this,
  14233. developers would usually put
  14234. these main sections of the page
  14235. inside <div> elements and use
  14236. the class or id attributes to
  14237. indicate the purpose of that part
  14238. of the page.
  14239. For a long time, web page authors used <div> elements to group
  14240. together related elements on the page (such as the elements that form a
  14241. header, an article, footer or sidebar). Authors used class or id attributes
  14242. to indicate the role of the <div> element in the structure of the page.
  14243. Traditional HTML
  14244. Layouts
  14245. <body>
  14246. <div id="page">
  14247. <div id="header">
  14248. <div id="content">
  14249. <div id="footer">
  14250. <div id=
  14251. "sidebar">
  14252. <div id="nav">
  14253. <div class="article">
  14254. <div class="article">
  14255. HTML5 LAYOUT 432
  14256. This example has exactly the
  14257. same structure as seen on the
  14258. previous page. However, many
  14259. of the <div> elements have been
  14260. replaced by new HTML5 layout
  14261. elements.
  14262. For example, the header sits
  14263. inside a new <header> element,
  14264. the navigation in a <nav>
  14265. element, and the articles are in
  14266. individual <article> elements.
  14267. The point of creating these
  14268. new elements is so that web
  14269. page authors can use them to
  14270. help describe the structure of
  14271. the page. For example, screen
  14272. reader software might allow
  14273. users to ignore headers and
  14274. footers and get straight to
  14275. the content. Similarly, search
  14276. engines might place more
  14277. weight on the content in an
  14278. <article> element than that
  14279. in the <header> or <footer>
  14280. elements. I think you will agree
  14281. that it also makes the code
  14282. easier to follow.
  14283. HTML5 introduces a new set of elements that allow you to divide up the
  14284. parts of a page. The names of these elements indicate the kind of content
  14285. you will find in them. They are still subject to change, but that has not
  14286. stopped many web page authors using them already.
  14287. New Html5 Layout
  14288. Elements
  14289. <body>
  14290. <div id="page">
  14291. <header>
  14292. <div id="content">
  14293. <footer>
  14294. <aside>
  14295. <nav>
  14296. <article>
  14297. <article>
  14298. 433 HTML5 LAYOUT
  14299. <header>
  14300. <h1>Yoko's Kitchen</h1>
  14301. <nav>
  14302. <ul>
  14303. <li><a href="" class="current">home</a></li>
  14304. <li><a href="">classes</a></li>
  14305. <li><a href="">catering</a></li>
  14306. <li><a href="">about</a></li>
  14307. <li><a href="">contact</a></li>
  14308. </ul>
  14309. </nav>
  14310. </header>
  14311. chapter-17/example.html HTML
  14312. The <header> and <footer>
  14313. elements can be used for:
  14314. ● The main header or footer
  14315. that appears at the top or
  14316. bottom of every page on the
  14317. site.
  14318. ● A header or footer for an
  14319. individual <article> or
  14320. <section> within the page.
  14321. In this example, the <header>
  14322. element used to contain the site
  14323. name and the main navigation.
  14324. The <footer> element contains
  14325. copyright information, along
  14326. with links to the privacy policy
  14327. and terms and conditions.
  14328. Each individual <article> and
  14329. <section> element can also
  14330. have its own <header> and
  14331. <footer> elements to hold the
  14332. header or footer information for
  14333. that section within the page.
  14334. For example, on a page with
  14335. several blog posts, each
  14336. individual post can be thought
  14337. of as a separate section. The
  14338. <header> element can therefore
  14339. be used to contain the title and
  14340. date of each individual post, and
  14341. the <footer> might contain
  14342. links to share the article on
  14343. social networking sites.
  14344. Please note that all of the
  14345. code shown in this chapter
  14346. is referenced in one HTML
  14347. document which is called:
  14348. html5-layout.html
  14349. Headers & Footers
  14350. <header> <footer>
  14351. <footer>
  14352. &copy; 2011 Yoko's Kitchen
  14353. </footer>
  14354. chapter-17/example.html HTML
  14355. Article
  14356. HTML5 LAYOUT 434
  14357. The <nav> element is used to
  14358. contain the major navigational
  14359. blocks on the site such as the
  14360. primary site navigation.
  14361. Going back to our blog example,
  14362. if you wanted to finish an article
  14363. with links to related blog posts,
  14364. these would not be counted as
  14365. major navigational blocks and
  14366. therefore should not sit inside a
  14367. <nav> element.
  14368. At the time of writing, some of
  14369. the developers that were already
  14370. using HTML5 decided to use the
  14371. <nav> element for the links that
  14372. appear at the bottom of every
  14373. page (links to things like privacy
  14374. policy, terms and conditions
  14375. and accessibility information).
  14376. Whether this will be widely
  14377. adopted is still yet to be seen.
  14378. <nav>
  14379. <ul>
  14380. <li><a href="" class="current">home</a></li>
  14381. <li><a href="">classes</a></li>
  14382. <li><a href="">catering</a></li>
  14383. <li><a href="">about</a></li>
  14384. <li><a href="">contact</a></li>
  14385. </ul>
  14386. </nav>
  14387. HTML chapter-17/example.html
  14388. Navigation
  14389. <nav>
  14390. 435 HTML5 LAYOUT
  14391. <article>
  14392. <figure>
  14393. <img src="images/bok-choi.jpg" alt="Bok Choi" />
  14394. <figcaption>Bok Choi</figcaption>
  14395. </figure>
  14396. <hgroup>
  14397. <h2>Japanese Vegetarian</h2>
  14398. <h3>Five week course in London</h3>
  14399. </hgroup>
  14400. <p>A five week introduction to traditional
  14401. Japanese vegetarian meals, teaching you a
  14402. selection of rice and noodle dishes.</p>
  14403. </article>
  14404. <article>
  14405. <figure>
  14406. <img src="images/teriyaki.jpg"
  14407. alt="Teriyaki sauce" />
  14408. <figcaption>Teriyaki Sauce</figcaption>
  14409. </figure>
  14410. <hgroup>
  14411. <h2>Sauces Masterclass</h2>
  14412. <h3>One day workshop</h3>
  14413. </hgroup>
  14414. <p>An intensive one-day course looking at how to
  14415. create the most delicious sauces for use in a
  14416. range of Japanese cookery.</p>
  14417. </article>
  14418. chapter-17/example.html HTML
  14419. The <article> element acts as
  14420. a container for any section of a
  14421. page that could stand alone and
  14422. potentially be syndicated.
  14423. This could be an individual
  14424. article or blog entry, a comment
  14425. or forum post, or any other
  14426. independent piece of content.
  14427. If a page contains several articles
  14428. (or even summaries of several
  14429. articles), then each individual
  14430. article would live inside its own
  14431. <article> element.
  14432. The <article> elements can
  14433. even be nested inside each
  14434. other. For example, a blog post
  14435. might live inside one <article>
  14436. element and each comment on
  14437. the article could live inside its
  14438. own child <article> element.
  14439. Articles
  14440. <article>
  14441. Article
  14442. HTML5 LAYOUT 436
  14443. The <aside> element has two
  14444. purposes, depending on whether
  14445. it is inside an <article>
  14446. element or not.
  14447. When the <aside> element
  14448. is used inside an <article>
  14449. element, it should contain
  14450. information that is related to the
  14451. article but not essential to its
  14452. overall meaning. For example, a
  14453. pullquote or glossary might be
  14454. considered as an aside to the
  14455. article it relates to.
  14456. When the <aside> element is
  14457. used outside of an <article>
  14458. element, it acts as a container
  14459. for content that is related to
  14460. the entire page. For example,
  14461. it might contain links to other
  14462. sections of the site, a list of
  14463. recent posts, a search box, or
  14464. recent tweets by the author.
  14465. <aside>
  14466. <section class="popular-recipes">
  14467. <h2>Popular Recipes</h2>
  14468. <a href="">Yakitori (grilled chicken)</a>
  14469. <a href="">Tsukune (minced chicken patties)</a>
  14470. <a href="">Okonomiyaki (savory pancakes)</a>
  14471. <a href="">Mizutaki (chicken stew)</a>
  14472. </section>
  14473. <section class="contact-details">
  14474. <h2>Contact</h2>
  14475. <p>Yoko's Kitchen<br />
  14476. 27 Redchurch Street<br />
  14477. Shoreditch<br />
  14478. London E2 7DP</p>
  14479. </section>
  14480. </aside>
  14481. HTML chapter-17/example.html
  14482. Asides
  14483. <aside>
  14484. 437 HTML5 LAYOUT
  14485. <section class="popular-recipes">
  14486. <h2>Popular Recipes</h2>
  14487. <a href="">Yakitori (grilled chicken)</a>
  14488. <a href="">Tsukune (minced chicken patties)</a>
  14489. <a href="">Okonomiyaki (savory pancakes)</a>
  14490. <a href="">Mizutaki (chicken stew)</a>
  14491. </section>
  14492. <section class="contact-details">
  14493. <h2>Contact</h2>
  14494. <p>Yoko's Kitchen<br />
  14495. 27 Redchurch Street<br />
  14496. Shoreditch<br />
  14497. London E2 7DP</p>
  14498. </section>
  14499. chapter-17/example.html HTML
  14500. The <section> element groups
  14501. related content together, and
  14502. typically each section would
  14503. have its own heading.
  14504. For example, on a homepage
  14505. there may be several <section>
  14506. elements to contain different
  14507. sections of the page, such as
  14508. latest news, top products, and
  14509. newsletter signup.
  14510. Because the <section> element
  14511. groups related items together,
  14512. it may contain several distinct
  14513. <article> elements that have a
  14514. common theme or purpose.
  14515. Alternatively, if you have a
  14516. page with a long article, the
  14517. <section> element can be
  14518. used to split the article up into
  14519. separate sections.
  14520. The <section> element should
  14521. not be used as a wrapper for
  14522. the entire page (unless the
  14523. page only contains one distinct
  14524. piece of content). If you want a
  14525. containing element for the entire
  14526. page, that job is still best left to
  14527. the <div> element.
  14528. Sections
  14529. <section>
  14530. Article
  14531. HTML5 LAYOUT 438
  14532. The purpose of the <hgroup>
  14533. element is to group together a
  14534. set of one or more <h1> through
  14535. <h6> elements so that they are
  14536. treated as one single heading.
  14537. For example, the <hgroup>
  14538. element could be used to contain
  14539. both a title inside an <h2>
  14540. element and a subtitle within an
  14541. <h3> element.
  14542. This element has had a mixed
  14543. reception. When it was first
  14544. proposed by the people
  14545. developing HTML5, there were
  14546. some complaints and it was
  14547. withdrawn from the HTML5
  14548. proposals. However, some
  14549. people changed their minds and
  14550. it has been added it back into the
  14551. language. Some developers do
  14552. not like the use of the <hgroup>
  14553. element, and prefer to place a
  14554. subtitle inside a <p> element
  14555. (using an attribute to indicate
  14556. that it is a subheading).
  14557. Some suggest that it is of little
  14558. use other than as a styling hook.
  14559. It has, however, been popular
  14560. with those developers who
  14561. believe that it is useful to group
  14562. together the primary heading
  14563. and the subheading (as both can
  14564. be integral parts of a heading).
  14565. <hgroup>
  14566. <h2>Japanese Vegetarian</h2>
  14567. <h3>Five week course in London</h3>
  14568. </hgroup>
  14569. HTML chapter-17/example.html
  14570. Heading Groups
  14571. <hgroup>
  14572. 439 HTML5 LAYOUT
  14573. <figure>
  14574. <img src="images/bok-choi.jpg" alt="Bok Choi" />
  14575. <figcaption>Bok Choi</figcaption>
  14576. </figure>
  14577. chapter-17/example.html HTML You already met the <figure>
  14578. element in Chapter 5 when we
  14579. looked at images. It can be used
  14580. to contain any content that is
  14581. referenced from the main flow of
  14582. an article (not just images).
  14583. It is important to note that the
  14584. article should still make sense
  14585. if the content of the <figure>
  14586. element were moved (to another
  14587. part of the page, or even to a
  14588. different page altogether).
  14589. For this reason, it should only be
  14590. used when the content simply
  14591. references the element (and not
  14592. for something that is absolutely
  14593. integral to the flow of a page).
  14594. Examples of usage include:
  14595. ● Images
  14596. ● Videos
  14597. ● Graphs
  14598. ● Diagrams
  14599. ● Code samples
  14600. ● Text that supports the main
  14601. body of an article
  14602. The <figure> element should
  14603. also contain a <figcaption>
  14604. element which provides a text
  14605. decription for the content of
  14606. the <figure> element. In
  14607. this example, you can see a
  14608. <figure> has been added inside
  14609. the <article> element.
  14610. Figures
  14611. <figure> <figcaption>
  14612. Article
  14613. HTML5 LAYOUT 440
  14614. <div class="wrapper">
  14615. <header>
  14616. <h1>Yoko's Kitchen</h1>
  14617. <nav>
  14618. <!-- nav content here -->
  14619. </nav>
  14620. </header>
  14621. <section class="courses">
  14622. <!-- section content here -->
  14623. </section>
  14624. <aside>
  14625. <!-- aside content here -->
  14626. </aside>
  14627. <footer>
  14628. <!-- footer content here -->
  14629. </footer>
  14630. </div><!-- .wrapper -->
  14631. HTML chapter-17/example.html It may seem strange to follow
  14632. these new elements by revisiting
  14633. the <div> element again. (After
  14634. all, the new elements are often
  14635. going to be used in its place.)
  14636. However, the <div> element
  14637. will remain an important way to
  14638. group together related elements,
  14639. because you should not be using
  14640. these new elements that you
  14641. have just met for purposes other
  14642. than those explicitly stated.
  14643. Where there is no suitable
  14644. element to group a set of
  14645. elements, the <div> element will
  14646. still be used. In this example, it is
  14647. used as a wrapper for the entire
  14648. page.
  14649. Some people have asked why
  14650. there is no <content> element
  14651. to contain the main part of
  14652. a page. The reason is that
  14653. anything that lies outside of the
  14654. <header>, <footer> or <aside>
  14655. elements can be considered as
  14656. the main content.
  14657. Sectioning Elements
  14658. <div>
  14659. 441 HTML5 LAYOUT
  14660. <a href="introduction.html">
  14661. <article>
  14662. <figure>
  14663. <img src="images/bok-choi.jpg"
  14664. alt="Bok Choi" />
  14665. <figcaption>Bok Choi</figcaption>
  14666. </figure>
  14667. <hgroup>
  14668. <h2>Japanese Vegetarian</h2>
  14669. <h3>Five week course in London</h3>
  14670. </hgroup>
  14671. <p>A five week introduction to traditional
  14672. Japanese vegetarian meals, teaching you a
  14673. selection of rice and noodle dishes.</p>
  14674. </article>
  14675. </a>
  14676. chapter-17/example.html HTML HTML5 allows web page authors
  14677. to place an <a> element around
  14678. a block level element that
  14679. contains child elements. This
  14680. allows you to turn an entire block
  14681. into a link.
  14682. This is not a new element in
  14683. HTML5, but it was not seen as a
  14684. correct usage of the <a> element
  14685. in earlier versions of HTML.
  14686. Linking Around
  14687. Block-Level Elements
  14688. Article
  14689. HTML5 LAYOUT 442
  14690. Older browsers that do not
  14691. know the new HTML5 elements
  14692. will automatically treat them as
  14693. inline elements. Therefore, to
  14694. help older browsers, you should
  14695. include the line of CSS on the
  14696. left which states which new
  14697. elements should be rendered as
  14698. block-level elements.
  14699. Also, IE9 was the first version of
  14700. Internet Explorer to allow CSS
  14701. rules to be associated with these
  14702. new HTML5 layout elements.
  14703. In order to style these elements
  14704. using earlier versions of IE, you
  14705. need to use a simple JavaScript
  14706. known as the HTML5 shiv or
  14707. HTML5 shim.
  14708. You do not need to understand
  14709. JavaScript to use it. You can
  14710. just link to a copy that Google
  14711. hosts on its servers. It should
  14712. be placed inside a conditional
  14713. comment which checks if the
  14714. browser version is less than
  14715. (hence the lt) IE9.
  14716. Unfortunately, this workaround
  14717. does require that anyone using
  14718. IE8 or earlier versions of IE
  14719. has JavaScript enabled in their
  14720. browser. If they do not have
  14721. JavaScript enabled then they will
  14722. not be able to see the content of
  14723. these HTML5 elements.
  14724. header, section, footer, aside, nav, article, figure
  14725. {
  14726. display: block;}
  14727. CSS chapter-17/example.html
  14728. Helping Older
  14729. Browsers Understand
  14730. <!--[if lt IE 9]>
  14731. <script src="http://html5shiv.googlecode.com/svn/
  14732. trunk/html5.js"></script>
  14733. <![endif]-->
  14734. HTML chapter-17/example.html
  14735. 443 HTML5 LAYOUT
  14736. Example
  14737. HTML5 LAYOUT
  14738. HTML5 LAYOUT 444
  14739. The header and footer of the page sit inside <header> and <footer>
  14740. elements. The courses are grouped together inside a <section>
  14741. element that has a class attribute whose value is courses (to
  14742. distinguish it from other <section> elements on the page). The sidebar
  14743. sits inside an <aside> element.
  14744. Each of the courses lives inside an <article> element, and use the
  14745. <figure> and <figcaption> elements to contain an image. The
  14746. headings for the courses have subheadings, so these are grouped inside
  14747. an <hgroup> element. In the sidebar, the recipes and contact details are
  14748. placed inside separate <section> elements.
  14749. The page is styled using CSS. The only difference is that our selectors
  14750. are using the new HTML5 elements to allow us to create rules that
  14751. target those elements. In order for the CSS to work in versions of IE
  14752. before Internet Explorer 9, the HTML5 page contains a link to the
  14753. HTML5 shiv JavaScript (hosted on Google's servers) inside a
  14754. conditional comment.
  14755. This example shows a cooking site built using
  14756. new HTML5 elements to describe the structure
  14757. of the page (rather than just grouping items
  14758. using <div> elements).
  14759. 445 HTML5 LAYOUT
  14760. Example
  14761. HTML5 LAYOUT
  14762. <!DOCTYPE html>
  14763. <html>
  14764. <head>
  14765. <title>HTML5 Layout</title>
  14766. <style type="text/css">
  14767. header, section, footer, aside, nav, article, figure, figcaption {
  14768. display: block;}
  14769. body {
  14770. color: #666666;
  14771. background-color: #f9f8f6;
  14772. background-image: url("images/dark-wood.jpg");
  14773. background-position: center;
  14774. font-family: Georgia, times, serif;
  14775. line-height: 1.4em;
  14776. margin: 0px;}
  14777. .wrapper {
  14778. width: 940px;
  14779. margin: 20px auto 20px auto;
  14780. border: 2px solid #000000;
  14781. background-color: #ffffff;}
  14782. header {
  14783. height: 160px;
  14784. background-image: url(images/header.jpg);}
  14785. h1 {
  14786. text-indent: -9999px;
  14787. width: 940px;
  14788. height: 130px;
  14789. margin: 0px;}
  14790. nav, footer {
  14791. clear: both;
  14792. color: #ffffff;
  14793. background-color: #aeaca8;
  14794. height: 30px;}
  14795. nav ul {
  14796. margin: 0px;
  14797. padding: 5px 0px 5px 30px;}
  14798. nav li {
  14799. display: inline;
  14800. margin-right: 40px;}
  14801. nav li a {
  14802. HTML5 LAYOUT 446
  14803. Example
  14804. HTML5 LAYOUT
  14805. color: #ffffff;}
  14806. nav li a:hover, nav li a.current {
  14807. color: #000000;}
  14808. section.courses {
  14809. float: left;
  14810. width: 659px;
  14811. border-right: 1px solid #eeeeee;}
  14812. article {
  14813. clear: both;
  14814. overflow: auto;
  14815. width: 100%;}
  14816. hgroup {
  14817. margin-top:40px;}
  14818. figure {
  14819. float: left;
  14820. width: 290px;
  14821. height: 220px;
  14822. padding: 5px;
  14823. margin: 20px;
  14824. border: 1px solid #eeeeee;}
  14825. figcaption {
  14826. font-size: 90%;
  14827. text-align: left;}
  14828. aside {
  14829. width: 230px;
  14830. float: left;
  14831. padding: 0px 0px 0px 20px;}
  14832. aside section a {
  14833. display: block;
  14834. padding: 10px;
  14835. border-bottom: 1px solid #eeeeee;}
  14836. aside section a:hover {
  14837. color: #985d6a;
  14838. background-color: #efefef;}
  14839. a {
  14840. color: #de6581;
  14841. text-decoration: none;}
  14842. h1, h2, h3 {
  14843. font-weight: normal;}
  14844. h2 {
  14845. 447 HTML5 LAYOUT
  14846. Example
  14847. HTML5 LAYOUT
  14848. margin: 10px 0px 5px 0px;
  14849. padding: 0px;}
  14850. h3 {
  14851. margin: 0px 0px 10px 0px;
  14852. color: #de6581;}
  14853. aside h2 {
  14854. padding: 30px 0px 10px 0px;
  14855. color: #de6581;}
  14856. footer {
  14857. font-size: 80%;
  14858. padding: 7px 0px 0px 20px;}
  14859. </style>
  14860. <!--[if lt IE 9]>
  14861. <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  14862. <![endif]-->
  14863. </head>
  14864. <body>
  14865. <div class="wrapper">
  14866. <header>
  14867. <h1>Yoko's Kitchen</h1>
  14868. <nav>
  14869. <ul>
  14870. <li><a href="" class="current">home</a></li>
  14871. <li><a href="">classes</a></li>
  14872. <li><a href="">catering</a></li>
  14873. <li><a href="">about</a></li>
  14874. <li><a href="">contact</a></li>
  14875. </ul>
  14876. </nav>
  14877. </header>
  14878. <section class="courses">
  14879. <article>
  14880. <figure>
  14881. <img src="images/bok-choi.jpg" alt="Bok Choi" />
  14882. <figcaption>Bok Choi</figcaption>
  14883. </figure>
  14884. <hgroup>
  14885. <h2>Japanese Vegetarian</h2>
  14886. <h3>Five week course in London</h3>
  14887. </hgroup>
  14888. HTML5 LAYOUT 448
  14889. Example
  14890. HTML5 LAYOUT
  14891. <p>A five week introduction to traditional Japanese vegetarian meals,
  14892. teaching you a selection of rice and noodle dishes.</p>
  14893. </article>
  14894. <article>
  14895. <figure>
  14896. <img src="images/teriyaki.jpg" alt="Teriyaki sauce" />
  14897. <figcaption>Teriyaki Sauce</figcaption>
  14898. </figure>
  14899. <hgroup>
  14900. <h2>Sauces Masterclass</h2>
  14901. <h3>One day workshop</h3>
  14902. </hgroup>
  14903. <p>An intensive one-day course looking at how to create the most delicious
  14904. sauces for use in a range of Japanese cookery.</p>
  14905. </article>
  14906. </section>
  14907. <aside>
  14908. <section class="popular-recipes">
  14909. <h2>Popular Recipes</h2>
  14910. <a href="">Yakitori (grilled chicken)</a>
  14911. <a href="">Tsukune (minced chicken patties)</a>
  14912. <a href="">Okonomiyaki (savory pancakes)</a>
  14913. <a href="">Mizutaki (chicken stew)</a>
  14914. </section>
  14915. <section class="contact-details">
  14916. <h2>Contact</h2>
  14917. <p>Yoko's Kitchen<br />
  14918. 27 Redchurch Street<br />
  14919. Shoreditch<br />
  14920. London E2 7DP</p>
  14921. </section>
  14922. </aside>
  14923. <footer>
  14924. &copy; 2011 Yoko's Kitchen
  14925. </footer>
  14926. </div><!-- .wrapper -->
  14927. </body>
  14928. </html>
  14929.  
  14930. Summary
  14931. HTML5 LAYOUT
  14932. X The new HTML5 elements indicate the purpose of
  14933. different parts of a web page and help to describe
  14934. its structure.
  14935. X The new elements provide clearer code (compared
  14936. with using multiple <div> elements).
  14937. X Older browsers that do not understand HTML5
  14938. elements need to be told which elements are
  14939. block-level elements.
  14940. X To make HTML5 elements work in Internet Explorer 8
  14941. (and older versions of IE), extra JavaScript is needed,
  14942. which is available free from Google.
  14943.  
  14944. X How to approach building a site
  14945. X Understanding your audience and their needs
  14946. X How to present information visitors want to see
  14947. Process
  14948. & Design
  14949. 18
  14950. 453 PROCESS
  14951. This section discusses a process that
  14952. you can use when you are creating a new
  14953. website.
  14954. It looks at who might be visiting your site and how to ensure
  14955. the pages feature the information those visitors need. It also
  14956. covers some key aspects of design theory to help you create
  14957. professional looking sites. In this chapter, we will look at:
  14958. ● How to understand the audience your site may attract and
  14959. what information they will expect to find on it
  14960. ● How to organize information so that visitors can find what
  14961. they are looking for
  14962. ● Design theory for presenting information in a way that
  14963. helps visitors achieve their goals
  14964. ● Design tips to help you create more attractive and
  14965. professional sites
  14966. PROCESS 454
  14967. 455 PROCESS
  14968. Every website should be designed for the
  14969. target audience—not just for yourself or the
  14970. site owner. It is therefore very important to
  14971. understand who your target audience is.
  14972. Who is the Site For?
  14973. Target Audience: individuals
  14974. ● What is the age range of your target audience?
  14975. ● Will your site appeal to more women or men? What is the mix?
  14976. ● Which country do your visitors live in?
  14977. ● Do they live in urban or rural areas?
  14978. ● What is the average income of visitors?
  14979. ● What level of education do they have?
  14980. ● What is their marital or family status?
  14981. ● What is their occupation?
  14982. ● How many hours do they work per week?
  14983. ● How often do they use the web?
  14984. ● What kind of device do they use to access the web?
  14985. Target Audience: Companies
  14986. ● What is the size of the company or relevant department?
  14987. ● What is the position of people in the company who visit your site?
  14988. ● Will visitors be using the site for themselves or for someone else?
  14989. ● How large is the budget they control?
  14990. It can be helpful to ask some
  14991. questions about the people you
  14992. would expect to be interested in
  14993. the subject of your site.
  14994. If you ask a client who a site is
  14995. for, it is not uncommon for them
  14996. to answer "the entire world."
  14997. Realistically, it is unlikely to be
  14998. relevant to everyone. If your site
  14999. sells light bulbs, even though
  15000. most people using a computer
  15001. probably use light bulbs, they
  15002. are not likely to order them from
  15003. someone in a different country.
  15004. Even if the site has a wide
  15005. appeal, you can still think about
  15006. the demographics of a sample of
  15007. the target audience.
  15008. PROCESS 456
  15009. Invent some fictional visitors from your typical
  15010. target audience. They will become your friends.
  15011. They can influence design decisions from color
  15012. palettes to level of detail in descriptions.
  15013. Name
  15014. Gender
  15015. Age
  15016. Location
  15017. Occupation
  15018. Income
  15019. Web Use
  15020. Gordon
  15021. M
  15022. 28
  15023. Chicago
  15024. Teacher
  15025. $62k
  15026. 2-3 days/wk
  15027. Molly
  15028. F
  15029. 47
  15030. San Francisco
  15031. Attorney
  15032. $180k
  15033. Daily
  15034. Jasper
  15035. M
  15036. 19
  15037. New York
  15038. Student
  15039. $24k
  15040. Daily
  15041. Ayo
  15042. M
  15043. 32
  15044. Miami
  15045. Retail
  15046. $160k
  15047. 4-5 days/wk
  15048. Ivy
  15049. F
  15050. 35
  15051. Boston
  15052. Journalist
  15053. $75k
  15054. Daily
  15055. If you have a question about how
  15056. the site is going to be used, or
  15057. what its priorities should be, you
  15058. will be able to think back and ask
  15059. yourself, "What would Gordon
  15060. or Molly want in this situation?"
  15061. 457 PROCESS
  15062. Your content and design should
  15063. be influenced by the goals of
  15064. your users.
  15065. To help determine why people
  15066. are coming to your website,
  15067. there are two basic categories of
  15068. questions you can ask:
  15069. 1: The first attempts to discover
  15070. the underlying motivations for
  15071. why visitors come to the site.
  15072. 2: The second examines the
  15073. specific goals of the visitors.
  15074. These are the triggers making
  15075. them come to the site now.
  15076. Key Motivations
  15077. ● Are they looking for general
  15078. entertainment or do they
  15079. need to achieve a specific
  15080. goal?
  15081. ● If there is a specific goal, is
  15082. it a personal or professional
  15083. one?
  15084. ● Do they see spending time on
  15085. this activity as essential or a
  15086. luxury?
  15087. Specific Goals
  15088. ● Do they want general
  15089. information / research (such
  15090. as background on a topic /
  15091. company), or are they after
  15092. something specific (such as a
  15093. particular fact or information
  15094. on a product)?
  15095. ● Are they already familiar with
  15096. the service or product that
  15097. you offer or do they need to
  15098. be introduced to it?
  15099. ● Are they looking for time
  15100. sensitive information, such as
  15101. the latest news or updates on
  15102. a particular topic?
  15103. ● Do they want to discover
  15104. information about a specific
  15105. product or service to help
  15106. them decide whether to buy
  15107. it or not?
  15108. ● Do they need to contact you?
  15109. If so, can they visit in person
  15110. (which might require opening
  15111. hours and a map)? Or might
  15112. they need email or telephone
  15113. contact details?
  15114. Now that you know who your visitors are, you
  15115. need to consider why they are coming. While
  15116. some people will simply chance across your
  15117. website, most will visit for a specific reason.
  15118. Why People Visit
  15119. YOUR Website
  15120. PROCESS 458
  15121. First you want to create a list
  15122. of reasons why people would
  15123. be coming to your site. You can
  15124. then assign the list of tasks to
  15125. the fictional visitors you created
  15126. in the step described on the
  15127. previous page.
  15128. Gordon bought a tennis racquet several years ago; now he wants to
  15129. purchase one from your site for his girlfriend.
  15130. Molly has read about your new doggy daycare service in the press and
  15131. wants to find out whether it would be suitable for her to use.
  15132. Jasper had a bad experience staying in a hotel when visiting Sydney,
  15133. Australia, and wants to make a complaint.
  15134. Ayo hopes to study architecture and wants to learn more about a new
  15135. course that is being offered.
  15136. Ivy is a picture editor and wants to look at a photographer's site to see
  15137. examples of his work before deciding whether to commission him.
  15138. It is unlikely that you will be able to list every
  15139. reason why someone visits your site but you
  15140. are looking for key tasks and motivations. This
  15141. information can help guide your site designs.
  15142. What Your Visitors are
  15143. Trying to Achieve
  15144. 459 PROCESS
  15145. You may want to offer additional
  15146. supporting information that you
  15147. think they might find helpful.
  15148. Look at each of the reasons why
  15149. people will be visiting your site
  15150. and determine what they need to
  15151. achieve their goals.
  15152. You can prioritize levels of
  15153. information from key points
  15154. down to non-essential or
  15155. background information.
  15156. By ensuring that you provide the
  15157. information that your visitors
  15158. are looking for, they will consider
  15159. your site more relevant to them.
  15160. Therefore, you will have more
  15161. opportunity to tell them any
  15162. extra information that you think
  15163. would be helpful to them (or to
  15164. expose them to other products
  15165. and services you want to
  15166. promote).
  15167. If you do not appear relevant to
  15168. them by answering their needs,
  15169. however, they are likely to go
  15170. elsewhere.
  15171. Here are some questions to help
  15172. you decide what information to
  15173. provide for visitors to your site...
  15174. Key Information
  15175. ● Will visitors be familiar with
  15176. your subject area / brand
  15177. or do you need to introduce
  15178. yourself?
  15179. ● Will they be familiar with
  15180. the product / service /
  15181. information you are covering
  15182. or do they need background
  15183. information on it?
  15184. ● What are the most important
  15185. features of what you are
  15186. offering?
  15187. ● What is special about what
  15188. you offer that differentiates
  15189. you from other sites that offer
  15190. something similar?
  15191. ● Once people have achieved
  15192. the goal that sent them to
  15193. your site, are there common
  15194. questions people ask about
  15195. this subject area?
  15196. You know who is coming to your site and why
  15197. they are coming, so now you need to work out
  15198. what information they need in order to achieve
  15199. their goals quickly and effectively.
  15200. What Information
  15201. Your Visitors Need
  15202. PROCESS 460
  15203. A website about fashion trends
  15204. will need to change a lot more
  15205. frequently than one that is
  15206. promoting a service that people
  15207. do not buy regularly (such as
  15208. domestic plumbing or double
  15209. glazing).
  15210. Once a site has been built, it can
  15211. take a lot of time and resources
  15212. to update it frequently.
  15213. Working out how often people
  15214. are likely to revisit your site gives
  15215. you an indication for how often
  15216. you should update the site.
  15217. It can often be helpful to set a
  15218. schedule for when a site will be
  15219. updated (rather than doing it on
  15220. an ad hoc basis).
  15221. You will often find that some
  15222. parts of a site will benefit from
  15223. being updated more frequently
  15224. than others.
  15225. Here are some questions to help
  15226. you decide how often to update
  15227. your website content...
  15228. Goods / Services
  15229. ● How often do the same
  15230. people return to purchase
  15231. from you?
  15232. ● How often is your stock
  15233. updated or your service
  15234. changed?
  15235. Information
  15236. ● How often is the subject
  15237. updated?
  15238. ● What percentage of your
  15239. visitors would return for
  15240. regular updates on the
  15241. subject, compared with
  15242. those who will just need the
  15243. information once?
  15244. Some sites benefit from being updated more
  15245. frequently than others. Some information (such
  15246. as news) may be constantly changing, while
  15247. other content remains relatively static.
  15248. How Often People Will
  15249. Visit Your Site
  15250. 461 PROCESS
  15251. The aim is to create a diagram
  15252. of the pages that will be used
  15253. to structure the site. This is
  15254. known as a site map and it will
  15255. show how those pages can be
  15256. grouped.
  15257. To help you decide what
  15258. information should go on each
  15259. page, you can use a technique
  15260. called card sorting.
  15261. This involves placing each
  15262. piece of information that a
  15263. visitor might need to know on
  15264. a separate piece of paper and
  15265. then organizing the related
  15266. information into groups.
  15267. Each group relates to a page and,
  15268. on larger sites the, pages can in
  15269. turn can be grouped together to
  15270. create different sections of the
  15271. website.
  15272. The groups of information are
  15273. then turned into the diagram
  15274. that is known as the site map.
  15275. Sometimes it can be helpful to
  15276. ask people who are the target
  15277. audience to help you group
  15278. related information together.
  15279. A site map will usually
  15280. begin with the homepage.
  15281. Additionally, if the site is large
  15282. and is compartmentalized
  15283. into sections, each section
  15284. might require its own section
  15285. homepage to link to all of the
  15286. information within it.
  15287. For example, most online shops
  15288. have section homepages for
  15289. each type of product, which then
  15290. in turn link to individual product
  15291. pages.
  15292. You may need to duplicate some
  15293. information if it needs to appear
  15294. on more than one page.
  15295. The pages (or groups of pages)
  15296. will inform how users navigate
  15297. through the site.
  15298. Remember to focus on the
  15299. goals that your visitors want to
  15300. achieve.
  15301. It is worth noting that the
  15302. site owner might organize
  15303. information in a way that is
  15304. different to what the public
  15305. expects. It is important to reflect
  15306. the public's understanding of the
  15307. subject (rather than just the site
  15308. owner's understanding of it).
  15309. Now that you know what needs to appear
  15310. on your site, you can start to organize the
  15311. information into sections or pages.
  15312. Site Maps
  15313. PROCESS 462
  15314. Example Site Map
  15315. Home
  15316. Location
  15317. Opening Times
  15318. Tickets
  15319. Books
  15320. Gifts
  15321. News
  15322. Book Reviews
  15323. Press
  15324. Interviews
  15325. History
  15326. Foundation
  15327. Future Plans
  15328. About Articles Visit Shop Contact
  15329. 463 PROCESS
  15330. A lot of designers will take the
  15331. elements that need to appear on
  15332. each page and start by creating
  15333. wireframes. This involves
  15334. sketching or shading areas
  15335. where each element of the page
  15336. will go (such as the logo, primary
  15337. navigation, headings and main
  15338. bodies of text, user logins etc).
  15339. By creating a wireframe you can
  15340. ensure that all of the information
  15341. that needs to be on a page is
  15342. included.
  15343. You should not include the
  15344. color scheme, font choices,
  15345. backgrounds or images for
  15346. the website in the wireframe.
  15347. It should focus on what
  15348. information needs to be on
  15349. each page and create a visual
  15350. hierarchy to indicate the most
  15351. important parts of each page.
  15352. The wireframes make design
  15353. easier because you know what
  15354. information needs to appear on
  15355. which page before considering
  15356. how the the page should look.
  15357. It can be very helpful to show the
  15358. wireframes of a site to a client
  15359. before showing them a design.
  15360. It enables the client to ensure
  15361. the site has all the functions and
  15362. information it needs to offer.
  15363. If you just present a site design
  15364. to a client, it is common for them
  15365. to focus on how the site looks,
  15366. which means they may not raise
  15367. issues about its function after
  15368. the site has been built.
  15369. A wireframe is a simple sketch of the key
  15370. information that needs to go on each page of a
  15371. site. It shows the hierarchy of the information
  15372. and how much space it might require.
  15373. WireFrames
  15374. The example on the right was
  15375. created in Photoshop using the
  15376. templates that come with the
  15377. 960.gs grid system.
  15378. You can sketch wireframes
  15379. on paper or use a graphics
  15380. application on your computer
  15381. (such as Illustrator or InDesign).
  15382. There are also online wireframe
  15383. tools such as those at:
  15384. http://gomockingbird.com
  15385. http://lovelycharts.com
  15386. PROCESS 464
  15387. Example Wireframe
  15388. 465 PROCESS
  15389. CONTENT
  15390. Web pages often have a lot of
  15391. information to communicate.
  15392. For example, the pages of
  15393. online newspapers will have
  15394. information that does not appear
  15395. on every page of the print
  15396. equivalent:
  15397. ● A masthead or logo
  15398. ● Links to navigate the site
  15399. ● Links to related content and
  15400. other popular articles
  15401. ● Login or membership options
  15402. ● Ability for users to comment
  15403. ● Copyright information
  15404. ● Links to privacy policies,
  15405. terms and conditions,
  15406. advertising information, RSS
  15407. feeds, subscription options
  15408. With so much on the page, the
  15409. designer needs to organize and
  15410. prioritize the information to
  15411. communicate their message
  15412. and help users find what they're
  15413. looking for.
  15414. Prioritizing
  15415. If everything on a page appeared
  15416. in the same style, it would be
  15417. much harder to understand. (Key
  15418. messages would not stand out.)
  15419. By making parts of the page
  15420. look distinct from surrounding
  15421. content, designers draw
  15422. attention to (or away from)
  15423. those items.
  15424. Designers create something
  15425. known as a visual hierarchy
  15426. to help users focus on the key
  15427. messages that will draw people's
  15428. attention, and then guide them
  15429. to subsequent messages.
  15430. We look at visual hierarchy on
  15431. pages 467-468.
  15432. Organizing
  15433. Grouping together related
  15434. content into blocks or chunks
  15435. makes the page look simpler
  15436. (and easier to understand).
  15437. Users should be able to
  15438. identify the purpose of each
  15439. block without processing each
  15440. individual item.
  15441. By presenting certain types of
  15442. information in a similar visual
  15443. style (such as using the same
  15444. style for all buttons or all links),
  15445. users will learn to associate that
  15446. style with a particular type of
  15447. content.
  15448. We look at grouping and
  15449. similarity on pages 469-470.
  15450. The primary aim of any kind of visual design
  15451. is to communicate. Organizing and prioritizing
  15452. information on a page helps users understand
  15453. its importance and what order to read it in.
  15454. Getting your message
  15455. across using design
  15456. PROCESS 466
  15457. Let's look at an example of how
  15458. design can be used to effectively
  15459. communicate the services of a
  15460. company.
  15461. visual hierarchy
  15462. Attention is immediately drawn
  15463. to a picture that shows the
  15464. service this company offers
  15465. and a headline to explain it. The
  15466. size and colored background
  15467. reinforce that this is the primary
  15468. message on the page.
  15469. Should this service appeal to the
  15470. user, below they can see more
  15471. detail about what it does, how
  15472. much it costs, and who uses it.
  15473. Grouping
  15474. There are several chunks of
  15475. information on this page.
  15476. At the top you can see the logo
  15477. and navigation. Under this is the
  15478. information that introduces the
  15479. company's services.
  15480. Further down are three distinct
  15481. groups showing you what the
  15482. services do, the costs involved
  15483. and some of the services' users.
  15484. Similarity
  15485. There are several examples of
  15486. similarity within this page.
  15487. The four points (at the bottom
  15488. left of the screenshot) are all
  15489. presented in a similar manner
  15490. with consistent headings and
  15491. icons.
  15492. All of the links in the body text
  15493. are in blue so it is clear what text
  15494. is clickable.
  15495. 467 PROCESS
  15496. Most web users do not read entire pages. Rather, they skim to find
  15497. information. You can use contrast to create a visual hierarchy that gets
  15498. across your key message and helps users find what they are looking for.
  15499. Visual hierarchy
  15500. Lorem ipsum
  15501. dolor sit amet, consectetur
  15502. adipiscing elit. Lorem
  15503. ipsum dolor sit amet,
  15504. consectetur adipscing elit.
  15505. SIZE
  15506. Larger elements will grab users'
  15507. attention first. For this reason it
  15508. is a good idea to make headings
  15509. and key points relatively large.
  15510. COLOR
  15511. Foreground and background
  15512. color can draw attention to key
  15513. messages. Brighter sections tend
  15514. to draw users' attention first.
  15515. Style
  15516. An element may be the same
  15517. size and color as surrounding
  15518. content but have a different style
  15519. applied to it to make it stand out.
  15520. Lorem ipsum dolor
  15521. sit amet, consectetur
  15522. adipiscing elit.
  15523. Lorem ipsum dolor
  15524. sit amet, consectetur
  15525. adipscing elit.
  15526. Lorem ipsum dolor
  15527. sit amet, consectetur
  15528. adipiscing elit.
  15529. Lorem ipsum dolor
  15530. sit amet, consectetur
  15531. adipscing elit.
  15532. PROCESS 468
  15533. Visual hierarchy refers to the order in which your eyes perceive what
  15534. they see. It is created by adding visual contrast between the items being
  15535. displayed. Items with higher contrast are recognized and processed first.
  15536. Images
  15537. Images create a high visual
  15538. contrast and often attract the
  15539. eye first. They can be used to
  15540. draw attention to a specific
  15541. message within the page. In
  15542. some cases, the right image can
  15543. succinctly reveal more than an
  15544. entire page of text.
  15545. The effect of a well-designed
  15546. visual hierarchy is largely
  15547. subliminal. Achieving a good
  15548. hierarchy requires balance; if
  15549. nothing stands out a site can be
  15550. rather uninteresting, and if too
  15551. many aspects are competing
  15552. for your attention it can be hard
  15553. to find the key messages. This
  15554. example has a clear hierarchy
  15555. which addresses the needs of
  15556. visitors to the site.
  15557. 469 PROCESS
  15558. When making sense of a design, we tend to organize visual elements
  15559. into groups. Grouping related pieces of information together can make a
  15560. design easier to comprehend. Here are some ways this can be achieved.
  15561. grouping and
  15562. Similarity
  15563. Proximity
  15564. When several items are
  15565. placed close together, they are
  15566. perceived as more related than
  15567. items that are placed further
  15568. apart. (You can also nest groups
  15569. of information within larger
  15570. groups of information.)
  15571. Closure
  15572. When faced with a complicated
  15573. arrangement of items, we
  15574. will often look for a single or
  15575. recognisable pattern or form.
  15576. A real or imaginary box can be
  15577. formed around elements due to
  15578. their proximity and alignment.
  15579. Continuance
  15580. When elements are placed in
  15581. a line or a curve then they are
  15582. perceived to be more related
  15583. than those that are not following
  15584. the same direction. This can be
  15585. used to direct a reader from one
  15586. part of a page to the next.
  15587. White Space
  15588. Placing related items closer
  15589. together and leaving a bigger
  15590. gap between unrelated items.
  15591. color
  15592. A background color placed
  15593. behind related items to
  15594. emphasize their connection.
  15595. Borders
  15596. A line can be drawn around the
  15597. border of the group or between it
  15598. and its neighbors.
  15599. PROCESS 470
  15600. We naturally observe similarities in design, and things that are similar are
  15601. perceived to be more related than things that are dissimilar. Repetition
  15602. of similar color, size, orientation, texture, font, or shape, suggests that
  15603. matching elements have similar importance or meaning.
  15604. Consistency
  15605. In this example each book
  15606. review has a consistent style for
  15607. the book titles, author names,
  15608. and purchasing links. Having
  15609. read just one of the blocks it is
  15610. possible to infer the meaning of
  15611. the other items in this box that
  15612. follow the same style.
  15613. Headings
  15614. Giving a chunk of information
  15615. a heading clearly tells the user
  15616. whether or not the content of
  15617. the grouping is relevant to them.
  15618. If not, they can ignore all of the
  15619. elements within it. It also helps
  15620. users of screen readers, as users
  15621. often have the option to hear the
  15622. headings on the page.
  15623. Raw Creation
  15624. John Maizels
  15625. Raw Creation is the definitive book
  15626. on outsider art and provides an
  15627. indispensible guide to the self-taught
  15628. art of this century and a fascinating
  15629. account of human creativity. The
  15630. chapter entitled Wonders of the
  15631. World is mostly dedicated to Nek
  15632. Chand's Rock Garden and includes a
  15633. number of color photographs.
  15634. Buy on Amazon
  15635. Nek Chand Outsider Art
  15636. Lucienne Peiry, Philippe Lespinasse
  15637. This publication tells the story of
  15638. Nek Chand and his life and takes the
  15639. reader on a colorful journey through
  15640. his Rock Garden, the world's most
  15641. expansive work of environmental art.
  15642. Buy on Amazon
  15643. Fantasy Worlds
  15644. Deidi von Schaewen, John Maizels
  15645. Presenting the world's most unusual,
  15646. colorful and poetic creations, some
  15647. of which have never previously
  15648. appeared in print. Fantasy Worlds
  15649. includes the classics of fantasy
  15650. architecture such as the Palais
  15651. Ideal near Lyon and, of course, Nek
  15652. Chand's Rock Garden in Chandigarh,
  15653. India.
  15654. Buy on Amazon
  15655. The Rock Garden
  15656. M.S.Aulakh
  15657. This small black and white book is
  15658. M.S. Aulakh's commentary on and
  15659. tribute to the Rock Garden and is not
  15660. widely available, but used copies can
  15661. be found from time to time.
  15662. Buy on Amazon
  15663. Book Reviews
  15664. Each visual chunk can contain its own hierarchy as shown in this
  15665. example, where the individual books have their own subsections of title,
  15666. author, text and link.
  15667. 471 PROCESS
  15668. Site navigation not only helps people find where they want to go, but also
  15669. helps them understand what your site is about and how it is organized.
  15670. Good navigation tends to follow these principles...
  15671. Designing Navigation
  15672. Concise
  15673. Ideally, the navigation should
  15674. be quick and easy to read. It is
  15675. a good idea to try to limit the
  15676. number of options in a menu to
  15677. no more than eight links. These
  15678. can link to section homepages
  15679. which in turn link to other pages.
  15680. Clear
  15681. Users should be able to predict
  15682. the kind of information that
  15683. they will find on the page
  15684. before clicking on the link.
  15685. Where possible, choose single
  15686. descriptive words for each link
  15687. rather than phrases.
  15688. Selective
  15689. The primary navigation should
  15690. only reflect the sections or
  15691. content of the site. Functions
  15692. like logins and search, and legal
  15693. information like terms and
  15694. conditions and so on are best
  15695. placed elsewhere on the page.
  15696. Home Artist Profiles Exhibitions and Events Galleries Books and Magazines
  15697. About this Website Contact Us Login Register Terms and Conditions Privacy Policy 
  15698. Home Artist Profiles Exhibitions Galleries Publications About Contact ✔
  15699. PROCESS 472
  15700. Context
  15701. Good navigation provides
  15702. context. It lets the user know
  15703. where they are in the website at
  15704. that moment. Using a different
  15705. color or some kind of visual
  15706. marker to indicate the current
  15707. page is a good way to do this.
  15708. Interactive
  15709. Each link should be big enough
  15710. to click on and the appearance
  15711. of the link should change when
  15712. the user hovers over each item
  15713. or clicks on it. It should also
  15714. be visually distinct from other
  15715. content on the page.
  15716. Consistent
  15717. The more pages a site contains,
  15718. the larger the number of
  15719. navigation items there will be.
  15720. Although secondary navigation
  15721. will change from page to page,
  15722. it is best to keep the primary
  15723. navigation exactly the same.
  15724. Home Artist Profiles Exhibitions Galleries Publications About Contact 
  15725. Home Artist Profiles Exhibitions Galleries Publications About Contact ✔
  15726. A large site may have primary,
  15727. secondary and even tertiary
  15728. navigation. Primary navigation
  15729. often appears across the top
  15730. of the site from left to right, or
  15731. down the left hand side of the
  15732. page. Secondary navigation
  15733. could be under the primary
  15734. navigation or down the side of
  15735. the page. Tertiary navigation
  15736. often sits in the footer of the
  15737. page. The menu will not be the
  15738. only way users navigate the site.
  15739. They will also use links within
  15740. each page. Some sites also offer
  15741. a search function.
  15742. Online Extra
  15743. Go to the website accompanying
  15744. this book for information on
  15745. how to implement search
  15746. functionality for your site using
  15747. Google Search.
  15748.  
  15749. Summary
  15750. PROCESS & Design
  15751. X It's important to understand who your target audience
  15752. is, why they would come to your site, what information
  15753. they want to find and when they are likely to return.
  15754. X Site maps allow you to plan the structure of a site.
  15755. X Wireframes allow you to organize the information that
  15756. will need to go on each page.
  15757. X Design is about communication. Visual hierarchy helps
  15758. visitors understand what you are trying to tell them.
  15759. X You can differentiate between pieces of information
  15760. using size, color, and style.
  15761. X You can use grouping and similarity to help simplify
  15762. the information you present.
  15763.  
  15764. X Search engine optimization
  15765. X Using analytics to understand visitors
  15766. X Putting your site on the web
  15767. Practical
  15768. Information
  15769. 19
  15770. 477 PRACTICAL INFORMATION
  15771. To wrap up the book we are going to look
  15772. at some practical information that will
  15773. help you launch a successful site.
  15774. There are entire books written about each of the topics
  15775. covered in this chapter but I will introduce you to the key
  15776. themes that each subject deals with and give you pointers for
  15777. what you need to be considering. You will see:
  15778. ● The basics of search engine optimization
  15779. ● Using analytics to understand how people are using your
  15780. site after it has launched
  15781. ● Putting your site on the web
  15782. PRACTICAL INFORMATION 478
  15783. 479 PRACTICAL INFORMATION
  15784. The Basics
  15785. Search engine optimization (or
  15786. SEO) is the practice of trying
  15787. to help your site appear nearer
  15788. the top of search engine results
  15789. when people look for the topics
  15790. that your website covers.
  15791. At the heart of SEO is the idea of
  15792. working out which terms people
  15793. are likely to enter into a search
  15794. engine to find your site and then
  15795. using these terms in the right
  15796. places on your site to increase
  15797. the chances that search engines
  15798. will show a link to your site in
  15799. their results.
  15800. In order to determine who comes
  15801. first in the search results, search
  15802. engines do not only look at what
  15803. appears on your site. They also
  15804. consider how many sites link
  15805. to you (and how relevant those
  15806. links are). For this reason, SEO
  15807. is often split into two areas:
  15808. on-page techniques and off-page
  15809. techniques.
  15810. On-Page Techniques
  15811. On-page techniques are the
  15812. methods you can use on your
  15813. web pages to improve their
  15814. rating in search engines.
  15815. The main component of this is
  15816. looking at keywords that people
  15817. are likely to enter into a search
  15818. engine if they wanted to find
  15819. your site, and then including
  15820. these in the text and HTML code
  15821. for your site in order to help the
  15822. search engines know that your
  15823. site covers these topics.
  15824. Search engines rely very heavily
  15825. on the text that is in your pages
  15826. so it is important that the terms
  15827. people are going to search for
  15828. are in text. There are seven
  15829. essential places where you want
  15830. your keywords to appear.
  15831. Ensuring that any images have
  15832. appropriate text in the value of
  15833. their alt attribute also helps
  15834. search engines understand the
  15835. content of images.
  15836. Off-Page Techniques
  15837. Getting other sites to link to you
  15838. is just as important as on-page
  15839. techniques. Search engines help
  15840. determine how to rank your
  15841. site by looking at the number of
  15842. other sites that link to yours.
  15843. They are particularly interested
  15844. in sites whose content is related
  15845. to yours. For example, if you
  15846. were running a website that
  15847. sold fish bait, then a link from
  15848. a hairdresser is not likely to be
  15849. considered as relevant as one
  15850. from an angling community.
  15851. Search engines also look at the
  15852. words between the opening
  15853. <a> tag and closing </a> tag
  15854. in the link. If the text in the link
  15855. contains keywords (rather than
  15856. just click here or your website
  15857. address) it may be considered
  15858. more relevant.
  15859. The words that appear in links to
  15860. your site should also appear in
  15861. the text of the page that the site
  15862. links to.
  15863. SEO is a huge topic and several books have been written on the subject.
  15864. The following pages will help you understand the key concepts so you can
  15865. improve your website's visibility on search engines.
  15866. Search Engine
  15867. Optimization (SEO)
  15868. PRACTICAL INFORMATION 480
  15869. In every page of your website there are seven key places where keywords
  15870. (the words people might search on to find your site) can appear in order
  15871. to improve its findability.
  15872. On-Page SEO
  15873. 1: Page Title
  15874. The page title appears at the top
  15875. of the browser window or on the
  15876. tab of a browser. It is specified in
  15877. the <title> element which lives
  15878. inside the <head> element.
  15879. 2: URL / Web Address
  15880. The name of the file is part of
  15881. the URL. Where possible, use
  15882. keywords in the file name.
  15883. 3: Headings
  15884. If the keywords are in a heading
  15885. <hn> element then a search
  15886. engine will know that this page is
  15887. all about that subject and give it
  15888. greater weight than other text.
  15889. 4: Text
  15890. Where possible, it helps to
  15891. repeat the keywords in the main
  15892. body of the text at least 2-3
  15893. times. Do not, however, over-use
  15894. these terms, because the text
  15895. must be easy for a human to
  15896. read.
  15897. 5: Link Text
  15898. Use keywords in the text that
  15899. create links between pages
  15900. (rather than using generic
  15901. expressions such as "click here").
  15902. 6: Image Alt Text
  15903. Search engines rely on you
  15904. providing accurate descriptions
  15905. of images in the alt text. This
  15906. will also help your images show
  15907. up in the results of image-based
  15908. searches.
  15909. 7: Page Descriptions
  15910. The description also lives inside
  15911. the <head> element and is
  15912. specified using a <meta> tag.
  15913. It should be a sentence that
  15914. describes the content of the
  15915. page. (These are not shown in
  15916. the browser window but they
  15917. may be displayed in the results
  15918. pages of search engines.)
  15919. Never try to fool search engines!
  15920. They will penalize you for it. For
  15921. example, never add text in the
  15922. same color as the background of
  15923. the page as they can detect this.
  15924. 6
  15925. 1
  15926. 4
  15927. 5
  15928. 2
  15929. 3
  15930. 481 PRACTICAL INFORMATION
  15931. 1: Brainstorm
  15932. List down the words that
  15933. someone might type into
  15934. Google to find your site. Be sure
  15935. to include the various topics,
  15936. products or services your site is
  15937. about.
  15938. It often helps to ask other people
  15939. what words they would use to
  15940. find your site because people
  15941. less familiar with a topic might
  15942. use different terms than you. (In
  15943. particular, they are less likely to
  15944. use industry-specific jargon.)
  15945. Your list may include some
  15946. keyword phrases (not just
  15947. individual words) if you have
  15948. topics which are described by
  15949. more than one word.
  15950. 2: Organize
  15951. Group the keywords into
  15952. separate lists for the different
  15953. sections or categories of your
  15954. website.
  15955. For example, if your website
  15956. was a pet shop you might have
  15957. different categories for different
  15958. animals (such as dogs, cats and
  15959. rabbits).
  15960. On a large site you may
  15961. break this up further into
  15962. sub-categories (for example,
  15963. separate groups for different pet
  15964. food brands).
  15965. 3: Research
  15966. There are several tools that let
  15967. you enter your keywords and
  15968. then they will suggest additional
  15969. keywords you might like to
  15970. consider, such as:
  15971. adwords.google.co.uk/
  15972. select/KeywordToolExternal
  15973. (When using this tool, select the
  15974. "exact match" option rather than
  15975. "broad match.")
  15976. www.wordtracker.com
  15977. www.keyworddiscovery.com
  15978. Once these tools have suggested
  15979. additional keywords, add the
  15980. relevant options to your lists.
  15981. (Keyword tools will most likely
  15982. suggest some terms that are
  15983. irrelevant so do omit any that do
  15984. not seem appropriate).
  15985. Determining which keywords to use on your site can be one of the
  15986. hardest tasks when you start to think about SEO. Here are six steps that
  15987. will help you identify the right keywords and phrases for your site.
  15988. How to Identify
  15989. Keywords and Phrases
  15990. PRACTICAL INFORMATION 482
  15991. 4: Compare
  15992. It is very unlikely that your
  15993. site will appear at the top of
  15994. the search results for every
  15995. keyword. This is especially true
  15996. for topics where there is a lot
  15997. of competition. The more sites
  15998. out there that have already been
  15999. optimized for a given keyword,
  16000. the harder it will be for you to
  16001. rise up the search results when
  16002. people search on that term.
  16003. Some of the keyword research
  16004. sites can tell you how many
  16005. people have searched for a
  16006. specific keyword to help you
  16007. know how much competition
  16008. those terms have.
  16009. You can also use Google's
  16010. advanced search feature to
  16011. just search the titles of web
  16012. pages. This will help you to
  16013. determine how many sites have
  16014. that keyword in the title of their
  16015. pages. (The more pages with
  16016. the term in the title, the more
  16017. competition there is.)
  16018. 5: Refine
  16019. Now you need to pick which
  16020. keywords you will focus on.
  16021. These should always be the ones
  16022. that are most relevant to each
  16023. section of your site.
  16024. If there is a phrase that is very
  16025. relevant but you find there is a
  16026. lot of competition, you should
  16027. still use it. To improve the
  16028. chances of your site being found
  16029. you can look at whether there
  16030. are other words that could be
  16031. incorporated into a phrase. For
  16032. example, if the information or
  16033. service you offer on your website
  16034. is location specific, then you will
  16035. often find that incorporating
  16036. your location into your keyword
  16037. list will help people find you.
  16038. If your site is promoting a slate
  16039. roofing company in Australia
  16040. then it is better to get 100
  16041. people from Australia who are
  16042. looking for a slate roof than
  16043. 10,000 from the USA who are
  16044. looking for other kinds of rooves.
  16045. 6: Map
  16046. Now that you have a refined list
  16047. of keywords, you know which
  16048. have the most competition, and
  16049. which ones are most relevant,
  16050. it is time to start picking which
  16051. keywords you will use for each
  16052. page.
  16053. Pick 3-5 keywords or phrases
  16054. that map to each page of your
  16055. website and use these as the
  16056. keywords for each page.
  16057. You should not need to repeat
  16058. the same keywords on all of
  16059. the pages. It is also likely that,
  16060. as you move further away from
  16061. the homepage into the sections
  16062. of the site, the keywords will
  16063. become more specific to the
  16064. individual topic dealt with on
  16065. each page.
  16066. 483 PRACTICAL INFORMATION
  16067. Signing Up
  16068. The Google Analytics service
  16069. relies on you signing up for an
  16070. account at:
  16071. www.google.com/analytics
  16072. The site will give you a piece of
  16073. tracking code which you need to
  16074. put on every page of your site.
  16075. How it Works
  16076. Every time someone loads a
  16077. page of your site, the tracking
  16078. code sends data to the Google
  16079. servers where it is stored.
  16080. Google then provides a webbased
  16081. interface that allows you
  16082. to see how visitors use your site.
  16083. The Tracking Code
  16084. A tracking code is provided
  16085. by Google Analytics for each
  16086. website you are tracking. It
  16087. should appear just before the
  16088. closing </head> tag. The code
  16089. does not alter the appearance of
  16090. your web pages.
  16091. As soon as people start coming to your site, you can start analyzing
  16092. how they found it, what they were looking at and at what point they are
  16093. leaving. One of the best tools for doing this is a free service offered by
  16094. Google called Google Analytics.
  16095. Analytics: Learning
  16096. about your Visitors
  16097. At the time of writing, Google
  16098. was updating their Analytics
  16099. interface to Version 5. If you
  16100. log into your account and see a
  16101. different interface, look for a link
  16102. in the top right-hand corner of
  16103. the page that says 'New Version.'
  16104. PRACTICAL INFORMATION 484
  16105. Visits
  16106. This is the number of times
  16107. people have come to your site. If
  16108. someone is inactive on your site
  16109. for 30 minutes and then looks at
  16110. another page on your site, it will
  16111. be counted as a new visit.
  16112. Unique Visits
  16113. This is the total number of
  16114. people who have visited your site
  16115. over the specified period. The
  16116. number of unique visits will be
  16117. lower than the number of visits
  16118. if people have been returning to
  16119. your site more than once in the
  16120. defined period.
  16121. Page Views
  16122. The total number of pages all
  16123. visitors have viewed on your site.
  16124. Pages per Visit
  16125. The average number of pages
  16126. each visitor has looked at on
  16127. your site per visit.
  16128. Average Time on Site
  16129. The average amount of time
  16130. each user has spent on the site
  16131. per visit.
  16132. Date Selector
  16133. Using the date selector in the top
  16134. right hand corner of the site, you
  16135. can change the period of time
  16136. the reports display. When you
  16137. log in, this is usually set to the
  16138. last month, but you can change
  16139. it to report on a specific time
  16140. period.
  16141. Export
  16142. The export link just above the
  16143. title that says "visitors overview"
  16144. allows you to export the
  16145. statistics on this page for other
  16146. applications such as Excel.
  16147. The overview page gives you a snapshot of the key information you are
  16148. likely to want to know. In particular, it tells you how many people are
  16149. coming to your site.
  16150. How Many People Are
  16151. Coming to Your Site?
  16152. 485 PRACTICAL INFORMATION
  16153. The content link on the left-hand side allows
  16154. you to learn more about what the visitors are
  16155. looking at when they come to your site.
  16156. What Are Your Visitors
  16157. Looking At?
  16158. Pages
  16159. This tells you which pages your
  16160. visitors are looking at the most
  16161. and also which pages they are
  16162. spending the most time on.
  16163. Landing Pages
  16164. These are the pages that people
  16165. arrive on when first visiting your
  16166. site. This can be particularly
  16167. helpful because you may find
  16168. people are not always coming
  16169. into your site via the homepage.
  16170. Top Exit Pages
  16171. This shows which pages people
  16172. most commonly leave from. If
  16173. a lot of people are leaving from
  16174. the same page then you might
  16175. consider changing that page or
  16176. improving it.
  16177. Bounce Rate
  16178. This shows the number of people
  16179. who left on the same page that
  16180. they arrived on. A high bounce
  16181. rate suggests that the content is
  16182. not what they were looking for or
  16183. that the page did not sufficiently
  16184. encourage them to look around
  16185. the rest of the site. What counts
  16186. as a bounce:
  16187. ● Clicked a link to another site
  16188. ● Clicked on an advertisement
  16189. ● Entered a new URL
  16190. ● Used the "back" button
  16191. ● Closed the browser
  16192. PRACTICAL INFORMATION 486
  16193. The traffic sources link on the left hand side
  16194. allows you to learn where your visitors are
  16195. coming from.
  16196. Where Are Your
  16197. Visitors Coming From?
  16198. Referrers
  16199. This shows the sites that have
  16200. linked to you and the number
  16201. of people who have come via
  16202. those sites. If a site sends a lot
  16203. of traffic to you, get in touch and
  16204. try to work together to ensure
  16205. that traffic keeps flowing. You
  16206. could also try to find similar
  16207. sites and ask them to link to you.
  16208. Direct
  16209. This shows which page a user
  16210. arrived on if they did not come
  16211. via a link on another site. They
  16212. might have typed the URL into
  16213. their browser, used a browser
  16214. bookmark, or clicked a link in an
  16215. email, PDF, or Word document.
  16216. Search Terms
  16217. This shows the terms users
  16218. entered into a search engine
  16219. to find your site. This can help
  16220. you learn how visitors describe
  16221. what they're looking for (which is
  16222. often different to how someone
  16223. might describe their own site).
  16224. This can help you fine-tune your
  16225. content and your SEO keywords.
  16226. Advanced Features
  16227. We have only scratched the
  16228. surface of what you can find
  16229. out about your visitors from
  16230. Google Analytics. Their help
  16231. files tell you many more of the
  16232. advanced features. If you run
  16233. an online shop, it is well worth
  16234. looking at their e-commerce
  16235. tracking, which adds information
  16236. about products sold, average
  16237. basket size and much more.
  16238. You can also set up goals where
  16239. you specify the paths you want
  16240. people to take, and then see how
  16241. far they get through those paths,
  16242. which is especially useful when
  16243. gathering data from users.
  16244. 487 PRACTICAL INFORMATION
  16245. In order to put your site on the web you will
  16246. need a domain name and web hosting.
  16247. Domain Names
  16248. & Hosting
  16249. DOMAIN NAMES WEB HOSTING
  16250. Your domain name is your web
  16251. address (e.g. google.com or bbc.
  16252. co.uk). There are many websites
  16253. that allow you to register domain
  16254. names. Usually you will have to
  16255. pay an annual fee to keep that
  16256. domain name.
  16257. These sites usually have a form
  16258. that allows you to check whether
  16259. your preferred domain name is
  16260. available, and because millions
  16261. of domain names have already
  16262. been registered, it might take
  16263. you a while to find the one that is
  16264. right for your site.
  16265. A lot of sites that offer domain
  16266. name registration also offer web
  16267. hosting.
  16268. Disk space
  16269. This refers to the total size of all
  16270. of the files that make up your site
  16271. (all of the HTML and CSS files,
  16272. images and scripts).
  16273. Bandwidth
  16274. This is the amount of data the
  16275. hosting company will send to
  16276. your site's visitors. If you imagine
  16277. 10 people looked at every page
  16278. on your site, then it would be
  16279. the equivalent to 10 times the
  16280. amount of disk space you use.
  16281. Backups
  16282. Check whether the hosting
  16283. company performs backups on
  16284. your site (and how often). Some
  16285. only create backups so that
  16286. they can restore your website in
  16287. the event of a server breaking.
  16288. Others allow access to backups
  16289. (which can be helpful if you
  16290. accidentally break the site when
  16291. updating it).
  16292. So that other people can see
  16293. your site, you will need to upload
  16294. it to a web server. Web servers
  16295. are special computers that are
  16296. constantly connected to the
  16297. Internet. They are specially set
  16298. up to serve web pages when
  16299. they are requested.
  16300. With the exception of some very
  16301. large sites, most websites live on
  16302. web servers run by web hosting
  16303. companies. This is usually far
  16304. cheaper and more reliable than
  16305. trying to run your own web
  16306. servers.
  16307. There are lots of different types
  16308. of hosting on offer. We will now
  16309. take a look at some of the key
  16310. things that will help you choose
  16311. which hosting company to use.
  16312. PRACTICAL INFORMATION 488
  16313. Email accounts
  16314. Most hosting companies will
  16315. provide email servers with their
  16316. web hosting packages. You will
  16317. want to check the size of mailbox
  16318. you are allowed and the number
  16319. of mailboxes you can use.
  16320. Server-side
  16321. languages and
  16322. databases
  16323. If you are using a content
  16324. management system, it will likely
  16325. use a server-side programming
  16326. language and a database (such
  16327. as PHP with a MySQL database,
  16328. or ASP.Net with a SQL Server
  16329. database). Be sure to check that
  16330. your hosting company supports
  16331. the technologies your software
  16332. needs to run.
  16333. It is often worth searching for
  16334. reviews of a hosting company
  16335. to see what other people's
  16336. experience has been with a
  16337. hosting company. Unfortunately,
  16338. you often can only tell how good
  16339. a hosting company is when
  16340. something goes wrong, at which
  16341. point you find out how they are
  16342. able to help you (so you can
  16343. expect to see a few negative
  16344. reviews for any company).
  16345. There are a number of online
  16346. services that allow you to point
  16347. your domain name to their
  16348. servers. Blogging platforms such
  16349. as WordPress.com, Tumblr,
  16350. and Posterous, or e-commerce
  16351. platforms such as Big Cartel and
  16352. Shopify provide the servers that
  16353. your site is hosted on. If you are
  16354. using a platform like this you
  16355. will not need your own hosting
  16356. for the website, although you
  16357. often still need hosting for your
  16358. email. If this is the case, some
  16359. web hosting companies offer
  16360. packages that will just offer
  16361. email services.
  16362. Hosted Services
  16363. 489 PRACTICAL INFORMATION
  16364. As the name suggests, File
  16365. Transfer Protocol (or FTP) allows
  16366. you to transfer files across the
  16367. Internet from your computer to
  16368. the web server hosting your site.
  16369. There are many FTP programs
  16370. that offer a simple interface
  16371. that shows you the files on your
  16372. computer alongside the files that
  16373. are on your web server. These
  16374. allow you to drag and drop
  16375. files from your computer to the
  16376. server or vice versa.
  16377. To transfer your code and images from your
  16378. computer to your hosting company, you use
  16379. something known as File Transfer Protocol.
  16380. FTP & Third Party Tools
  16381. PRACTICAL INFORMATION 490
  16382. There are a wide variety of sites that offer
  16383. services commonly created by web developers
  16384. (to save you having to build them yourself).
  16385. Here is a list of some popular
  16386. third party tools:
  16387. Blogs
  16388. wordpress.com
  16389. tumblr.com
  16390. posterous.com
  16391. E-commerce
  16392. shopify.com
  16393. bigcartel.com
  16394. go.magento.com
  16395. Email newsletters
  16396. campaignmonitor.com
  16397. mailchimp.com
  16398. Social networking
  16399. sharing buttons
  16400. addthis.com
  16401. addtoany.com
  16402. Some hosting companies offer
  16403. tools to upload files to their
  16404. servers using a web browser, but
  16405. it is more common to use an FTP
  16406. program as they are faster at
  16407. transmitting files.
  16408. When you purchase your web
  16409. hosting, you will be given FTP
  16410. details that you enter into your
  16411. FTP program in order to connect
  16412. to the server. Usually this will
  16413. be an address (such as ftp://
  16414. mydomain.com), a username,
  16415. and a password. It is important
  16416. to keep this information secure
  16417. in order to prevent strangers
  16418. from gaining access to your
  16419. server.
  16420. Here is a list of some popular
  16421. FTP applications:
  16422. FileZilla
  16423. filezilla-project.org
  16424. Windows, Mac, Linux
  16425. FireFTP
  16426. fireftp.mozdev.org
  16427. Windows, Mac, Linux
  16428. CuteFTP
  16429. cuteftp.com
  16430. Windows, Mac
  16431. SmartFTP
  16432. smartftp.com
  16433. WIndows
  16434. Transmit
  16435. panic.com/transmit
  16436. Mac
  16437.  
  16438. Summary
  16439. PRACTICAL INFORMATION
  16440. X Search engine optimization helps visitors find your
  16441. sites when using search engines.
  16442. X Analytics tools such as Google Analytics allow you to
  16443. see how many people visit your site, how they find it,
  16444. and what they do when they get there.
  16445. X To put your site on the web, you will need to obtain a
  16446. domain name and web hosting.
  16447. X FTP programs allow you to transfer files from your
  16448. local computer to your web server.
  16449. X Many companies provide platforms for blogging, email
  16450. newsletters, e-commerce and other popular website
  16451. tools (to save you writing them from scratch).
  16452.  
  16453. X A-Z
  16454. X HTML & CSS shortcuts
  16455. X Troubleshooting
  16456. Index
  16457. INDEX
  16458. # symbol (links) 87, 88
  16459. _blank 86
  16460. <!-- --> 182
  16461. 3D borders 310
  16462. 3D form buttoms 343
  16463. 12 column grid 387–390
  16464. 960 pixel grid 387–390,
  16465. 391–394, 463
  16466. A
  16467. abbreviations 53
  16468. above the fold 379
  16469. absolute positioning 363, 367
  16470. absolute URLs 79
  16471. accessibility 7
  16472. alt text 99, 272, 480
  16473. contrast 253, 420
  16474. headings 480
  16475. labelling form controls 163
  16476. screen readers 7
  16477. acronyms 53
  16478. adjacent sibling selector 238
  16479. align attribute 103–105
  16480. aligning form controls 345
  16481. aligning images using CSS 411
  16482. aligning text 285
  16483. alpha transparency 256
  16484. alt attribute 99
  16485. alt text 99, 272, 480
  16486. ampersand 194
  16487. analytics 483–486
  16488. angled brackets 23, 24
  16489. animated GIFs 117
  16490. ascender 268, 283
  16491. attributes 25, 26, 38
  16492. attribute names 25, 26
  16493. attribute selectors 292
  16494. attribute values 25, 26
  16495. audio 217–223
  16496. author details 55, 192
  16497. autoplay attribute 214, 219
  16498. B
  16499. background property 344
  16500. background images 413-416
  16501. background colors 138, 250
  16502. background gradients 419
  16503. backups 487
  16504. bandwidth 487
  16505. baseline 268
  16506. bgcolor attribute 138
  16507. blinking text 282
  16508. block elements 102, 185, 317,
  16509. 229, 361
  16510. blueprint css 391
  16511. bold text 45
  16512. <b> 45
  16513. font-weight property 279
  16514. <strong> 51
  16515. borders
  16516. border attribute 138
  16517. border (CSS shorthand) 312
  16518. color 311
  16519. design 469
  16520. images 319
  16521. radius 321
  16522. spacing 340
  16523. style 310
  16524. width 309
  16525. bottom property 366–371
  16526. bounce rate 485
  16527. boxes 300-327
  16528. borders 309-312, 321
  16529. design 469
  16530. box offsets 364, 364–371
  16531. box-shadow property 320
  16532. centering boxes 315
  16533. circles 322
  16534. elliptical shapes 322
  16535. float 370–375
  16536. hiding content 317, 318
  16537. IE6 box model 316
  16538. margin 307, 314
  16539. max-height property 305
  16540. min-height property 305
  16541. overflow property 306
  16542. padding 307, 313
  16543. positioning schemes 367-375
  16544. rounded corners 321
  16545. visibility property 318
  16546. box offsets 364, 364–371
  16547. bottom 366–371
  16548. left 366–371
  16549. right 366–371
  16550. top 366–371
  16551. box-shadow property 320
  16552. brightness 252
  16553. bring to front 369
  16554. browser quirk 242
  16555. bulleted lists 65
  16556. list-style-type property 333
  16557. position of marker 335
  16558. C
  16559. cache control 192
  16560. cap height 268
  16561. capitalize 281
  16562. carriage returns 48
  16563. cascade in CSS 239
  16564. centering boxes 315
  16565. centering images 412
  16566. centering layouts 315
  16567. centering text 285
  16568. changes to content
  16569. <del> 56
  16570. <ins> 56
  16571. <s> 56
  16572. checkboxes (forms) 155
  16573. checked attribute 155, 156
  16574. child folder 84
  16575. child selector 238
  16576. chunking / grouping 465
  16577. circles in CSS 322
  16578. citations 52, 54
  16579. cite attribute 52
  16580. class attribute 184, 431
  16581. class selector 238
  16582. clear property 372
  16583. closing tag 20, 24
  16584. closure 469
  16585. codecs attribute 215
  16586. code editors 29, 31-34, 49
  16587. color 246–261
  16588. background color 250
  16589. bgcolor attribute 138
  16590. border color 311
  16591. brightness 252
  16592. color names 249, 252
  16593. color pickers 251
  16594. color values for CSS 251
  16595. contrast 253, 420
  16596. INDEX
  16597. design 467, 469
  16598. hex codes 249, 252
  16599. hsl / hsla 255–256
  16600. hue 252, 255
  16601. lightness 255
  16602. opacity 254
  16603. rgb values 249, 252
  16604. rgba 254
  16605. saturation 252, 255
  16606. selecting a color 251
  16607. cols attribute 154
  16608. colspan attribute 133
  16609. columns (layout) 375–376
  16610. comments in HTML 182
  16611. comments in CSS 249
  16612. conditional comments 442
  16613. containing elements 362
  16614. content attribute 191–192
  16615. content management system
  16616. (CMS) 33-34
  16617. code view 34
  16618. templates 81
  16619. visual view 34
  16620. continuance 469
  16621. contrast 253, 420
  16622. controls attribute 214, 219
  16623. copyright symbol 194
  16624. cropping images 113–114
  16625. CSS 226–425
  16626. @import rule 395
  16627. !important 239
  16628. attribute selectors 292
  16629. background images 413-419
  16630. borders 309-321
  16631. boxes 300–327
  16632. box offsets 366–371
  16633. bugs and browser quirks 242
  16634. clearing floats 372
  16635. colors 249, 252, 255–256
  16636. CSS1, CSS2, CSS3 (versions)
  16637. 242
  16638. CSS3 8
  16639. declaration 231–232
  16640. frameworks 391
  16641. cursor styles 347
  16642. external style sheets 235
  16643. external vs internal style
  16644. sheets 241
  16645. float 364, 370–375
  16646. float (images) 411
  16647. fonts 271-280
  16648. height 303, 409–410
  16649. hiding content 317-318
  16650. how CSS works 229–232
  16651. how rules cascade 239
  16652. inheritance 239
  16653. internal style sheets 236
  16654. layout 358-405
  16655. links 290-291
  16656. lists 333-336
  16657. margins 314
  16658. multiple style sheets 395
  16659. padding 313, 337
  16660. positioning boxes 363-367
  16661. properties and values 231
  16662. pseudo-classes 289-290
  16663. rules 231–232
  16664. selectors 231–232, 237–238,
  16665. 292
  16666. style attribute 236
  16667. <style> element (for internal
  16668. CSS) 236
  16669. tables 337-340
  16670. text 282–297
  16671. vertical-alignment 286
  16672. what CSS is 6
  16673. what style an element is using
  16674. 348
  16675. width 303, 337, 371, 409-410
  16676. cufon (typefaces) 272
  16677. currency symbols 194
  16678. cursive typefaces 270
  16679. cursor styles 347
  16680. D
  16681. dashed borders 310
  16682. databases 149, 488
  16683. date input 166
  16684. default pages 81, 82
  16685. defining intsance of a term 54
  16686. definition lists 67
  16687. definitions 54
  16688. descendant selector 238
  16689. descender (typefaces) 268, 283
  16690. description attribute 191
  16691. design 452–473
  16692. 960 pixel grid 387–390,
  16693. 391–394, 463
  16694. above the fold 379
  16695. chunking / grouping 465
  16696. columns 387–390
  16697. consistency 470
  16698. fixed-width layouts 381,
  16699. 383–384
  16700. getting your message across
  16701. 465–466
  16702. grouping and similarity
  16703. 469–470
  16704. information hierarchy 465–
  16705. 466
  16706. layout 358-405
  16707. liquid layouts 382, 385–386
  16708. screen sizes and resolution
  16709. 377–378
  16710. site maps 461
  16711. target audience 455
  16712. visitors' motivation 457
  16713. visual hierarchy 465, 467–468
  16714. web page sizes 379–380
  16715. what information visitors need
  16716. 459
  16717. wireframes 463–464
  16718. digital rights management 213
  16719. dimensions of boxes in CSS 303
  16720. directory structure 81-84
  16721. images 98
  16722. direct traffic 486
  16723. diskspace 487
  16724. display property 317
  16725. division symbol 194
  16726. DOCTYPE declarations 181
  16727. domain name 10, 487
  16728. Domain Name System (DNS)
  16729. 9, 10
  16730. dotted borders 310
  16731. drop down list box 157
  16732. drop shadows 288, 320
  16733. INDEX
  16734. E
  16735. e-commerce 33
  16736. editing content
  16737. <del> 56
  16738. <ins> 56
  16739. <s> 56
  16740. editing images 108
  16741. editing pages in a CMS 33
  16742. elements 52
  16743. definition of 20, 24, 38
  16744. diagram of 23, 24
  16745. elliptical shapes 322
  16746. email input 167
  16747. email links 85
  16748. embossed borders 310
  16749. emphasis 51
  16750. empty-cells property 339
  16751. empty elements 48
  16752. ems (for font sizes) 274, 276
  16753. ems (unit of measurement
  16754. boxes) 303
  16755. encoding 209
  16756. entity references 193–194
  16757. equality selector 292
  16758. escape characters/codes
  16759. 193–194
  16760. existence selector 292
  16761. exit pages 485
  16762. expires (meta information) 192
  16763. external style sheets (when to
  16764. use) 241
  16765. F
  16766. fantasy typefaces 270
  16767. file input / upload box 159
  16768. fixed positioning 364, 368
  16769. fixed width layouts 381,
  16770. 383–384
  16771. flash 200–223
  16772. adding a flash movie to your
  16773. page 207–208
  16774. declining usage 204
  16775. flash movies 203
  16776. flash player 203
  16777. flashvars 212, 218
  16778. flash video 211
  16779. how flash works 203
  16780. params 218
  16781. swfobject 207–208, 211, 218
  16782. uses of 204
  16783. flash of unstyled content 278
  16784. float property 364, 370–375
  16785. float property (images) 411
  16786. FLV (video format) 211
  16787. folder structure 81-84
  16788. images 98
  16789. fonts
  16790. choosing a typeface 269
  16791. font sizes 276
  16792. fontsquirrel.com 277
  16793. specifying a font 273
  16794. preferences / font stack 269
  16795. styles / terminology 267–268
  16796. type scales 275
  16797. weights 268
  16798. font-face property 271
  16799. font-family property 271, 273
  16800. font-size property 274, 276
  16801. font-weight property 279
  16802. for attribute 163
  16803. foreground color 249
  16804. forward slash 24, 48, 84
  16805. formatting code 47
  16806. forms 144–173
  16807. how forms work 149–150
  16808. what HTML forms are 145
  16809. where to position labels 163
  16810. why use forms 147
  16811. <button> 162
  16812. <fieldset> 164
  16813. <form> 151
  16814. <input> 155, 159, 160-162, 166
  16815. <label> 163
  16816. <legend> 164
  16817. <option> 157
  16818. <select> 157
  16819. <textarea> element 154
  16820. type attribute 155
  16821. type="checkbox" 156
  16822. type="date" 166
  16823. type="email" 167
  16824. type="file" 159
  16825. type="hidden" 162
  16826. type="image" 161
  16827. type="radio" 155
  16828. type="search" 168
  16829. types of form control 148
  16830. type="submit" 160
  16831. type="text" 152
  16832. type="url" 167
  16833. action attribute 151
  16834. checked attribute 155, 156
  16835. cols attribute 154
  16836. for attribute 163
  16837. id attribute 151, 163
  16838. maxlength attribute 152
  16839. method attribute 151
  16840. multiple attribute 158
  16841. name attribute 152, 155, 156,
  16842. 157, 160
  16843. rows attribute 154
  16844. selected attribute 157
  16845. size attribute 152, 158
  16846. value attribute 155, 156, 157,
  16847. 160
  16848. aligning form controls 345
  16849. changing submit button on
  16850. hover 343
  16851. form validation 165
  16852. get method 151
  16853. grouping form elements 164
  16854. hidden form controls 162
  16855. hover styles 342
  16856. image buttons 161
  16857. name/value pairs 150
  16858. placeholder text 168
  16859. rounded corners on text inputs
  16860. 342
  16861. styling with CSS 341–346
  16862. submit button 160
  16863. form validation 165
  16864. frameborder attribute 190
  16865. FTP 489–490
  16866. full screen layouts 382
  16867. G
  16868. general sibling selector 238
  16869. GIF 111
  16870. animated GIFs 117
  16871. GIMP 108
  16872. global attributes 183
  16873. INDEX
  16874. Google analytics 483–486
  16875. Google maps 189
  16876. Google web fonts 277
  16877. gradients 419
  16878. greater than symbol 194
  16879. grids 387–390, 463
  16880. grouping and similarity 469,
  16881. 469–470
  16882. grouping / chunking 465
  16883. grouping elements (<div>) 187
  16884. grouping inline elements
  16885. (<span>) 188
  16886. H
  16887. hCard 55
  16888. headings 22, 43
  16889. <hgroup> 438
  16890. height attribute 100, 214
  16891. height property 303
  16892. height property (images)
  16893. 409–410
  16894. height iframe 189
  16895. hex codes 249, 252
  16896. hidden form controls 162
  16897. hiding content 317, 318
  16898. home pages 81, 82
  16899. horizontal rules 48
  16900. hosted video 210
  16901. href 77, 79, 88, 235
  16902. hsl / hsla 255–256
  16903. HTML
  16904. what is HTML? 6
  16905. HTML 4 179
  16906. HTML5, 179
  16907. DOCTYPE declaration 181
  16908. differences from XHTML 179
  16909. HTML5 179
  16910. Comparison with HTML 4 179
  16911. <a> (HTML5 block level links)
  16912. 441
  16913. <article> 432-439
  16914. <aside> 436
  16915. <audio> 217–220
  16916. <figcaption> 119, 422, 439
  16917. <figure> 119, 422, 439
  16918. <footer> 432
  16919. <header> 432, 433
  16920. <hgroup> 438
  16921. <nav> 432, 434
  16922. <section> 433, 437
  16923. <source> 215, 220
  16924. <video> 213–216
  16925. autoplay attribute 219
  16926. controls attribute 219
  16927. loop attribute 219
  16928. preload attribute 219
  16929. scrolling attribute 190
  16930. seamless attribute 190
  16931. src attribute (audio) 219
  16932. date input 166
  16933. email input 167
  16934. search input 168
  16935. URL input 167
  16936. form validation 165
  16937. placeholder text 168
  16938. helping older browser
  16939. understand 442
  16940. HTML5 shiv / shim 442
  16941. layout 428–449
  16942. HTML5 layout 428–449
  16943. HTTP
  16944. get method 151
  16945. post method 151, 159
  16946. HTTP headers 151
  16947. Secure Sockets Layer (SSL)
  16948. 153
  16949. http-equiv attribute 192
  16950. hue 252, 255
  16951. I
  16952. id attribute 87, 88, 151, 163, 183
  16953. id attribute (layout) 431
  16954. id selector 238
  16955. IE6 box model 316
  16956. image button 161
  16957. image resolution 115
  16958. images 95–120
  16959. <img> 99, 100
  16960. <figcaption> 439
  16961. <figure> 119, 439
  16962. src attribute 99
  16963. alt text 99, 480
  16964. aligning images 103–105, 412
  16965. aligning images with CSS 411
  16966. background-images 413-416
  16967. (gradients) 419
  16968. indenting text 287
  16969. border-images 319
  16970. bullet points 334
  16971. choosing images and stock
  16972. photography 97
  16973. copyright 97
  16974. cursors 347
  16975. dimensions 100, 107, 113–114
  16976. in CSS 409–410
  16977. editing images 108, 113–114,
  16978. 116, 117
  16979. image formats 107
  16980. animated GIFs 117
  16981. bitmap 115
  16982. GIF 111, 115, 118
  16983. JPEG 109–110, 115
  16984. PNG 112, 115, 118
  16985. SVG 116
  16986. transparent GIF/PNGs 118
  16987. vector formats 116
  16988. resolution 107, 115
  16989. orientation (landscape/
  16990. portrait) 114
  16991. position in surrounding text
  16992. 101
  16993. preparing for the web 107
  16994. rollovers 417
  16995. sprites 417
  16996. titles 99
  16997. indenting code 47
  16998. indenting text 287
  16999. index.html 81, 82
  17000. information hierarchy 465–466
  17001. inheritance (CSS) 239
  17002. inline elements 102, 186, 229,
  17003. 317, 361
  17004. Internet Service Provider (ISP)
  17005. 10
  17006. IP address 10
  17007. italic text 45
  17008. <em> 51
  17009. font-style property 280
  17010. <i> 45
  17011. INDEX
  17012. J
  17013. JavaScript 208, 212, 218
  17014. JPEG 109, 109–112
  17015. justify 285
  17016. K
  17017. kerning 284
  17018. keywords 191, 479–482
  17019. L
  17020. labelling form controls 163
  17021. landing pages 485
  17022. lang attribute 25
  17023. layer order 369
  17024. layout 358–405
  17025. 960 pixel grid 387–390, 391
  17026. absolute positioning 363
  17027. box offsets 364
  17028. centering boxes 315
  17029. columns 371–376, 387–390
  17030. design 452–473
  17031. <div> 431, 440
  17032. fixed positioning 364
  17033. fixed width layouts 381,
  17034. 383–384
  17035. float 364
  17036. grids 387–397
  17037. helping older browsers
  17038. understand HTML5 442
  17039. liquid layouts 382, 385–386
  17040. normal flow 363, 365
  17041. positioning schemes
  17042. absolute positioning 367
  17043. fixed positioning 368
  17044. floats
  17045. clearing floats 372
  17046. normal flow 365
  17047. relative positioning 366
  17048. position property 365
  17049. sidebars 436
  17050. page sizes 379–380
  17051. z-index property 364
  17052. leading 283
  17053. left property 366–371
  17054. less than symbol 194
  17055. letter-spacing property 284
  17056. lightness 255
  17057. like buttons 490
  17058. line breaks 48
  17059. line-height property 283
  17060. line items (lists) 65, 66
  17061. links 75
  17062. <a> 77, 79
  17063. href attribute 77
  17064. :active 291
  17065. :focus 291
  17066. :hover 291
  17067. :link 290
  17068. :visited 290
  17069. add / remove underline 282
  17070. link opens in new window 86
  17071. link to a part of a page 87
  17072. link to an email address 85
  17073. link to other sites 79
  17074. link to the same site 80
  17075. link to top of page 87
  17076. link text 78, 479, 480
  17077. # symbol 87, 88
  17078. liquid layout 382, 385–386
  17079. min and max width 304
  17080. lists
  17081. definition lists 67
  17082. nested lists 68
  17083. ordered lists 65
  17084. unordered lists 66
  17085. <ol> 65
  17086. <ul> 66
  17087. <li> 65
  17088. <dd> 67
  17089. <dl> 67
  17090. <dt> 67
  17091. bullet or number styles 333-
  17092. 336
  17093. gaps between list items 334
  17094. displaying items side by side
  17095. 317
  17096. using images for bullet points
  17097. 334
  17098. list-style-image property 334
  17099. list-style property 336
  17100. list-style-type property 333
  17101. loop attribute 214, 219
  17102. lowercase 281
  17103. M
  17104. mailto: 85
  17105. margin:auto 315
  17106. margin property 314
  17107. margin-top property 314
  17108. margin-right property 314
  17109. margin-bottom property 314
  17110. margin-left property 314
  17111. markers in lists 333
  17112. markup (definition) 41
  17113. mathematical symbols 194
  17114. max-height property 305
  17115. max-length attribute 152, 153
  17116. max-width property 304
  17117. meta descriptions 480
  17118. meta information 191–192
  17119. method attribute 151
  17120. min-height property 305
  17121. min-width property 304
  17122. mobile devices 377
  17123. monospace typefaces 267–270
  17124. multiple attribute 158
  17125. multiple browsers (testing) 242
  17126. multiple columns 375–376
  17127. multiple languages 25
  17128. multiple style sheets 395
  17129. music 217–220
  17130. mp3 player 218
  17131. N
  17132. name attribute 152, 153, 155,
  17133. 156, 157, 160, 191
  17134. names for attributes 25, 26
  17135. navigation
  17136. <a> 77, 79
  17137. <a> (HTML5 block-level links)
  17138. 441
  17139. designing navigation 471–472
  17140. <nav> 432, 434
  17141. using lists for navigation 317
  17142. nested elements 362
  17143. nested lists 68
  17144. new window 86
  17145. nofollow (stop search engines
  17146. indexing) 191
  17147. normal flow 363, 365
  17148. INDEX
  17149. notepad 29-30
  17150. notepad++ 29
  17151. O
  17152. oblique text 280
  17153. Ogg Vorbis (audio format) 220
  17154. opacity 254
  17155. opening tag 20, 23
  17156. open source fonts 277
  17157. ordered lists 65
  17158. overflow property 306
  17159. overlapping content 306
  17160. overlapping elements
  17161. z-index property 369
  17162. overline 282
  17163. P
  17164. padding property 313
  17165. padding-top property 313
  17166. padding-right property 313
  17167. padding-bottom property 313
  17168. padding-left property 313
  17169. padding property (tables) 337
  17170. page sizes 379–380
  17171. page titles 27, 28, 480
  17172. page views 484
  17173. paragraphs 44
  17174. parent elements 362
  17175. parent folder 84
  17176. password input (forms) 153
  17177. PC (creating pages on) 29
  17178. percentages (font sizes) 274,
  17179. 276
  17180. percentages (boxes) 303
  17181. Photoshop 108, 117
  17182. PHP 149, 488
  17183. pixels (images / resolution) 115
  17184. pixels (unit of measurement)
  17185. 274, 276, 303
  17186. placeholder attribute 168
  17187. PNG 112
  17188. transparent PNGs 118
  17189. positioning schemes 363
  17190. normal flow 363, 365
  17191. relative positioning 363, 366
  17192. absolute positioning 363, 367
  17193. fixed positioning 364, 368
  17194. float 364, 370–375
  17195. position property 365, 366, 367
  17196. poster attribute 214
  17197. post method 151, 159
  17198. pragma (meta information) 192
  17199. prefix selector 292
  17200. preload attribute 214, 219
  17201. process (design process)
  17202. 452–473
  17203. properties (see CSS Properties)
  17204. proximity 469
  17205. pseudo-classes 289
  17206. :active 291
  17207. :focus 291
  17208. :hover 291
  17209. :link 290
  17210. :visited 290
  17211. pseudo elements
  17212. :first-line 289
  17213. :first-letter 289
  17214. Q
  17215. quotations
  17216. <blockquote> 52
  17217. cite attribute 52
  17218. <q> 52
  17219. quote marks 194
  17220. quotes
  17221. quote marks 194
  17222. R
  17223. radio buttons (forms) 155
  17224. referrers 486
  17225. relative positioning 363, 366
  17226. relative URLs 80, 83
  17227. rel attribute (CSS) 235
  17228. resizing images 113–114
  17229. resolution (images) 107
  17230. resolution and screen sizes
  17231. 377–378
  17232. rgb values 249, 252
  17233. rgba 254
  17234. right property 366–371
  17235. robots (meta information) 191
  17236. rollover buttons 343
  17237. rollover images 417
  17238. root folder 82
  17239. rounded corners 321
  17240. rounded corners on form
  17241. elements 342
  17242. rows attribute 154
  17243. rowspan attribute 134
  17244. S
  17245. sans-serif typefaces 267–270
  17246. saturation 252, 255
  17247. Scalable Vector Graphics (SVG)
  17248. 180
  17249. screen readers
  17250. what screen readers do 7
  17251. alt text 272
  17252. alt text for images 99
  17253. interpreting semantic markup
  17254. 50
  17255. link text 78
  17256. screen sizes and resolution
  17257. 377–378
  17258. scrolling attribute 190
  17259. scroll value (overflow property)
  17260. 306
  17261. seamless attribute 190
  17262. Search Engine Optimization
  17263. (SEO) 479–482
  17264. alt text 480
  17265. Google keyword tool 481
  17266. headings 480
  17267. keywords 479–482
  17268. link text 78, 479, 480
  17269. meta keywords 191
  17270. meta descriptions 480
  17271. off-page techniques 479
  17272. on-page techniques 479–480
  17273. page names / URLs 480
  17274. page titles 480
  17275. preventing pages being
  17276. indexed 191
  17277. search terms 486
  17278. secure sockets layer (SSL) 153
  17279. select box 157-158
  17280. selected attribute 157
  17281. selectors (CSS) 237, 292
  17282. semantic markup 41, 50
  17283. INDEX
  17284. send to back 369
  17285. serif typefaces 267, 267–270
  17286. shading alternate table rows
  17287. 338
  17288. sifr (typefaces) 272
  17289. site maps 461-462
  17290. size attribute 152, 153, 158
  17291. size of boxes in CSS 303
  17292. social networking buttons 490
  17293. space selector 292
  17294. sprites 417
  17295. src attribute 99, 189
  17296. src attribute (audio) 219, 220
  17297. src attribute (video) 214, 215
  17298. stacking context 369
  17299. strikethrough 56, 282
  17300. structural markup 41
  17301. structure
  17302. how documents use structure
  17303. 15
  17304. how HTML describes structure
  17305. 20, 21
  17306. using word processors 17
  17307. style attribute 236
  17308. submit button 160
  17309. styling buttons with CSS 343
  17310. subscript 46
  17311. substring selector 292
  17312. suffix selector 292
  17313. superscript 46
  17314. SVG 116, 278
  17315. swfobject 207–208, 211, 218
  17316. T
  17317. tables 126–141
  17318. <table> 131
  17319. <tbody> 135
  17320. <td> 131
  17321. <tfoot> 135
  17322. <thead> 135
  17323. <th> 132
  17324. <tr> 131
  17325. bgcolor attribute 138
  17326. border attribute 138
  17327. colspan attribute 133
  17328. padding property (tables) 337
  17329. rowspan attribute 134
  17330. width attribute 137
  17331. styling tables in CSS 337–340
  17332. border-collapse property 340
  17333. border-spacing property 340
  17334. empty-cells property 339
  17335. adding/removing gaps
  17336. between cells 340
  17337. highlighting table rows 337
  17338. shading alternate rows 338
  17339. what is a table 130
  17340. why use tables 127
  17341. tags 20-24, 38
  17342. target attribute 86
  17343. target audience 455
  17344. templates (in a CMS) 33, 34, 81
  17345. text
  17346. :active pseudo-class 291
  17347. :focus pseudo-class 291
  17348. :hover pseudo-class 291
  17349. :first-letter pseudo element
  17350. 289
  17351. :first-line pseudo element 289
  17352. @font-face 277
  17353. aligning text 285-286
  17354. blinking text 282
  17355. choosing a typeface 269
  17356. drop shadows 288
  17357. formats 278
  17358. font stack 269
  17359. indenting 287
  17360. kerning/letter-spacing 284
  17361. leading/line-height 283
  17362. open source fonts 277
  17363. specifying a font 273
  17364. size 274
  17365. typefaces 267–270
  17366. type scales 275
  17367. underline 282
  17368. uppercase/lowercase 281
  17369. underline 282
  17370. weight 268, 279
  17371. word-spacing 284
  17372. text-align property 285
  17373. text color 249
  17374. text-decoration property 282
  17375. textedit 31-32
  17376. text editors 29, 31
  17377. text in CSS 264–297
  17378. text-indent property 287
  17379. text-shadow property 288
  17380. text-transform property 281
  17381. textwrangler 31
  17382. title attribute 53, 99
  17383. tools
  17384. 960 pixel grid 387
  17385. blogs 490
  17386. CSS frameworks 391
  17387. e-commerce 490
  17388. email newsletters 490
  17389. Google analytics 483–486
  17390. Google keyword tool 481
  17391. HTML5 shiv / shim 442
  17392. social networking buttons 490
  17393. web developer toolbar 348
  17394. top of page links 87
  17395. top property 366–371
  17396. tracking visitors 483
  17397. trademark symbol 194
  17398. transparency (images) 118
  17399. transparecny 256
  17400. type attribute 152, 153, 155, 159,
  17401. 236
  17402. type attribute (audio) 220
  17403. type attribute (CSS) 235-236
  17404. type attribute (video) 215
  17405. typefaces 267–272
  17406. typekit.com 277
  17407. type scales 275
  17408. type selector 238
  17409. U
  17410. underline 56, 282
  17411. Uniform Resource Locators
  17412. (URLs) 82
  17413. absolute URLs 79
  17414. relative URLs 80
  17415. directory structure 81
  17416. universal selector 238
  17417. unordered lists 66
  17418. uploading web pages 489–490
  17419. uppercase 281
  17420. URLs
  17421. Search Engine Optimization
  17422. (SEO) 480
  17423. URL input 167
  17424. INDEX
  17425. V
  17426. value attribute 155, 156, 157, 160
  17427. values for attributes 25, 26
  17428. vector images 116
  17429. vertical-align property 286
  17430. vertical alignment of images
  17431. 105–106
  17432. vertical margins 308
  17433. video 200–223
  17434. <video> 209
  17435. hosted services or self-hosting
  17436. 210
  17437. digital rights management 213
  17438. encoding 209
  17439. flash video (FLV) 211
  17440. formats 213–216
  17441. AVI, Flash Video, h264,
  17442. MPEG, Ogg theora,
  17443. QuickTime, WebM,
  17444. Windows Media 209
  17445. players and plugins 209
  17446. src attribute 214
  17447. view source 35, 162, 317, 318
  17448. Vimeo 210
  17449. visibility property 318
  17450. visitors
  17451. referrers 486
  17452. tracking 483
  17453. visitors / visits / unique visits
  17454. 484
  17455. visual editors in a CMS 34, 49
  17456. visual hierarchy 465, 467,
  17457. 467–468
  17458. W
  17459. wallpaper (images) 414
  17460. watermark (images) 414
  17461. web browsers 7
  17462. testing in multiple browsers
  17463. 242
  17464. view source 35
  17465. web developer toolbar 348
  17466. web hosting 7, 9, 487
  17467. email accounts 488
  17468. web page layout 358–405
  17469. web pages
  17470. exit pages 485
  17471. landing pages 485
  17472. referrers 486
  17473. uploading to a web server
  17474. 489–490
  17475. web page sizes 379–380
  17476. web servers 7, 9, 10, 81, 84
  17477. white space 308, 469
  17478. margin and padding 307
  17479. padding property 313
  17480. margin property 314
  17481. gaps between list items 334
  17482. white space collapsing 47, 308
  17483. white space handling in HTML
  17484. 47
  17485. width attribute 100, 137, 189,
  17486. 214
  17487. width property 303
  17488. width property (floating
  17489. elements) 371
  17490. width property (images)
  17491. 409–410
  17492. width property (tables) 337
  17493. wireframes 463–464
  17494. word-spacing property 284
  17495. X
  17496. x height 268
  17497. XHTML 179
  17498. differences from HTML 179
  17499. DOCTYPE declaration 181
  17500. Strict/Transitional XHTML
  17501. 180
  17502. XML 180
  17503. XML declaration 181
  17504. Y
  17505. YouTube 210
  17506. Z
  17507. z axis 369
  17508. z-index property 364, 369
  17509. INDEX
  17510. STARTING OUT
  17511. The browser shows the markup
  17512. typed in (not the result page).
  17513. Check the file extension is .html
  17514. and not .txt. p 30, 32
  17515. Bold text, italics, headings, or
  17516. link text are extending longer
  17517. than expected.
  17518. Check you have closed the
  17519. relevant tag e.g. </a>. p 21, 22
  17520. The page I linked to is not found.
  17521. Check the relative URL. p 83, 84
  17522. IMAGES
  17523. Images are not showing up.
  17524. Check the relative URL. p 83, 84
  17525. Images are looking blurry.
  17526. Check that you have saved your
  17527. images in the right format and at
  17528. the size you want to show them
  17529. at. p 109-113
  17530. Border images are not showing.
  17531. This only works with latest
  17532. browsers. (Also, check the
  17533. relative URL). p 319, 21, 22
  17534. GIFs that were resized now look
  17535. grainy or have jagged edges.
  17536. Check the color space in your
  17537. image editing program. It should
  17538. be RGB (not indexed color).
  17539. TEXT
  17540. Some text flashes up before
  17541. showing the correct font.
  17542. You have a Flash Of Unstyled
  17543. Content. p 278
  17544. When copying text from word
  17545. processors, lots of extra tags are
  17546. added to the markup.
  17547. Copy the text into a plain text
  17548. editor (to remove formatting)
  17549. then paste it into your HTML
  17550. editor. p 49
  17551. The text looks bigger/smaller on
  17552. some screens.
  17553. This is usually due to variances
  17554. in screen resolutions. Also,
  17555. check the type scale is set for the
  17556. <body> element. p 377, 276
  17557. The font size is wrong in IE when
  17558. I use ems.
  17559. See above. p 276
  17560. The font I specified is not
  17561. showing in some browsers.
  17562. The computer must have that
  17563. font installed. p 269-272
  17564. If you are use @font-face it must
  17565. be in several formats. p 341
  17566. My fonts look jagged on a PC.
  17567. Some fonts to do not anti-alias
  17568. as well as others on a PC. Try a
  17569. different typeface or try a thicker
  17570. version. p 272
  17571. GENERAL CSS
  17572. A specified style is not showing.
  17573. Remember CSS selectors are
  17574. case sensitive.
  17575. Check that your selectors are
  17576. correct. p 238
  17577. The web developer toolbar can
  17578. help you find the right selector.
  17579. p 348
  17580. If the selectors are correct, do
  17581. you have another selector that
  17582. applies to the same element
  17583. later in the CSS? p 239, 240
  17584. CSS varies in some browsers.
  17585. There are a number of CSS
  17586. bugs/browser quirks that mean
  17587. they render the page slightly
  17588. differently - try searching for the
  17589. problem and see if it is a known
  17590. CSS bug/quirk. p 242
  17591. HTML 5
  17592. The browser is not applying
  17593. styles to HTML5 elements.
  17594. If it is IE, you might need to use
  17595. the HTML5 shiv / shim. p442
  17596. Block-level elements are
  17597. rendering as inline elements.
  17598. Use display:block to tell the
  17599. browser which HTML5 elements
  17600. are block-level elements. p 442
  17601. Here are a few problems that beginners commonly face, along with the
  17602. pages where you can find solutions to them.
  17603. TroubleShooting
  17604. INDEX
  17605. LAYOUT
  17606. The design looks bigger/smaller
  17607. on some screens.
  17608. The resolution of a monitor
  17609. affects how big the items appear
  17610. on the page. p 377, 378
  17611. Margins above and below a box
  17612. not showing.
  17613. Vertical margins collapse. p 308
  17614. My content does not fit in the
  17615. containing box/browser window.
  17616. You can deal with this using the
  17617. overflow property. p 306, 316
  17618. Boxes look a different size in IE.
  17619. Some versions of IE use a
  17620. different box model than all
  17621. other browsers. Use a DOCTYPE
  17622. declaration to make old versions
  17623. of IE behave like other browsers.
  17624. p 316
  17625. Boxes do not appear centered
  17626. when using auto for left and
  17627. right margins.
  17628. You may need to use the
  17629. text-align property on the
  17630. containing element. p 315
  17631. Elements are overlapping.
  17632. When you take elements out of
  17633. normal flow, they can overlap.
  17634. z-index helps you control which
  17635. item goes on top. p 369
  17636. Why is the vertical-align
  17637. property not vertically centering
  17638. my block-level element?
  17639. This property is not designed for
  17640. this purpose. It is used to center
  17641. inline elements on the page.
  17642. You will find several ways to
  17643. vertically center block-level
  17644. elements (depending on their
  17645. context) if you search on Google.
  17646. A background image is not
  17647. showing on my box.
  17648. Does the box you are applying
  17649. the style to to have a defined
  17650. height and width? p 303
  17651. Does the containing box have an
  17652. overflow property set to auto?
  17653. p 373, 374
  17654. My background images do not
  17655. show when the page is printed.
  17656. Most browsers do not print
  17657. background images by default to
  17658. help save ink. You can adjust this
  17659. in your print preferences.
  17660. There is a gap between the
  17661. browser window and my
  17662. content.
  17663. You may need to set margin and
  17664. padding on the <body> element
  17665. to 0. p 313, 314
  17666. FLOAT IN LAYOUT
  17667. A box is not sitting next to
  17668. another floated element.
  17669. Ensure that there is enough
  17670. space in the containing element
  17671. for the two to sit side by side.
  17672. p 303
  17673. Margins and padding are added
  17674. to the width of the box (except
  17675. for older versions of IE, which
  17676. have a different box model).
  17677. Therefore, the box might be
  17678. wider than specified in the width
  17679. property. p 316
  17680. Did you specify a width for the
  17681. floated element? (See next
  17682. point.)
  17683. My floated element takes up the
  17684. full width of the browser window
  17685. (or containing box).
  17686. Check that you have specified
  17687. a width for the floated element.
  17688. p 371
  17689. The container around my floated
  17690. elements are one pixel tall.
  17691. The containing element doesn't
  17692. know the height of the floated
  17693. elements inside it. You can
  17694. either add an element that acts
  17695. as a clearing box or use the
  17696. overflow property with a value
  17697. set to auto. p 373
  17698. IE added an extra margin to my
  17699. floated elements.
  17700. Set the display property to
  17701. inline.
  17702. If you've come across a problem
  17703. that you think belongs in this
  17704. troubleshooting section, please
  17705. feel welcome to email it to us at:
  17706. hello@htmlandcssbook.com.
  17707. We will endeavor to address
  17708. the most common problems
  17709. our readers have faced in future
  17710. editions of this book. Thank you!
  17711. INDEX
  17712. <a> 77, 79, 85, 441
  17713. <abbr> 53
  17714. <acronym> 53
  17715. <address> 55
  17716. <article> 432-439
  17717. <aside> 436
  17718. <audio> 217–220, 219
  17719. <b> 45
  17720. <blockquote> 52
  17721. <body> 22, 27
  17722. <br /> 48
  17723. <button> 162
  17724. <cite> 54
  17725. <dd> 67
  17726. <del> 56
  17727. <dfn> 54
  17728. <div> 187, 431, 440
  17729. <dl> 67
  17730. <dt> 67
  17731. <em> 51
  17732. <embed> 203
  17733. <fieldset> 164
  17734. <figcaption> 119, 422, 439
  17735. <figure> 119, 422, 439
  17736. <footer> 432, 433
  17737. <form> 151
  17738. <h1> 22, 43
  17739. <h2> 22, 43
  17740. <h3> 43
  17741. <h4> 43
  17742. <h5> 43
  17743. <h6> 43
  17744. <head> 27
  17745. <header> 432, 433
  17746. <hgroup> 438
  17747. <hr /> 48
  17748. <html> 22
  17749. <i> 45
  17750. <iframe> 189–190
  17751. <img> 99, 100
  17752. <input> 152, 155, 159- 162, 166
  17753. <ins> 56
  17754. <label> 163
  17755. <legend> 164
  17756. <li> 65, 66
  17757. <link> 235, 396
  17758. <meta> 191, 192
  17759. <nav> 432, 434
  17760. <object> 203
  17761. <ol> 65
  17762. <option> 157
  17763. <p> 22, 44
  17764. <q> 52
  17765. <s> 56
  17766. <script> 208, 218
  17767. <section> 433, 437
  17768. <select> 157
  17769. <source> 215, 220
  17770. <span> 188
  17771. <strong> 51
  17772. <style> 236
  17773. <sub> 46
  17774. <sup> 46
  17775. <table> 131
  17776. <tbody> 135
  17777. <td> 131
  17778. <textarea> 154
  17779. <tfoot> 135
  17780. <th> 132
  17781. <thead> 135
  17782. <title> 27, 28
  17783. <tr> 131
  17784. <u> 56
  17785. <ul> 66
  17786. <video> 209, 213–216
  17787. HTML Elements
  17788. INDEX
  17789. action 151
  17790. align 103–105
  17791. alt 99
  17792. autoplay 214, 219
  17793. bgcolor 138
  17794. border 138
  17795. checked 155, 156
  17796. cite 52
  17797. class 184, 431
  17798. codecs 215
  17799. cols 154
  17800. colspan 133
  17801. content 191, 192
  17802. controls 214, 219
  17803. description 191
  17804. for 163
  17805. frameborder 190
  17806. global attributes 183
  17807. height 100, 189, 214
  17808. href 77, 79, 88, 235
  17809. http-equiv 192
  17810. id 87, 88, 151, 163
  17811. id attribute 183, 431
  17812. loop 214, 219
  17813. maxlength 152, 153
  17814. method 151
  17815. multiple 158
  17816. name 152-157, 160, 191
  17817. placeholder 168
  17818. poster 214
  17819. preload 214, 219
  17820. rel 235
  17821. robots 191
  17822. rows 154
  17823. rowspan 134
  17824. scrolling 190
  17825. seamless 190
  17826. selected 157
  17827. size 152, 153, 158
  17828. src 99, 189, 214, 215, 219, 220
  17829. style 236
  17830. target 86
  17831. title 53, 99
  17832. type 152, 155, 159
  17833. type (audio/video) 220, 215
  17834. type (CSS) 235-236
  17835. type="date" 166
  17836. type="email" 167
  17837. type="hidden" 162
  17838. type="image" 161
  17839. type="password" 153
  17840. type="search" 168
  17841. type="submit" 160
  17842. type="url" 167
  17843. value 155-157, 160
  17844. width 100, 137, 189, 214
  17845. HTML Attributes
  17846. INDEX
  17847. background-attachment
  17848. property 414
  17849. background-color 250
  17850. background-image property 413
  17851. background-image property
  17852. (gradients) 419
  17853. background-position property
  17854. 415
  17855. background property 416
  17856. background-repeat property
  17857. 414
  17858. border-bottom-color 311
  17859. border-bottom-style 310
  17860. border-collapse property 340
  17861. border-color 311
  17862. border-image property 319
  17863. border-left-color 311
  17864. border-left-style 310
  17865. border property 312
  17866. border-radius property 321
  17867. border-right-color 311
  17868. border-right-style 310
  17869. border-spacing property 340
  17870. border-style 310
  17871. border-top-color 311
  17872. border-top-style 310
  17873. bottom property 366–371
  17874. box-shadow property 320
  17875. clear property 372
  17876. color 249
  17877. cursor property 347
  17878. display property 317
  17879. empty-cells property 339
  17880. float property 364, 370–375
  17881. float property (images) 411
  17882. @font-face 277
  17883. font-face 271
  17884. font-family 271, 273
  17885. font-size 274, 276
  17886. font-style property 280
  17887. height (images) 409–410
  17888. hsl / hsla 255–256
  17889. left property 366–371
  17890. letter-spacing 284
  17891. line-height 283
  17892. list-style-image property 334
  17893. list-style-position property 335
  17894. list-style property 336
  17895. list-style-type property 333
  17896. margin-bottom property 314
  17897. margin-left property 314
  17898. margin property 314
  17899. margin-right property 314
  17900. margin-top property 314
  17901. opacity 254
  17902. padding-bottom property 313
  17903. padding-left property 313
  17904. padding property 313
  17905. padding property (tables) 337
  17906. padding-right property 313
  17907. padding-top property 313
  17908. position property 366, 367
  17909. rgba 254
  17910. right property 366–371
  17911. text-align 285
  17912. text-decoration 282
  17913. text-indent 287
  17914. text-shadow 288
  17915. text-transform 281
  17916. top property 366–371
  17917. vertical-align 286
  17918. visibility property 318
  17919. width (images) 409–410
  17920. width property (floating
  17921. elements) 371
  17922. width property (tables) 337
  17923. word-spacing 284
  17924. z-index property 364, 369
  17925. CSS Properties
  17926. :active 291
  17927. :first-letter 289
  17928. :first-line 289
  17929. :focus 291, 342
  17930. :hover 291, 343, 342
  17931. highlighting table rows 337
  17932. :link 290
  17933. :visited 290
  17934. @font-face 277
  17935. @import rule 395
  17936. !important 239
  17937. Pseudo-Classes, Elements & Rules
Add Comment
Please, Sign In to add comment