Sams Teach Yourself JavaScript in 24 Hours Free Open Book

Sams Teach Yourself JavaScript in 24 Hours

Previous Page
Next Page

Using CSS Properties

CSS supports a wide variety of properties, such as color and text-align, in the previous example. The following sections list some of the most useful CSS properties for aligning text, changing colors, working with fonts, and setting margins and borders.

Did you Know?

This is only an introduction to CSS, and there are many properties beyond those listed here. For more details about CSS, consult one of the web resources or books listed in Appendix A, "Other JavaScript Resources."


Aligning Text

One of the most useful features of style sheets is the capability to change the spacing and alignment of text. Most of these features aren't available using standard HTML. You can use the following properties to change the alignment and spacing of text:

  • letter-spacing Specifies the spacing between letters.

  • text-decoration Enables you to create lines over, under, or through the text, or to choose blinking text. The value can be none (default), underline, overline, line-through, or blink. Blinking text is, thankfully, unsupported by most browsers.

  • vertical-align Enables you to move the element up or down to align with other elements on the same line. The value can be baseline, sub, super, top, text-top, middle, text-bottom, and bottom.

  • text-align Specifies the justification of text. This can be left, right, center, or justify.

  • text-transform Changes the capitalization of text. capitalize makes the first letter of each word uppercase; uppercase makes all letters uppercase; and lowercase makes all letters lowercase.

  • text-indent Enables you to specify the amount of indentation for paragraphs and other elements.

  • line-height Enables you to specify the distance between the top of one line of text and the top of the next.

Changing Colors and Background Images

You can also use style sheets to gain more control over the colors and background images used on your web page. CSS includes the following properties for this purpose:

  • color Specifies the color of the text within an element. This is useful for emphasizing text or for using a specific color scheme for the document. You can specify a named color (for example, red) or red, green, and blue values to define a specific color (for example, #0522A5).

  • background-color Specifies the background color of an element. By setting this value, you can make paragraphs, table cells, and other elements with unique background colors. As with color, you can specify a color name or numeric color.

  • background-image Specifies the URL for an image to be used as the background for the element. This is specified with the keyword url and a URL in parentheses, as in url(/back.gif).

  • background-repeat Specifies whether the background image is repeated (tiled). The image can be repeated horizontally, vertically, or both.

  • background-attachment Controls whether the background image scrolls when you scroll through the document. fixed means that the background image stays still while the document scrolls; scroll means the image scrolls with the document (like background images on normal web documents).

  • background-position Enables you to offset the position of the background image.

  • background Provides a quick way to set all of the background elements in this list. You can specify all of the attributes in a single background rule.

Did you Know?

The basic list of colors supported by most browsers for the color and background-color properties includes aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, orange, purple, red, silver, teal, white, and yellow.


Working with Fonts

Style sheets also enable you to control the fonts used on the web document and how they are displayed. You can use the following properties to control fonts:

  • font-family Specifies the name of a font, such as arial or helvetica, to use with the element. Because not all users have the same fonts installed, you can list several fonts. The CSS specification also supports several generic font families that are guaranteed to be available: serif, sans-serif, cursive, fantasy, and monospace.

  • font-style Specifies the style of a font, such as normal, italic, or oblique.

  • font-variant This value is normal for normal text, and small-caps to display lowercase letters as small capitals.

  • font-weight Enables you to specify the weight of text: normal or bold. You can also specify a numeric font weight for a specific amount of boldness.

  • font-size The point size of the font.

  • font This is a quick way to set all the font properties in this list. You can list all the values in a single font rule.

Margins and Borders

Last but not least, you can use style sheets to control the general layout of the page. The following properties affect margins, borders, and the width and height of elements on the web page:

  • margin-top, margin-bottom, margin-left, margin-right Specify the margins of the element. You can specify the margins as an exact number or as a percentage of the page's width.

  • margin Allows you to specify a single value for all four of the margins.

  • width Specifies the width of an element, such as an image.

  • height Specifies the height of an element.

  • float Enables the text to flow around an element. This is particularly useful with images or tables.

  • clear Specifies that the text should stop flowing around a floating image.

Did you Know?

Along with these features, CSS style sheets enable you to create sections of the document that can be positioned independently. This feature is described in Hour 13, "Using the W3C DOM."


Units for Style Sheets

Style sheet properties support a wide variety of units, or types of values you can specify. Most properties that accept a numeric value support the following types of units:

  • px Pixels (for example, 15px). Pixels are the smallest addressable units on a computer screen or other device. In some devices with non-typical resolutions (for example, handheld computers) the browser might rescale this value to fit the device.

  • pt Points (for example, 10pt). Points are a standard unit for font size. The size of text of a specified point size varies depending on the monitor resolution. Points are equal to 1/72 of an inch.

  • ex Approximate height of the letter x in the current font (for example, 1.2ex).

  • em Approximate width of the letter m in the current font (for example, 1.5em). This is usually equal to the font-size property for the current element.

  • % Percentage of the containing object's value (for example, 150%).

Which unit you choose to use is generally a matter of convenience. Point sizes are commonly used for fonts, pixel units for the size and position of layers or other objects, and so on.

Previous Page
Next Page
Index: [SYMBOL][A][B][C][D][E][F][G][H][I][J][K][L][M][N][O][P][Q][R][S][T][U][V][W][X][Y]


     Main Menu
Sams Teach Yourself JavaScript in 24 Hours
Table of Contents
Copyright
About the Author
Acknowledgments
Part I: Introducing the Concept of Web scripting and the JavaScript Language
Part II: Learning JavaScript Basics
Part III: Learning More About the DOM
Hour 9. Responding to Events
Hour 10. Using Windows and Frames
Hour 11. Getting Data with Forms
Hour 12. Working with Style Sheets
Style and Substance
Defining and Using CSS Styles
Using CSS Properties
Creating a Simple Style Sheet
Using External Style Sheets
Controlling Styles with JavaScript
Summary
Q&A
Quiz Questions
Quiz Answers
Exercises
Hour 13. Using the W3C DOM
Hour 14. Using Advanced DOM Features
Part IV: Working with Advanced JavaScript Features
Part V: Building Multimedia Applications with JavaScript
Part VI: Creating Complex Scripts
Part VII: Appendixes
Index


More Books
PHP Hacks
Processing Xml With Java - A Guide To Sax, Dom, Jdom, Jaxp, And Trax
The Koran (Holy Qur'an)
Macromedia Flash 8 Bible
Search Engine Optimization for Dummies
YouTube Traffic
PHP 5 for Dummies
Harry Potter and The Chamber of Secrets
Harry Potter and the Sorcerer's Stone
The Pilgrim's Progress
Wireless Hacks
Flash Hacks. 100 Industrial-Strength Tips & Tools
PayPal Hacks. 100 Industrial-Strength Tips and Tools
Amazon Hacks
Pdf Hacks
The Da Vinci Code
Google Hacks
The Holy Bible
Windows XP For Dummies
Harry Potter and the Half-Blood Prince
Seo Book
Upgrading and Repairing Networks
Macromedia Dreamweaver 8 UNLEASHED
Windows XP Annoyances
Windows XP Hacks
Microsoft Windows XP Power Toolkit
Teach Yourself MS Office In 24Hours
iPod & iTunes Missing Manual
PC Hacks 100 Industrial-Strength Tips and Tools
PC Overclocking, Optimization, and Tuning - 2th Edition
PC Hardware In A Nutshell 3rd Edition
PC Hardware in a Nutshell, 2nd Edition
Upgrading and Repairing PCs
Google for Dummies
MySQL Cookbook
Teach Yourself Macromedia Flash 8 In 24 Hours
PHP CookBook
Sams Teach Yourself JavaScript in 24 Hours
PHP5 Manual
Free Games Paper Airplanes
500 Juegos Gratis 500 Giochi Gratis 500 Jeux Gratuits 500 Jogos Gratis 500 Kostenlose Spiele