Slashdot Log In
CSS Cookbook
Posted by
samzenpus
on Mon Nov 20, 2006 03:21 PM
from the always-in-style dept.
from the always-in-style dept.
Michael J. Ross writes "Anyone involved with the coding of Web sites likely knows that Cascading Style Sheets (CSS) should be used for styling the content of their sites' pages — setting text sizes and fonts, setting background colors, sizing margins, positioning images, and more. CSS allows the Web developer to specify the visual appearance of the site, separately from the HTML, and thus to be able to make changes in the future within a single stylesheet, rather than hunting through the HTML and modifying every occurrence of each affected element. The benefits of CSS are many, but so too can be the frustrations when the developer turns for help to CSS books heavy on theory and light on practical explanations. For every Web site 'cook' feeling the heat in their cyber kitchen, there is an ingredient that can help: CSS Cookbook." Read the rest of Michael's review,
| CSS Cookbook | |
| author | Christopher Schmitt |
| pages | 538 |
| publisher | O'Reilly Media |
| rating | 8 |
| reviewer | Michael J. Ross |
| ISBN | 0596005768 |
| summary | Practical solutions to common CSS challenges |
Written by award-winning Web designer Christopher Schmitt, this book is published by O'Reilly Media, under the ISBN 0596005768, and is in its second edition, having been updated for Internet Explorer 7 and Firefox 1.5. The book has its own Web page on the publisher's site, offering the book's table of contents, the index, Appendix D ("Styling of Form Elements," in PDF format), and links for reading and submitting book reviews/comments, as well as reading and reporting errata (there are none, as of this writing).
The book's 538 pages are organized into 12 chapters, which cover the major areas of interest to the Web developer: CSS overview, typography, images, page elements, lists, links and navigation, forms, tables, page layouts, printable pages, hacks and workarounds, and design considerations. Appendix A briefly describes some of the better online CSS resources, including tutorials, design guides, discussion groups, technical references, and tools, such as the W3C validators. The next two appendices cover CSS 2.1 properties, proprietary extensions, selectors, pseudo-classes, and pseudo-elements.
The fourth and last appendix, on the styling of form elements, details how 20 CSS properties affect eight form elements, as displayed within Windows Internet Explorer 5, 5.5, 6, and 7; Mac Safari 2; Windows and Mac Firefox 1.5; Windows and Mac Netscape Navigator 7.2; and Opera 8.5. The form elements considered are: checkboxes, file upload elements, radio buttons, text fields, multiple options, select elements, submit buttons, and text areas. The author does not explain exactly what page elements are meant by "File Upload" (at the beginning of the appendix) or "File Input" (the actual section title). Presumably he is referring to the file display field and Browse button, and not the file locator dialog box, which is determined by the browser and operating system. More importantly, he does not explain what is meant by "multiple options" nor "select elements," and neither term is listed in the book's index. Future editions of the book would benefit by beginning every element's section with an example, showing the code as well as the element's appearance on a Web page. Despite this obvious omission, this appendix could prove a godsend to anyone concerned with how these various types of elements are affected by CSS within these eight major browser versions. As noted earlier, the appendix can be downloaded for free.
HTML/CSS books generally fall into two broad categories: Introductory books are usually sufficient for beginners, because they cover the basics. But they are typically useless to the veteran developer who is struggling to understand why Internet Explorer is mucking up yet another page that looks fine in Firefox, Opera, and Safari — and how to work around the problem. Advanced books assume that the reader already has a relatively solid understanding of the technologies, and uses that basis as a foundation from which to explore sophisticated design techniques. But even those books prove inadequate for the developer who is simply wondering how to best use pure CSS to do such presumably straightforward tasks as positioning some images horizontally, with small captions centered underneath each one. In fact, many of those advanced books seem to have little interest in clearly explaining how the reader can do what the author has done, largely because the sample projects and their source listings are too long and involved, thus burying the critical HTML and CSS in pages of code.
There is clearly a great need for one or more HTML/CSS books aimed at the developer who already understands the basics, and wants to apply that knowledge for building robust Web pages, all while following defensible best practices. The O'Reilly "Cookbook" titles are intended to fill that gap, by presenting the material in the form of recipes, each comprising a brief statement of the problem to be solved, a summary of the solution, and a discussion of the solution's details. Oftentimes additional resources are referenced, in a "Sea Also" subsection, which might have one or more links to relevant Web sites. The discussion subsections usually have sample code, in addition to a figure showing the code's output.
Possibly the greatest benefits of the cookbook format, is that it forces the author to clearly state the purpose of each section, and then to get right to the point of how to achieve that purpose. This prevents the meandering seen in many of the advanced design books, which is the main reason why they can be so frustrating for the developer who wants to quickly find out how to perform a specific task on a Web page, such as the image positioning task mentioned earlier. Possibly the biggest downside to the cookbook format is that it results in contrived problem statements, such as the very first one in CSS Cookbook: "Problem — You want to use CSS in your web pages." Is that truly a problem? Is it not much more a goal or task, than some sort of problematic difficulty?
Yet aside from any misleading subsection titling, the recipe format does cause any (largely) expository material in a technical book to get chopped up into somewhat artificial pieces. It is more noticeable in the first chapter of this particular book, titled "General," in which Schmitt explains the fundamentals of CSS: selectors, classes and IDs, properties, the box model, style sheets, comments, shorthand properties, floating images, absolute and relative positioning, and using CSS with the more common page development tools. As the author gets into more advanced topics — for which individual subsections can stand more on their own — the recipe format works fine. One advantage is that the section titles end up being detailed enough that the reader can, in most cases, quickly find the relevant section to address their needs.
Overall, this book is a fine addition to O'Reilly's growing list of programming titles. However, like all books, it is not perfect. It does not cover all of the more common tasks that the average Web programmer might want to accomplish — but it does hit the bulk of them. Sadly, all of the figures in the book are in black and white, including those displaying colors on the sample Web pages. Shades of gray are just not optimal. Fortunately, in most cases, the crux of the technique is discernible. In addition, the sample code has too many instances where layout is achieved using tables, and not pure CSS. Lastly, the book's index — similar to that of so many other technical books nowadays — could certainly use some beefing up. After all, if the reader cannot find the desired material using the table of contents, the index is their last hope, before resorting to time-wasting page flipping.
In terms of HTML and CSS information, the topics are well chosen, and the coverage of browser hacks and workarounds is excellent. Also, the most critical parts of the code are helpfully bolded. For those readers completely unfamiliar with JavaScript, it is used only where unavoidable. The book's material is neatly presented, and the author's writing style is straightforward and approachable.
On balance, CSS Cookbook is to be recommended to any developer looking for a CSS guide that is concise, clearly written, well-illustrated, and addresses the most common challenges in building Web pages.
Michael J. Ross is a computer consultant, freelance writer, and the editor of PristinePlanet.com's free newsletter. He can be reached at www.ross.ws, hosted by SiteGround.
You can purchase CSS Cookbook from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
This discussion has been archived.
No new comments can be posted.
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
How did they get the book out so fast (Score:2)
(http://www.kibbee.ca/)
Re:How did they get the book out so fast (Score:4, Insightful)
(http://www.tanningbeds4less.com/ | Last Journal: Sunday November 05 2006, @07:23AM)
Re:How did they get the book out so fast (Score:4, Informative)
(http://asztal.net/)
Not to mention, IE7 came out before Firefox 2.0...
Re:How did they get the book out so fast (Score:4, Informative)
(http://slashdot.org/ | Last Journal: Monday November 03 2003, @03:59PM)
If nothing else, they'd rather be the first guys in the shelf with an IE 7 book and be wrong than the last guys and be right. An author friend of mine quit writing technical books precisely because she hated losing market share to badly-written books that came out sooner.
Re:How did they get the book out so fast (Score:4, Informative)
(http://www.kibbee.ca/)
With IE7 I feel like I'm back developing in 1999 (Score:1, Funny)
<link type="text/css" href="stylesIE7.css" rel="stylesheet" media="screen"
<![endif]>
<!--[if IE 6]>
<link type="text/css" href="stylesIE6.css" rel="stylesheet" media="screen"
<![endif]>
<!--[if IE 5]>
<link type="text/css" href="stylesIE5.css" rel="stylesheet" media="screen"
<![endif]>
<!--[if lte IE 4]>
<link type="text/css" href="stylesIE4.css" rel="stylesheet" media="screen"
<![endif]>
some improvements for you (Score:5, Funny)
javascript:self.close()
<![endif]>
<!--[if IE 6]>
javascript:self.close()
<![endif]>
<!--[if IE 5]>
javascript:self.close()
<![endif]>
<!--[if lte IE 4]>
javascript:self.close()
<![endif]>
Well this sounds promising... (Score:3, Insightful)
Use of hacks? Sweet!
Hacks are a bad practice that has been challenged and debated for a while now. I though, and correct me if I am wrong, that conditional HTML statements were the best way to go. Nowadays, why would someone want a book that is going to lead you to write non-compliant code.
Re:Sounds logical, but isn't (Score:4, Informative)
You are wrong. There are a few different factors at play here:
The anonymous coward was completely correct - it's perfectly possible to use valid code with Internet Explorer by simply limiting yourself to the subset of code that works in Internet Explorer and is defined by a W3C specification. This can be extremely frustrating at times, but it's usually better than the alternative.
In addition, you shouldn't really focus on the XHTML bit. There are very few people who actually need XHTML, and despite the buzz, it has nothing to do with standards compliance or CSS. XHTML 1.0 and HTML 4.01 are functionally identical in these respects.
The problem with these types of books... (Score:2, Insightful)
My work got me a few CSS books and when the boss asked if I'd read them, I indicated I'd used them briefly for reference, but no, not as such. He wasn't too impressed until I pointed out the recent sites I'd created, all validated, all exactly to spec and all AA accessible, not to mention extreme light weight CSS which works in *any* browser without resorting to hacks.
I'm sure it's a great reference point, but the web is by far the most immediate and effective learning medium - I never stop learning and improving my CSS skills, but I don't think a book like this would help me further my skills any quicker.
The simple fact is that if your looking for very specific requirements and answers, a book will seldom fulfil that goal.
On the flip side, if your new to CSS and HTML in general and don't have a damn tight deadline, it's worth the purchase.
For those whose career is web coding, the web itself is the most valuable resource.
Or, alteratively, if your like me, I prefer reading fiction
Does any major site use pure CSS? (Score:5, Interesting)
(http://www.bleeding-head.com)
Re:Does any major site use pure CSS? (Score:5, Informative)
Unfortunately, there are a lot of people with bad habits writing HTML tutorials too.
One of the big problems is software developers who have a basic grounding in "bad" HTML and use it to lay out programatically generated sites. Developers in general don't want to bother to learn CSS - they seem to think it's the sugar on top - "just" a graphic design thing. So you see a lot of crap HTML work out there - and a lot of table layout.
For a sublime, pure-CSS experience (make sure and load some of the stylesheets on the right-hand side), check out http://www.csszengarden.com/ [csszengarden.com]
Re:Does any major site use pure CSS? (Score:4, Insightful)
(http://free-usa.blogspot.com/)
Every single CSS methond has some kind of drawback that requires some kind of hack to fix if it's even fixable at all.
Yes, there's a great deal to be said about separating presentation from content, but like OOP, CSS is no silver bullet.
They could solve about 99% of the things tables are used for by simply having a "float: center", but even if they did that it would take like 10 years for all the different web browsers to implement it and you'd still be supporting all the old ways, which is why people still use tables.
Don't get me wrong, I really try and I use the books I've purchased on CSS and website design and online resources including news groups and so forth, and I'd really rather use CSS than tables (and I usually accept a layout that I'm not always happy with just to do it), but this whole "tables are evil" thing will only be true when CSS can do the layouts you can so easily accomplish with tables.
And contrary to your assertation; the kind of simple "center this" kind of layout I'm referring to doesn't give you a nightmare of nested tables and cells that are hard to figure out where they are.
Here's an example: a simple centered box that grows or shrinks in width based on dynamic content. A simple unordered list, for example. If the options are small, the entire table is small and centered. If some of the items are wordier, the table automatically grows wider to accomodate the longer list item. If you don't want the table to grow too wide just for the one option (you'd rather it wrap before it gets to 100%), you can put it in a div that narrows the maximum width of the table. In this case, it could simply be a single cell table.
In CSS, you don't get dynamic width based on the content - you get a percentage width or a specific width. The only way to center it in this case is to use javascript (or you could aproximate it with server side scripting). Believe it or not, after weeks of debate on the CSS newsgroup, that was the answer I got: don't use tables, use scripting to compensate. I'm sorry, but no.
Re:Does any major site use pure CSS? (Score:5, Insightful)
(http://slashdot.org/)
The solution, of course, is to rely on a bunch of hacks to present slightly different rules to different browsers, forcing all of them to display the correct bounding-box, margin, padding etc. And now we're writing unsupported, undocumented nasty hacks that will come back to bite us each time a browser is updated, which as a previous poster pointed out is an obvious no-no.
Nested tables are not elegant, they're not CSS-based, they're not extensible etc. But they work. A 100px cell displays as at 100 px pretty darn reliably, without a laundry-list of hacks and hints. A menu placed to the left of the content STAYS to the left of the content, it doesn't suddenly display after the content block. From a practical standpoint, tables are simply more robust and more reliable than CSS-based layouts, at least with the flakey browser support CSS layouts have. I've pulled lots of hair out to get my CSS layouts as good as they are, because I believe in CSS, but I think a smarter man would have used tables.
CSS degrades far better than tables (Score:4, Insightful)
(http://www.highprogrammer.com/alan/ | Last Journal: Saturday April 29 2006, @04:33PM)
The entire point of CSS is to "degrade well." You've confused "displays identically on mainstream browsers with large resolutions" for actually degrading gracefully. To take a single example I have a lot of experience with, those beautiful table layouts fall apart on small displays. Maybe you can reasonably assume modern laptops and desktops have a resolution of 800x600, but what about my phone (128 x 160) or my Palm (320x480). A table based layout falls apart. But a CSS based layout using floating sidebars degrade reasonably gracefully on my palm. My phone doesn't support CSS and I frequently disable CSS on my Palm for speed. In both cases the CSS based layout may be dull and sequential, but it's perfectly readable. For web sites about presenting useful information this is great. Table based layouts turn into hard to read messes. Now my Palm's browser has a great feature that tries to detect tables-as-layout and linearizes them, and it's pretty good, but it occasionally trashed actual tabular data. Because people use tables to mean two totally different things ("I want this thing exactly here for visual impact" vs "This is tabular data"), my Palm can't try to present a graceful degredation.
Re:Does any major site use pure CSS? (Score:4, Insightful)
(http://membled.com/)
A book? (Score:2, Insightful)
Personally, the only way for me to know a particular cross-browser CSS approach works is to actually test it on every browser I can. Kinda hard to do that with a book.
And if these guys were real CSS gurus, they would have written their book in XML and CSS and used Prince to convert it and then open sourced the book code.
Chapter on 'Styling of Form Elements' (Score:1)
(http://www.abitcloser.com/)
Use the right tool for the job (Score:1)
CSS Book vs Web Tutorials (Score:1)
From the review, I don't see any reason to jump out to purchase the book. Cookbook items are already provided ubiquitously. Even a casual search on google via the general terms "best css tutorial [google.com]" returns some elegant recipes for free [cameronolthuis.com].
Re:Cooking with CSS. (Score:1)
(http://slashdot.org/ | Last Journal: Wednesday August 14 2002, @01:03PM)
Re:CSS isn't "doing it" for me.... (Score:3, Insightful)
Re:One more time (Score:2)
Sure it does.
The book belongs to Samuel Its. It's Its' book; his name is written inside its cover.
Re:CSS isn't "doing it" for me.... (Score:1)
IMO, the nature of the web limits design. CSS is just a way to work within those limits.
Re:CSS isn't "doing it" for me.... (Score:2)
(http://www.nocturnis.net/)
There are quite a few designs I've created that I couldn't do with the old table-within-table-within-table sludge and morass we used to have to work with. And they're easily changeable if I have to revamps the look of the site without having to mess with the (properly separated and semantically organized) html or the content in the database. CSS is extraordinarily flexible.
Re:ccs: unneccessary complication (Score:1)