Book HomeCascading Style Sheets: The Definitive GuideSearch this book Saturday 20th of December 2014 09:49:03 PM

Chapter 10. CSS2: A Look Ahead

Contents:

Changes from CSS1
CSS2 Selectors
Fonts and Text
Generated Content
Adapting to the Environment
Borders
Tables
Media Types and @-rules
Summary

In the course of writing this book, I vacillated back and forth over how to handle CSS2. It's a full W3C Recommendation, of course, but so little of it has actually been implemented correctly that it seemed almost a waste of time -- both mine and yours -- to talk about CSS2 in detail. After all, not only would I have to fake all of the screenshots (not to mention guess at correct behavior in a few cases), but you wouldn't be able to try out anything I discussed, since browsers wouldn't recognize your CSS2 rules.

On the other hand, CSS2 can hardly be ignored. So in the end, I settled on writing a chapter that talks about CSS2 in brief, abstract detail -- in other words, this chapter. The next edition of this book will almost certainly be driven by the need to add detailed information concerning CSS2, and will very likely be undertaken once the dust settles and browsers start to correctly implement major portions of CSS2.

Also realize that, of the figures shown in this chapter, the vast majority are -- well -- faked. There was no other way to produce most of these examples. The point of telling you this is to spare you the frustration of trying to figure out how they were produced. So, with that in mind, here's a brief taste of what CSS2 can offer.

10.1. Changes from CSS1

Only a few CSS1 properties have gained new values. These were mostly concerned with addressing issues that did not exist, or were not considered, when CSS1 was written. The one standout is a new value called inherit, which represents a huge change to everything -- but more on that in a moment.

10.1.1. Additions and Changes to the display Property

The property display has received quite a few new values in CSS2. Now, in addition to block, inline,

App server developers are not restricted to using HTTP, they can transmit and recieve XML information using simple remote CORBA objects and RMI objects. The key is that by using XML, it makes these remote services or objects easier to build. And, by sticking with XML, any one of these technologies can be used in your design of your app server. You can use whatever technology is most appropriate to getting the job done, knowing that all the information flows as XML and can be processed by any part of the system. The reason Java object serialization did not achieve this is because it encodes object data to a binary format that is dependent on too many things (like the JVM version, and the existence of classes when things are deserialized, etc). XML is not limited by any of these restrictions (or problems), which makes it much easier to create systems that allow XML information to flow between different subsystems. Also by relying only on the data, large portions of the system can be replaced with better or different implementations for future-readiness.

App servers traditionally give their client apps access to information in remote databases, remote file systems, remote object repositories, remote web resources, and even other app servers. All these information sources don't even need to reside on the machine that hosts the app server. These remote resources may be on other machines on the Intranet or the Internet. Using Java and XML, RMI, JDBC, CORBA, JNDI, Servlet and Swing, you can create app servers that can integrate all kinds of remote and local information resources, and client apps that allow you to remotely or locally access this information from the app server.

In the future, with publicly available DTDs that are standardized for each vertical industry, XML based app servers will become very popular. Also when XML schema repositories become available and widely used, app servers will be able to take on a new role and provide application services that are not offered now. Companies will need to share information with other companies in related fields, and each company might have a different software system in which all their data is housed. By agreeing upon a set of DTDs or schemas (encoded in XML), these companies can exchange information with each other regardless of what systems they are using to store this information. If their app servers can exchange XML documents (based on some shared DTD or schema), then these disparate app servers can understand each other and share information. One of the uses for XML foreseen by the W3C is just this, vertical industries (like insurance and health care) creating sets of DTDs and schemas that all companies in the industry agree upon. Then these companies' app servers can talk to each other using some popular protocol (like HTTP or CORBA/IIOP) to exchange information between each other. This has the potential to save a lot of time and money in the daily business operations of these companies.

Web-based Applications

line-item, and none, we have run-in, compact, and marker (which we'll get to later), as well as a number of values specific to tables (which we'll also cover later on).

The display value compact has an effect similar to <DL compact> (assuming your browser supports that bit of HTML). Basically, if an element is set to display: compact, then it will appear in the margin of the next element, assuming there is enough room for it. Otherwise, both elements will be treated as block-level elements. Think of a "compacted" element as one that floats, but only if there is room for it to be displayed without altering the formatting of the following element, something like the illustration in Figure 10-1.

Figure 10-1

Figure 10-1. Compact display of a definition list

On the other hand, run-in has the effect of turning a block-level element into an inline element at the beginning of the following block-level element. Another way to think of it is that a block-level element set to run-in will be combined with the next block-level element so that the two together form a single block-level element.

Given this code:

<H3 STYLE="display: run-in;">A Heading.</H3>
<P>This is a paragraph of text....</P>

the result will look something like what's shown in Figure 10-2.

Figure 10-2

Figure 10-2. A run-in heading

The display type run-in can be applied to any block-level element, not just headings. However, this rule should only work if the next element is block-level and is not floating or positioned absolutely. So, for example, if you try to set an inline anchor to run-in, it won't have any effect.

Another change for display is that its default value is inline, not block, as was defined in CSS1. The authors have termed the original default value an error, so if you don't declare a value for display, it is assumed to be inline. Of course, your browser should have its own built-in HTML styles, so don't worry about your paragraphs suddenly running together!

10.1.2. More Inheritance

Finally, there is one very important new feature of CSS2 that belongs in this section: the value inherit. If you were to ask the question, "Okay, to which properties did inherit get applied?" the answer would be, "Every last one of them." There is not a single property in the whole of CSS that does not accept a value of inherit.

inherit is used to explicitly declare that a given computed value should be inherited from its parent. In other words, if the font-size for BODY is computed to be 14 points, then the declaration P {font-size: inherit;} would set paragraph text to 14 points in size, as long as the paragraphs are children of the BODY element. Similarly, you could make sure that hyperlinks always have the same color as the text that surrounds them by using the simple declaration:

A:link, A:visited {color: inherit;}

The power of this change should not be underestimated. In effect, you are able to override the specificity mechanism that ordinarily takes effect. Usually, hyperlinks are (for instance) blue unless you explicitly declare them to be otherwise -- and if you want differently colored links in different areas of the same page, you'd have to construct a different rule for each color.

Now, thanks to inherit, if it's okay to make them the same color as surrounding text, you just need one rule that will cover all circumstances. Note that I'm not saying this is a good idea, or the only thing for which inherit can be used. It's simply the most obvious possibility.



Library Navigation Links

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

contains it. However, the background will only be visible within itscontaining element. This leads to a rather interesting consequence.

Let's say we have a document with a tiled background thatactually looks like it's tiled and an H1element with the same pattern, only in a different color. Both theBODY and H1 elements are set tohave fixed backgrounds, resulting in somethinglike Figure 6-57:

The 2nd category of Java applications called Java Application Servers (or app servers) and they make good use of XML. Unlike client side graphical Java apps (from the previous section) which are very standalone in their operations, app servers tie many different networked software components together in order to provide information from multiple sources to a set of client side Java apps or web browsers (maybe even running on different devices). This is shown in Figure 2. An app server is actually a conglomeration of several distributed and client/server software systems. So when you write an app server, you are actually writing many different software systems which are all networked to work together, to process information that comes from various sources, and distribute this information to a set of client apps (that you also have to write) running on different devices and platforms.

How can XML help app servers do their work? As you can see in Figure 2, in order for the app server to harvest information from such a rich variety of sources, there must be some common ground between all of these sources (each of which might be running on a different hardware and software system). This common ground is the information which flows throughout the entire system, regardless of what source the information comes from. CORBA is an example of tying disparate systems together based on the interfaces that certain remote objects implement. XML does the same thing for data. It allows these disparate systems to share information in a medium that consists only of pure information (and the structural relationships that exist inside of that information). By taking the lowest common denominator approach by using plain text to encode data, XML allows these systems to talk with each other without requiring any special binary information format converters or other service layers to translate between binary formats (for encoding data). Also, since HTTP already supports transmission of plain text, it is completely natural to move XML around using the Hyper Text Transfer Protocol through firewalls and disparate networks. This is shown in Figure 3. XML can be transmitted between systems using one of the most prevalent protocols in use today, Hypertext Transfer Protocol or HTTP 1.1 (which is the protocol of the web).