Book HomeCascading Style Sheets: The Definitive GuideSearch this book Sunday 14th of February 2016 04:37:52 AM

Chapter 8. Visual Formatting

Contents:

Basic Boxes
Block-Level Elements
Floated Elements
Inline Elements
Summary

In the previous chapter, we covered a great deal of information on how CSS handles the visual formatting of a document. However, we did this in a mostly practical fashion: lots of explanation about how things work, with only a little lip service paid to the questions of why. In this chapter, we turn to the theoretical side of visual rendering, with only occasional references to the practical.

You may wonder why it's necessary to spend an entire chapter on the theoretical underpinnings of visual rendering in CSS. The main reason is to cover all the bases. I attempted to provide as many and varied examples as possible in the previous chapters, but with a model as open and powerful as that contained within CSS, no book could hope to cover every possible way of combining properties and effects. Every reader of this book will obviously go on to discover new ways of using CSS for their own document effects.

In the course of so doing, you may encounter what seems like strange behavior on the part of user agents. With a thorough grasp of how the visual rendering model works in CSS, you'll be able to determine whether the behavior is a correct (if unexpected) consequence of the rendering engine CSS defines or whether you've stumbled across a bug that needs to be reported. (See Appendix A, "CSS Resources", for details on how to report problems with rendering engines.)

8.1. Basic Boxes

Then there is the question of what happens to elements that flow pasta floated element but have visible backgrounds. Let's take thepreceding example and change it so that the secondH3 element has a visible background and border, ashas been done in Figure 7-69.

Figure 7-69

Figure 7-69. More floating images and element backgrounds

Yes, the figure is correct: the content of the H3flows past the image, and the background "slides under"the image, so to speak. This is, in its way, no different than the

In the rendering of elements, CSS assumes that every element generates one or more rectangular boxes, called element boxes . (Future versions of the specification may allow for nonrectangular boxes, but for now everything is rectangular.) Each element box consists of a content area at its core. This content area is surrounded by optional amounts of padding, borders, and margins. These are considered optional because all could be set to a width of zero, effectively removing them from the element box. An example content area is shown in Figure 8-1, along with the surrounding regions of padding, border, and margins.

Figure 8-1

Figure 8-1. The content area and its surroundings

Each of the margins, borders, and padding can be set using various properties, such as margin-left or border-bottom. The content's background (for example, a color or tiled image) is also applied to the padding, while the margins are always transparent, allowing the background of any parent elements to be visible. In effect, the margins simulate the HSPACE and VSPACE attributes of images, although in a much more sophisticated fashion. Padding cannot be set to a negative value, but margins can. The effects of negative margins are explored later in this chapter.

The borders, on the other hand, have their own rules. Borders are generated using defined styles, such as solid or inset, and their color can be set using the border-color property. If no color is set, then the color of the border is based on the foreground color of the element's content. For example, if the text of a paragraph is white, then any borders around that paragraph will be white, unless a different border color is explicitly declared by the author. If a border style has "gaps" of some type, then the element's background is visible through those gaps; in other words, the border has the same background as the content and padding. Finally, the width of a border can never be negative.

There are differences in how different types of elements are formatted, however. Block-level elements are not treated in the same way that inline elements are, for example, and floated elements introduce a whole new level of complexity. Let's examine each type of element in turn.



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.

Let's assume we have a table of links like this one:

<TABLE BORDER CELLPADDING="4">
<TR>
<TD><A HREF="home.html">Home Page</A></TD>
<TD><A HREF="read.html">My Writing</A></TD>
<TD><A HREF="fun.html">Fun Stuff!</A></TD>
<TD><A HREF="links.html">Other Links</A></TD>
<TD><A HREF="write.html">Contact Me</A></TD>
</TR>"should" -- this is not a guarantee. It generally
seems to work, however.

Web-safe colors are those colors that are expressed in multiples of the RGB values 20% and 51, and the corresponding hex-pair value 33. Also, 0% or 0 is a safe value. So, if you use RGB percentages, then make all three values either 0% or a number divisible by 20; for example, rgb(40%,100%,80%) or tags can list multiple fonts in order of preference.  The list should include a generic font family as a last resort, e.g.
   <FONT FACE="Creepy, Times New Roman, serif">
Generic font families include serif, sans-serif, monospace, cursive and fantasy

Note that as of HTML 4, you are encouraged to use style sheets instead of these in-line font manipulations, but these tags work fine. 
  There are many different types of software that you can write in Java to make use of XML. I have created 3 major categories to describe certain types of apps (that are currently popular) that are really well suited to the use of XML. This is by no means a comprehensive set of categories; you can create your own, and many more major categories will emerge as XML becomes more popular.

Client side - Graphical Java Applications

The simplest category of XML Java applications is the kind of Java application that stores information in XML documents (files). This is illustrated in Figure 1. By using XML to create your own markup languages (i.e. your own file formats for your information) in an open way, you don't have to use propietary and binary file formats. Using XML over proprietary binary file formats, allows your applications to have immense inter operability across platforms, applications and even programming languages. Since any kind of markup language can be defined using XML (you can even formalize it by creating a DTD for it) applications can store their information using their own markup languages. For example, address book information can be stored in an AddressBookML file. A few commercial programs currently available allow saving their application data to XML files, e.g., Framemaker can save its documents as XML files.