Beginning CSS: Cascading Style Sheets for Web Design

Overview

Completely updated material and new examples show you what CSS can do

With the latest versions of Firefox, Safari, Internet Explorer, and other browsers released, CSS is more essential than ever. This beginner guide demonstrates how cascading style sheets can be used to define styles to items in Web pages, rather than format each item individually. Each lesson in this full-color book has been methodically revised to be more concise and ...

See more details below
Paperback
$28.21
BN.com price
(Save 29%)$39.99 List Price

Pick Up In Store

Reserve and pick up in 60 minutes at your local store

Other sellers (Paperback)
  • All (32) from $3.80   
  • New (15) from $3.80   
  • Used (17) from $5.10   

Overview

Completely updated material and new examples show you what CSS can do

With the latest versions of Firefox, Safari, Internet Explorer, and other browsers released, CSS is more essential than ever. This beginner guide demonstrates how cascading style sheets can be used to define styles to items in Web pages, rather than format each item individually. Each lesson in this full-color book has been methodically revised to be more concise and efficient, making your learning experience as productive as possible.

  • Covers the latest in CSS, including the new features of Internet Explorer, Firefox, Safari, and Google Chrome
  • Reviews the vast improvements to mobile browsers and how CSS can work with them
  • Provides helpful examples and walks you through real-world solutions to common hurdles
  • Discusses embedded fonts, compatibility tables, and cross-browser bug scenarios

Beginning CSS, Third Edition gets you completely up to date so that you can start using CSS in the newest Web and mobile browsers today!

Read More Show Less

Product Details

  • ISBN-13: 9780470891520
  • Publisher: Wiley
  • Publication date: 6/28/2011
  • Edition number: 3
  • Pages: 464
  • Sales rank: 1,374,371
  • Product dimensions: 7.30 (w) x 9.10 (h) x 1.00 (d)

Meet the Author

Ian Pouncey is a web developer living in London, England, and working for the BBC. He has been working on the web for over 11 years, producing web sites from small sites for local businesses to the latest version of the Yahoo! home page. He is a member of the W3C Web Accessibility Initiative Education and Outreach Working Group and a web accessibility advocate.

Richard York is a web developer at Westlake Design, a web design and development firm, and an active contributing member of the PHP community. In addition to writing previous editions of Beginning CSS: Cascading Style Sheets for Web Design, he is also the author of Beginning JavaScript and CSS Development with jQuery.

Read More Show Less

Read an Excerpt

Beginning CSS

Cascading Style Sheets for Web Design
By Ian Pouncey Richard York

John Wiley & Sons

Copyright © 2011 John Wiley & Sons, Ltd
All right reserved.

ISBN: 978-0-470-89152-0


Chapter One

Introducing Cascading Style Sheets

WHAT YOU WILL LEARN IN THIS CHAPTER:

* What CSS is * The history of CSS * How to create a CSS enhanced HTML document

Cascading Style Sheets (CSS) is a language designed for describing the appearance of documents written in a markup language such as HTML. With CSS you can control the color of text, the style of fonts, the spacing between paragraphs, how columns are sized and laid out, what background images or colors are used, and a variety of other visual effects. One of the major benefits is that the same CSS can be used by more than one page, meaning that the style of an entire website can be adjusted without having to change each page individually.

The most common use for CSS is to style web pages, and in combination with HTML or XHTML (which is used to describe content) and JavaScript (which is used to add interactivity to a site), CSS is a very powerful tool.

The history of how CSS came to be isn't actually all that relevant to CSS authors of today, so you can skip the next bit if you're in a hurry. If, like me, you're interested in the nitty-gritty, read on.

In the early days of the Web, nine different proposals were made to the World Wide Web Consortium, the main standards organization for the Web which is more commonly known as the W3C, for a style sheet language to help separate the visual appearance of a document from its content. In 1994, Cascading HTML Style Sheets was proposed by Hkon Wium Lie, now CTO of Opera Software (a company you'll meet again later in this chapter), but at the time he was working at CERN with Tim Berners-Lee and Robert Cailliau, the two men who invented the World Wide Web. CHSS became CSS because CSS can be applied to more than just HTML, and in December 1996 the CSS level 1 Recommendation was published.

Since then, three more CSS specifications have been published by the W3C. CSS 2 became a recommendation in 1998, with CSS 2.1 (which fixes a few mistakes in 2), and CSS 3 currently existing as candidate recommendations.

Although CSS 3 is still under development, CSS 2.1 is likely to become a fully fledged recommendation in the near future and is well supported by all modern browsers. In this book, you will cover CSS 2.1 as it stands today and take a look at some of the new features in CSS 3 that you can use in browsers today.

In the rest of this chapter, you will learn the advantages of using CSS and then get started with your first Cascading Style Sheet.

ADVANTAGES OF USING CSS

By using CSS for the presentation of a document, you can substantially reduce the amount of time you spend composing not only a single document but an entire website As you'll discover, CSS is much more versatile than the styling mechanisms provided by HTML alone. The versatility of CSS, when harnessed effectively, can reduce the amount of hard disk space that a website occupies, as well as the amount of bandwidth required to transmit that website from the server to the browser. CSS has the following advantages:

* The presentation of an entire website can be centralized to one or a handful of documents, enabling the look and feel of a website to be updated at a moment's notice. In legacy HTML documents, the presentation is contained entirely in the body of each document. CSS brings a much needed feature to HTML: the separation of a document's structure from its presentation. CSS can be written independently of HTML. * Browsers are beginning to support multiple alternative style sheets, a feature that allows more than one design of a website to be presented at the same time. The user can simply select the look and feel that he or she likes most. This could only be done previously with the aid of more complex programming languages. * Style sheets allow content to be optimized for more than one type of device. By using the same HTML document, different versions of a website can be presented for handheld devices such as PDAs and cell phones or for printing. * Style sheets download much more quickly because web documents using CSS commonly consume less bandwidth. Browsers also use a feature called caching, a process by which your browser will download a CSS file or other web document only once, and not request that file from the web server again unless it's been updated, further providing your website with the potential for lightning-fast performance. * Users of a website can compose style sheets of their own, a feature that makes websites more accessible. For example, a user can compose a high-contrast style sheet that makes content easier to read. Many browsers provide controls for this feature for novice users, but it is CSS nonetheless.

These features, along with the power of the cascade, which you will read about in Chapter 4, makes the planning, production, and maintenance of a website simpler with Cascading Style Sheets than with HTML alone. By using CSS to present your web documents, you can cut days of development and planning time.

HOW TO WRITE CSS

To write CSS, just as is the case when writing HTML source, you will need a text editor. Word processing programs such as Microsoft Word aren't ideally suited for CSS, because they automatically do lots of things that are helpful when writing a letter or book, such as correct spelling but get in the way when writing code.

Instead, you want something that doesn't make any changes that you don't want to what you type but lets you write and save plain text.

The Windows Notepad program is one example of a text editor that is ideal for composing source code. To launch Notepad, choose Start Run and then type Notepad in the Open textbox.

On Mac OS X, the Notepad equivalent is TextEdit, which can be found in the Mac OS X Applications folder.

There are more advanced text editors that will do useful things such as color your code so that it is clear which parts do what (this is known as syntax highlighting) or automatically complete code for you when you've started typing.

Editors available for Windows include:

* Notepad++: http://sourceforge.net/projects/notepad-plus/ (free) * Crimson Editor: www.crimsoneditor.com (free) * HTML-kit: www.chami.com/html-kit (free)

And here are some alternative text editors that work with Mac OS X:

* TextWrangler: www.barebones.com (free) * TextMate: http://macromates.com/ (retail with 30 day free trial) * You can find more text editors suitable for CSS and HTML at http://en.wikipedia.org/ wiki/List_of_HTML_editors

In addition, there is the very popular Adobe Dreamweaver (www.adobe.com/products/dreamweaver), which combines a text editor with a WYSIWYG (or What You See Is What You Get) code generator, which lets you use a graphical interface to create web pages in HTML and CSS. To follow along with the code in this book, you must use the code view of Dreamweaver or similar application rather than the WYSIWYG view.

You must create HTML files with the .html extension. If you use Notepad or TextEdit, beware of your files being saved with a .txt extension, which will not result in a web browser interpreting your file as ordinary text rather than HTML.

To ensure that your files are saved properly on Windows, choose Start Run and type Explorer (or right-click Start and choose Explore from the pop-up menu) to open Windows Explorer. After Windows Explorer is open, choose Tools Folder Options to open the Folder Options window, click the View tab, and uncheck the Hide Extensions for Known File Types box. Then click OK.

On Mac OS X, open Finder, and go to Finder Preferences. Select the Advanced tab, and check the box for Show All File Extensions.

YOUR FIRST CSS-ENABLED DOCUMENT

The following example is designed to introduce you to what CSS is capable of. It will help you get your feet wet and get straight down to the business of writing style sheets.

NOTE You can find the images and source code for the following example at www.wrox.com. While for this example you should obtain the source code from www.wrox.com, I recommend that for most chapters you type the example so that you can get used to writing the syntax and take in the different bits that come together in each example.

TRY IT OUT Create a Web Page with HTML and CSS

Example 1-1

To write your first CSS-enabled document, follow these steps.

1. In your text editor of choice, enter the following markup:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link rel="stylesheet" type="text/css" href="[PHRASE NOT REPRODUCIBLE IN ASCII]">

The gas giants

Jupiter

Jupiter is the fifth planet from the Sun and the largest planet within the Solar System. The Romans named the planet after the god Jupiter. It is a gas giant with a mass two and a half times the mass of all the other planets in our Solar System combined.

78,412,020 km      71,492 km      1,425,500,000,000,000 km3      1,898,700,000,000,000,000,000,000,000 kg     
Jupiter Facts
Distance from the Sun Equatorial Radius Volume Mass

More Jupiter facts

Saturn

Saturn is the sixth planet from the Sun and the second largest planet in the Solar System, after Jupiter. Saturn is named after the Roman god Saturn, equated to the Greek Cronus (the Titan father of Zeus), the Babylonian Ninurta, and the Hindu Shani.

1,426,725,400 km      60,268 km      827,130,000,000,000 km3      568,510,000,000,000,000,000,000,000 kg     
Saturn Facts
Distance from the Sun Equatorial Radius Volume Mass

More Saturn facts

Uranus

Uranus is the seventh planet from the Sun, and the third-largest and fourth most massive planet in the Solar System. It is named after the ancient Greek deity of the sky Uranus the father of Cronus and grandfather of Zeus.

78,412,020 km      25,559 km      69,142,000,000,000 km3      86,849,000,000,000,000,000,000,000 kg     
Uranus Facts
Distance from the Sun Equatorial Radius Volume Mass

More Uranus facts

Neptune

Neptune is the eighth and farthest planet from the Sun in our Solar System. Named for the Roman god of the sea, it is the fourth-largest planet by diameter and the third-largest by mass.

4,498,252,900 km      24,764 km      62,526,000,000,000 km3      102,440,000,000,000,000,000,000,000 kg     
Neptune Facts
Distance from the Sun Equatorial Radius Volume Mass

More Neptune facts

2. Save the preceding file in a new folder of its own as example_1-1.html.

3. Open example_1-1.html in your browser. You will see a page that looks something like the image in Figure 1-1.

4. Create a new, blank document in your text editor, and enter the following CSS:

body { width: 650px; margin: 0 auto; background: #000; color: #FFF; font: 12px sans-serif; }

h1 { font-size: 24px; }

h2 { font-size: 18px; margin-top: 0; }

a { color: #FFF; }

a:focus, a:hover { text-decoration: none; }

table { margin-bottom: 10px; border-spacing: 0; }

caption { margin-bottom: 10px; font-size: 14px; font-weight: bold; text-align: left; }

th, td { padding: 0 10px 0 0; text-align: left; }

.planet { margin: 10px 0; padding: 20px 20px 20px 200px; border: 1px solid #FFF; background-position: 20px 20px; background-repeat: no-repeat; }

.jupiter { background-image: url(jupiter.jpg); }

.saturn { background-image: url(saturn.jpg); }

.uranus { background-image: url(uranus.jpg); }

.neptune { background-image: url(neptune.jpg); }

5. Save the preceding CSS in the same folder where you saved example_1-1.html, as [PHRASE NOT REPRODUCIBLE IN ASCII].

This code results in the image shown in Figure 1-2, when loaded into Safari on Mac OS X.

To see how example_1-1.html looks in other browsers, you can load it up by going to the File menu of the browser you'd like to view it in, selecting Open or Open File, and locating example_1-1.html on your hard disk.

How It Works

Example 1-1 is an introduction to a little of what CSS is capable of. This example is designed to get your hands dirty up front with CSS, as a preview of what you can expect throughout the rest of the book. With each new chapter, I introduce and explain the nuts and bolts that come together to make examples like the preceding one. In Figure 1-2, you see that CSS can be used to specify background images and other aesthetic aspects of an HTML document. I continue to revisit and explain the CSS that resulted in Figure 1-2 throughout the book.

If you are feeling adventurous, play around with the CSS used here — try changing some of the values to see what happens. Don't worry if things break, that's all part of learning.

Some times you might find that CSS requires some workarounds specifically to get older versions of Internet Explorer to display content in the same way as Safari, Firefox, Chrome, and Opera. Throughout this book, you also learn the hacks and workarounds that you need to make CSS-enabled web pages compatible with IE 6.

(Continues...)



Excerpted from Beginning CSS by Ian Pouncey Richard York Copyright © 2011 by John Wiley & Sons, Ltd. Excerpted by permission of John Wiley & Sons. All rights reserved. No part of this excerpt may be reproduced or reprinted without permission in writing from the publisher.
Excerpts are provided by Dial-A-Book Inc. solely for the personal use of visitors to this web site.

Read More Show Less

Table of Contents

INTRODUCTION.

PART I: THE BASICS.

CHAPTER 1: INTRODUCING CASCADING STYLE SHEETS.

CHAPTER 2: THE BITS THAT MAKE UP A STYLE SHEET.

CHAPTER 3: SELECTORS.

CHAPTER 4: THE CASCADE AND INHERITANCE.

PART II: PROPERTIES.

CHAPTER 5: APPLYING FONT FACES.

CHAPTER 6: MANIPULATING THE DISPLAY OF TEXT.

CHAPTER 7: BACKGROUND COLORS AND IMAGES.

CHAPTER 8: THE BOX MODEL: CONTROLLING MARGINS, BORDERS, PADDING, WIDTH, AND HEIGHT.

CHAPTER 9: FLOATING AND VERTICAL ALIGNMENT.

CHAPTER 10: STYLING LISTS.

CHAPTER 11: POSITIONING.

CHAPTER 12: STYLING TABLES.

CHAPTER 13: CREATE A COMPLETE LAYOUT.

PART III: ADVANCED CSS AND ALTERNATIVE MEDIA.

CHAPTER 14: ADVANCED SELECTORS.

CHAPTER 15: STYLING FOR PRINT.

CHAPTER 16: CUSTOMIZING THE MOUSE CURSOR.

CHAPTER 17: CONTROLLING OPACITY AND VISIBILITY.

CHAPTER 18: STYLING CONTENT FOR MOBILE DEVICES.

CHAPTER 19: CLOSING COMMENTS.

APPENDIX A: ANSWERS TO EXERCISES.

APPENDIX B: ADDITIONAL CSS RESOURCES.

APPENDIX C: CSS REFERENCE.

APPENDIX D: CSS COLORS.

INDEX.

Read More Show Less

Customer Reviews

Be the first to write a review
( 0 )
Rating Distribution

5 Star

(0)

4 Star

(0)

3 Star

(0)

2 Star

(0)

1 Star

(0)

Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation

Reminder:

  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

 
Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously
Sort by: Showing 1 Customer Reviews
  • Posted August 12, 2012

    CSS for the Beginner

    This is one of the better books I have come across on basic CSS. As a beginner's book, it is best I have found. It is simple, easy to read and full of examples. The book is a little repetitive, but as it is aimed at the beginner, one would expect that.
    I always find books that have lots of code examples much easier to read when they use color syntax as this book does.
    Although the book comes in at about 400 pages, most of the space is taken up with code examples and illustrations. Being familiar with CSS, I find myself just looking at the code examples, which are enough to remind me of the style's properties and how to use them.
    Unfortunately the book doesn't cover CSS3, although that's a whole book to itself. Still Wrox normally produces easy to read and understand books. This is no exception, as a beginner's book on CSS this would be the one I would choose.

    Was this review helpful? Yes  No   Report this review
Sort by: Showing 1 Customer Reviews

If you find inappropriate content, please report it to Barnes & Noble
Why is this product inappropriate?
Comments (optional)