Slashdot Mirror


CSS Pocket Reference

Michael J. Ross writes "For Web developers who appreciate the value of separating Web content from its presentation, Cascading Style Sheets (CSS) has proved a godsend, because it allows all of the styling of a Web site to be organized in CSS files separate from the site's semantic content, in HTML files (possibly dynamically generated). Yet to make this styling power possible, CSS must incorporate a long list of syntax elements, including hundreds of selectors, properties, and values. Thus it can be quite handy for the developer to have on hand a concise summary of CSS, such as the CSS Pocket Reference, authored by Eric A. Meyer." Read on for the rest of Michael's review. CSS Pocket Reference, 3rd Edition author Eric A. Meyer pages 168 publisher O'Reilly Media rating 8/10 reviewer Michael J. Ross ISBN 0596515057 summary A concise reference book for CSS. The book was published by O'Reilly Media on 5 October 2007, under the ISBNs 0596515057 and 978-0596515058. CSS itself has evolved along with other Web technologies, and this book is now in its third edition, having been updated to reflect the ongoing changes in CSS; the book now covers CSS2 and CSS2.1. On the book's Web page, O'Reilly offers an online table of contents, as well as ways for the visitor to view and submit errata (none as of this writing) and reviews for the book. Unlike most technical publishers, O'Reilly now makes available previews of their books' contents, in the form of a table of contents with links to the first few paragraphs of each section, including tables and illustrations.

Despite the growth in the number of elements in CSS, and the attention paid to each one of them by the author of CSS Pocket Reference, the book is still small enough to fit in a pocket, at only 168 pages. The book's material is organized into 18 unnumbered sections, preceded by some notes on the book's typographical conventions, and followed by an essential index. The bulk of the material is found in the Property Reference section. Other sections explain how to add styles to HTML and XHTML pages; CSS rule structure and style precedence, including inheritance and the cascade; element classification and display roles; visual layout; rules on floating and positioning; and table layout. Subsequent sections cover CSS value types and units, and selectors, including some of the newest additions to CSS, such as the adjacent sibling selector and the language attribute selector. Just before getting into the details on properties, Eric Meyer discusses pseudo-classes and pseudo-elements, which have made it possible for Web developers to create rather robust and attractive site navigation using CSS exclusively, without any need to resort to images and JavaScript for rollover effects and other navigation eye candy.

For each element of CSS that is covered in all of the sections mentioned above, the types of information presented to the reader can vary, depending upon the category of element. But they generally include the element's possible values, a default value, what elements it can apply to, whether it is inherited, its computed value, a brief description of the element, at least one example illustrating its usage, what browsers support it, and oftentimes a note on its usage. Consequently, this new edition of the book, like its predecessors, should prove more than adequate for most CSS reference needs.

As with any computer book, there are several ways in which this one could be improved. Any reader using the book to look up a particular element, has two possible ways of doing so: They could first consult the index, and, assuming the element is listed there, go straight to the page indicated. But most readers, knowing that the elements in each section are listed alphabetically, will probably open up the book near the front or the back, and begin flipping backward or forward, respectively, hoping to spot the element of interest as quickly as possible, given its alphabetical ordering. That individual will likely immediately spot an obvious problem with the book: The pages have no running titles (the words that indicate the first element discussed on that page, and typically listed at the very top of each page). Inclusion of such running titles in the next edition of the book, would make it much faster to use.

Another valuable addition would be some sort of table listing all of the CSS elements and their level of support within the most commonly used Web browsers and, in the case of Internet Explorer, the most commonly used versions of the browser. Also, on page 48 of the book, at the beginning of the Property Reference section, it has a subhead of "Visual Media," which suggests that there are other subheads within that section, for other media types; but I was unable to find any.

All of these problems concern the publisher's choice of material. My last criticism concerns the layout of that material in the print version of the book. Because this diminutive volume has narrow pages, and they are tightly glued together in the binding, it is imperative that the publisher of such a book provide plenty of white space in the inner margins (those closest to the binding), so the reader does not have to crack open the book too much in order to read the text closest to the binding. Repeatedly opening up the book far enough to read those inmost words, will over time weaken and eventually destroy the binding. In contrast, a small reference book like this has no need for much outer margin. Sadly, O'Reilly got it backwards with this volume, with relatively wide and useless outer margins, and inadequate inner margins.

Aside from the aforementioned flaws — all of which can be remedied in the future — CSS Pocket Reference is a compact and neatly organized gem of a book, packed with information of value to busy Web programmers.

Michael J. Ross is a Web developer, writer, and freelance editor.

You can purchase CSS Pocket Reference, 3rd Edition from amazon.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

21 of 87 comments (clear)

  1. Browsers? by WinterSolstice · · Score: 3, Informative

    I note that he mentions there is a list of "browsers that support" any given tag, and some notes. If it actually has some of the quick workarounds for the different browsers, I'm so buying this book.

    I hate setting up something, then spending hours looking up workarounds for some random tag or other on IE.

    --
    An operating system should be like a light switch... simple, effective, easy to use, and designed for everyone.
    1. Re:Browsers? by ls+-la · · Score: 3, Insightful

      I've stopped bothering to spend more than 5 minutes figuring out any IE bug. Granted, my pages aren't widely used, mostly testing stuff out and internal school pages, but IE is more trouble than it's worth. All the public computers here have firefox, so no one can really complain anyway.

    2. Re:Browsers? by CRCulver · · Score: 4, Insightful

      It's not as if this is the first guide to designing for all browsers. CSS Mastery by Budd et al., the CSS guide I've been using lately, gives plenty of info on tag support and collects a number of useful hacks, and it's been out for only two years. And remember, this Slashdot review is for a O'Reilly pocket reference. That whole series consists of little more than what one could find in free sources, and though I've bought a couple of volumes, they've been more to provide reading while I'm away from the computer (using a laptop at the cafeteria is messy) than for essential reference while I'm at work.

    3. Re:Browsers? by Bazman · · Score: 5, Funny
    4. Re:Browsers? by moderatorrater · · Score: 4, Funny

      my pages aren't widely used And they'll likely stay that way ;)
    5. Re:Browsers? by ComputerPhreak · · Score: 2, Informative

      Back when Firefox wasn't really used a lot of web developers felt a lot like you:
      I've stopped bothering to spend more than 5 minutes figuring out any Firefox bug. Granted, my pages aren't widely used, mostly testing stuff out and internal school pages, but Firefox is more trouble than it's worth. All the public computers here have IE, so no one can really complain anyway.

      It's coding for one web browser that lead to the mess of pages that 'only work on IE'. Just because Firefox happens to be more adherent to the standards doesn't mean that it doesn't have its own quirks. You should develop to the standard, not to your favorite browser's implementation of it.

    6. Re:Browsers? by an.echte.trilingue · · Score: 5, Insightful

      Yeah, except that it's not Firefox: it's writing to THE W3C STANDARD which Firefox and almost every other browser that exists (including Opera and khtml based browsers such as Konqueror and Safari) just happen to render correctly (with a couple of caveats).

      IE, on the other hand, is a freaking nightmare. I find that IE7 works pretty well; in general I can fix its small bugs by changing the css in ways that don't break the standard or break rendering in other browsers, but IE6 is so horridly in compliant that even for a lot of really common css tasks that were around long before IE6 was released and that Microsoft helped to write are totally broken. Things like the :hover pseudo class and default element margins and padding are totally broke. Floats act funny. You cannot fix it without breaking compliance with the standard and other browsers, which means that you have to write a special css file for IE6. It's not even consistent within versions of IE: IE5.5 and 5.5 for Macs don't render the same code in the same way.

      So, IE7 finally mostly works, but MS fucked the user interface up so bad that everybody wants to stick with IE6, which is still the world's most common browser over a year after IE7's release. Do you realize how bad that is? How many people haven't upgraded from Firefox 1.5 to Firefox 2?

      I can only conclude that Microsoft does this kind of stuff on purpose. They have a standard for trident: their web development products always produce code that renders perfectly in all versions of IE. Rendering the w3c standard is not hard: a bunch of hobbyists and a small company in Norway have both separately proven that you can do it on relatively limited resources. The only reason they could possibly have for their horribly broken browser is that they have an interest in web standards being broken.

      Ok. Rant over.

      --
      weirdest thing I ever saw: scientology advertising on slashdot.
    7. Re:Browsers? by bcat24 · · Score: 2, Informative

      Mod parent up. These days, if I design a website, I get it working in a modern, standards-compliant browser first. (Personally, I use Firefox, but like the parent said, it's certainly not the only choice.) Then and only then will I start putting in workarounds for browser bugs. (IE 6, I'm looking at you.)

    8. Re:Browsers? by Walter+Carver · · Score: 2, Informative

      Look up on "conditional comments" for IE. They allow you to add styles (and consequently override existing rules) that only IE can see. Also, test your pages in IE as you create them. It only takes a few minutes to fix an IE bug that just popped in, rather than try to fix the whole page.

  2. I liked this guide by Anonymous Coward · · Score: 5, Funny

    But I couldn't find any info on nested tables.

    1. Re:I liked this guide by Bill+Hayden · · Score: 2, Informative

      If you are labeling this informative instead of funny, then you are not a web designer and the joke has gone right over your head.

      --
      Protect your browser with the Force Safe Search add-on
  3. Godsend by Ikoma+Andy · · Score: 2, Insightful

    I have heard CSS called many things, but never a godsend.

  4. A good, free reference by athloi · · Score: 5, Informative

    http://technical-writing.dionysius.com/resources/CSS-2.0.pdf

    Helped me through many a "what's that called again?" session.

    Link updated because both original links were dead.

  5. Am I missing something? by incripshin · · Score: 4, Funny

    I was looking at the O'Reilly page for this book. Under the review section, there are two reviews: 3/5 and 5/5. The page claims the average is 5/5. Let's see, (3/5 + 5/5)/2 = ((3+5)/5)/2 = (8/5)/2 = 8/10 = 5/5. Oh, their math is right. Never mind.

  6. Awesome by commodoresloat · · Score: 5, Funny

    I can't wait to read this book and start encrypting DVDs....

  7. wow by uepuejq · · Score: 5, Funny

    this is especially useful for unconventional web developers who don't actually have access to the internet.

  8. Re:I like it by Intron · · Score: 5, Funny

    "It has some typos. And unfortunately the binding broke"

    So the book is just like CSS in general.

    --
    Intron: the portion of DNA which expresses nothing useful.
  9. Alone At Sea... by Nitroadict · · Score: 4, Interesting

    Before I go further, I use CSS everyday I design, especially since I'm still learning all of it's annoying idiosyncrasies, mainly because (and I'm not the only one) the CSS language itself is flawed (constraints & variables being some of which CSS lacks). The idea of what CSS created for, style sheets, is great & is a step forward, but the way we have to use style sheets with CSS sometimes makes me wonder what an abortion feels like.

    I admit, some days it seems to get *easier* to deal with since I actively remember the times I more or less lost my shit because the stupid code wouldn't render correctly in different browsers, so I also remember (most of the time) what to avoid, but I really don't think the full potential of style sheets will be fufilled with CSS as the way it is. Even with CSS 3 (I'm not touching HTML5; I'm one of those "wacky" people who think we should stick with what we have until it's stable enough to warrant additions; a more eloquent way of putting it has already been said: http://www.molly.com/2007/06/14/defy-the-pedantic-semantic-html5-and-xhtml-11-must-stop-for-now/ ), I just don't see the difficulties of CSS, which warrant most of the CSS books being made, being resolved anytime soon.

    I know I'm not the only one who begrudgingly uses CSS (I realize they are other technologies to use instead or to supplement CSS' shortcomings, I'm currently looking into that...), and I know I'm not the only who thinks something new should be made to address what CSS fails to do. I'm not talking about HTML5, nor CSS3, and defintley not FLASH (although, personally, I think if HTML & CSS were to somehow utilize a plug-in for browsers to render shit properly, standards would be able to compete with FLASH, but I'm just rambling there).

    While googling out of frustration, I came across this:

    PSL (Proteus Style Sheets): http://www.cs.uwm.edu/~multimedia/papers/jucs/jucs.html

    Why Current Style Sheet Standards Have Failed to Improve Document Engineering: http://www.cs.uwm.edu/~multimedia/WWW8/webEng.html

    I know every single Pure-CSS zealot is going to moan & groan at me for thinking differently than them, but honestly, PSL seems like a way better idea than simply adding on to an inheritantly broken style sheet language in which books & books need to be made to tell people what hoops to jump through to get it work. I don't know, I guess that sounds stupid to too many people; often I've let that prevent me from expressing my not unreasonable doubts.

    Sometimes I feel like some poor bloke who time traveled back to the Titanic but can't prevent anything due to paradox. :\

  10. A Pocket Reference!!!!!! by FlyingGuy · · Score: 3, Funny

    Is this a joke or what!? Does this pocket reference explain this kind of gibberish?

    Someone please translate this into something that resembles logic, please?

    ul.nav,.nav, ul{ /*Remove all spacings from the list items*/
            margin: 0;
            padding: 0;
            cursor: default;
            list-style-type: none;
            border: 0px solid #369;
                    display: table ;
    }

    ul.nav>li{
            display: table-cell;
            position: relative;
            padding: 2px 6px;
    }

    ul.nav li>ul{ /*Make the sub list items invisible*/
            display: none;
            position: absolute;
            max-width: 40ex;
            margin-left: -6px;
            margin-top: 2px;

    }

    ul.nav li:hover>ul{ /*When hovered, make them appear*/
            display : block;
    } .nav ul li a{ /*Make the hyperlinks as a block element, sort of a hover effect*/
            display: block;
            padding: 2px 10px;

    } /*** Menu colors (customizable) ***/

    ul.nav, .nav, li, a{
            background-color: white;
            color: blue;
    }

    ul.nav li:hover, .nav ul li a:hover{
            background-color: yellow;
            color: blue;
    }

    ul.nav li:active, .nav ul li a:active{
            background-color: black;
            color: white;
    } .nav a{
            text-decoration: none;
    }

    CSS is a miserable and irrational set of style tags that when used to do things like turn un-ordered lists in menu's becomes pretty much inscrutable and damn near unusable. Nested DIVS are a poor substitute for nested tables. If you want to say I am wrong, then show me how create that will hold data in perfect rows and columns, or how you can make two divs equally occupy 50% of the outer div's area.

    --
    Hey KID! Yeah you, get the fuck off my lawn!
    1. Re:A Pocket Reference!!!!!! by Selanit · · Score: 3, Informative
      It makes a menu in which sub-items are revealed when you move your mouse over them. And it's being done badly, for the following reasons:

      1) It relies on all kinds of things which IE either doesn't support or supports badly, including: the child selector (that's the > bits), using the :hover pseudo-class on elements other than anchors, display: table, and display: table-cell. There's no way this sucker is ever going to work in IE. Not IE 7, and definitely not IE 6. Just look up IE's support for the various properties used here on WebDevout.net's CSS compatibility list.

      2) The code has needless redundancy built into it. Example: in that first rule set, they're using three selectors:

      ul.nav <-- an unordered list of the "nav" class
      .nav <-- any element at all of the "nav" class
      ul <-- any unordered list

      Stacking selectors by separating them using a comma can be useful, but this has been done badly. The first selector alone should have been sufficient for their purposes, or the second one alone. And the third one is simply atrocious, because it makes the rule apply to EVERY unordered list in the document unless it is explicitly overridden. If there is EVER an unordered list in the document which is NOT part of the menu, it's going to be totally fubared by the menu formatting instructions. Selectors which apply to every element in the entire document are dangerous that way unless you use them really carefully or make only tiny modifications. For example, I like changing the cursor over label elements so that people will know they do something if you click them, like this:

      /* Make labels for form elements have a pointer. */
      label { cursor: pointer; }

      The modification is very simple, does not change the basic appearance or functionality of the element, and provides a useful bit of feedback to the user.

      3) Inconsistent use of whitespace. Note that sometimes a rule will start immediately after another with no whitespace, like this:

      ul.nav li:active, .nav ul li a:active{
      background-color: black;
      color: white;
      } .nav a{ <--------------- here
      text-decoration: none;
      }

      The rule set for ".nav a" starts on the same line as the previous rule set finishes, which is ugly as sin. For improved comprehensibility, it should have at least two carriage returns after the previous rule set. And the author didn't even do it consistently.

      I'll happily agree that this is an ugly bit of code. And no, the CSS pocket reference will not be especially helpful in untangling this snarl; it's a reference, for looking up properties and selectors. It shows you what individual bits do, but does not explain how the many bits may be combined. References are primarily useful when you're building your own code, and rather less so when interpreting somebody else's.

      That said, I have to take issue with your conclusions.

      1) "CSS is a miserable and irrational set of style tags"

      First off, CSS doesn't use tags. It uses selectors to refer to tags. Second, CSS itself is not irrational. It is abstract, and takes a while to wrap your head around. It has some inadequacies and shortcomings, such as making multiple columns have an equal height or centering content vertically as well as horizontally, both of which are a serious pain in the ass. But you're throwing out the baby with the bathwater. CSS also gives you quite a lot of fairly fine-grained control over your pages. Moving the presentational stuff out of your HTML makes it considerably easier to read (assuming that you don't keep throwing extraneous DIVs into it instead of learning the inheritance rules and the box model), and has truly amazing benefits

  11. Re:A good, free reference (even more!) by Skrynesaver · · Score: 2, Interesting

    I use that diagram a lot. I have it pinned to my cubicle wall (here in Dilbert land) along with the Javascript cheat cheat, the regex cheat sheet etc..
    For a complete selection of quick and dirty guides to common technologies IloveJackDaniels.com is a very handy resource, thanks Dave.

    --
    "Linux is for noobs"-The new MS fud strategy