Thursday, August 21st, 2008
Category: Browsers
, CSS
![[image]](http://mowser.com/img?url=http%3A%2F%2Fejohn.org%2Ffiles%2Fqsa-blog.png)
We have all been talking about querySelectAll for awhile, but John Resig gives us a wrap-up that covers the state of play.
He talks about the browsers, and the libraries that wrap them and clean up shop via code like:
JAVASCRIPT:
function querySelectorAll(selector){
try {
return Array.prototype.slice.call(
document.querySelectorAll( selector ) );
} catch(e){}
return myOtherLibrary( selector );
}
Less code. More speed.
Wednesday, August 20th, 2008
Category: CSS
Jeremy Keith has been doing a great job blogging An Event Apart, and his writeup of The Lessons of CSS Frameworks by Eric Meyer caught my eye.
Eric took a look at the most popular CSS frameworks (960, Blueprint, Content With Style, That Standards Guy, YAML, YUI, Elements, Tripoli, WYMStyle) and talks about choosing one...
Let’s get one question out of the way, the question "which one is right for you?" Answer… none of the above. It’s like templates. There’s nothing wrong with templates but you don’t put together your client’s site based on a template, right? They can be a good starting point for ideas but you do your own designs. If you’re going to use a framework, it should be yours; one that you’ve created. You can look at existing frameworks for ideas and hack at it. But the professionals in this room are not well served by picking up a framework and using it as-is.
Eric put together a grid of features and which frameworks support those features. Every framework does reset, colours, and fonts. The fact that every framework has a reset is evidence of the frustration we all feel with the inconsistencies between browsers. The rules for colour tend to be much more minimal. Font styling, on the other hand, is more fully-featured generally. Whereas the colour might just be set for the body element, font sizes and faces are specified throughout. Usually that font face is Helvetica. Most frameworks steer away from trying to style form elements. Almost all of them do layout, usually combinations of columns. Four of the nine frameworks included print styles. Three of the nine included hacks.
After using a framework on Google Code, I can definitely say that they add a lot, and can take some of the pain of out CSS.
Monday, August 18th, 2008
Category: CSS
, IE
, jQuery
Paul Bakaus, or jQuery UI fame, has created a nice little hack to implement WebKit CSS transforms in IE
![[image]](http://mowser.com/img?url=http%3A%2F%2Fpaulbakaus.com%2Fwp-content%2Fuploads%2F2008%2F08%2Fbild-5.png)
When you include the library, it can scan for your -webkit-transform-* transforms (soon to support the standard transform-*) and will go to work for you using a couple of nifty technologies all put together:
IE Filters such as DXImageTransform.Microsoft.Matrix that do the rotate, skew, scale, and general matrix work for you onpropertychange "almost behaves like DOMAttrChanged, but is much finer grained. It is capable of telling you whenever a DOM property changes on an element, and when you track the style attribute, it actually passes the actual style that changed along with the event." Here it is at work in the library:
JAVASCRIPT:
jQuery(Transformie.trackChangesFor).bind('propertychange', function(e) {
if(e.originalEvent.propertyName == 'style.webkitTransform') {
Transformie.refreshMatrix(this);
}
});
From there you can see the transforms which look like:
JAVASCRIPT:
// rotate
matrices.push($M([
[Math.cos(a), -Math.sin(a), 0],
[Math.sin(a), Math.cos(a), 0],
[0, 0, 1]
]));
Very nice indeed.
Wednesday, August 13th, 2008
Category: Browsers
, CSS
Remember when you wanted a growable area with rounded-goodness and you had to cut up the image into a million pieces to have the top corners and the sides? Since then we have gotten nice effects to help us, and John Resig just posted on how Firefox 3.1 will implement what WebKit already has in the border-image CSS 3 magic:
Now you can create the iPhone search button that iUI contains, using the simple CSS:
CSS:
border-width: 0 5 0 5;
-webkit-border-image: url(toolButton.png) 0 5 0 5 stretch stretch;
-moz-border-image: url(toolButton.png) 0 5 0 5 stretch stretch;
Here you see the reusable button on the left, that will stretch and become the button on the right:

Next up, rounding the borders themselves in all browsers (border-radius!)
Monday, August 11th, 2008
Category: CSS
Allan Jardine has created Conditional-CSS, a tool that allows a style sheet author to place IE style conditional statements inline with CSS to target multiple different browsers.
Expanding the IE conditional statement syntax we get:
CSS:
[if {!} browser] or
[if {!} browser version] or
[if {!} condition browser version]
Of course, browsers are getting better and better with their CSS rendering, but in this way those annoying little CSS bugs which always seem to crop up can be worked around. It can also make maintenance of style sheets much easier since it is no longer necessary to maintain separate 'hack' files for the various IE versions. For example the following block can be used to overcome some of the issues faced with the button tag:
CSS:
a.button_active, a.button_unactive {
display: inline-block;
[if lte Gecko 1.8] display: -moz-inline-stack;
[if lte Konq 3.1] float: left;
height: 30px;
[if IE 5.0] margin-top: -1px;
text-decoration: none;
outline: none;
[if IE] text-decoration: expression(hideFocus='true');
}
Conditional-CSS is an open source project and is currently available in three different source languages: PHP, C and C#, all with identical feature sets. It can readily be deployed on Apache, IIS or any other web-server with a CGI interface. Conditional-CSS can also be run from the command-line such that a style sheet with conditional statements in it can be pre-parsed for IE and included using standard conditional comments in the HTML.
Allan has generators for PHP, C, and C#. You upload the CSS and it spits out what you need. There are also advanced usage.
Thursday, August 7th, 2008
Category: CSS
, Standards
, W3C

Bert Bos, a W3C fellow, thinks that CSS variables are to be considered harmful:
Adding any form of macros or additional scopes and indirections, including symbolic constants, is not just redundant, but changes CSS in ways that make it unsuitable for its intended audience. Given that there is currently no alternative to CSS, these things must not be added.
He has some very compelling points in there, some of which I agree with, and others that I don't:
This PHP version proves that it is not necessary to add constants to CSS. Just like the existence of the WebKit implementation cannot be taken as proof that constants in CSS are useful, so the PHP implementation cannot prove that either. But the PHP implementation has the benefit of letting authors determine the usefulness for themselves, without modifying CSS on the Web.
You can obviously use pre-processors to do many macro situations. This doesn't mean that it is the right place for functionality like this. I don't want to force every CSS request through PHP. I also like having functionality in CSS itself, as that can be shared across projects and developers without "oh, and by the way this looks a little different as we pre-process it with a magic Rails action". Something as important as variables should be low level IMO.
It is quite likely that somebody who is trying to learn CSS will give up learning it when he sees that style sheets that occur on the Web don't actually look like the tutorials he started from. Difference in upper- and lowercase or in pretty-printing are hindrances to learning, too, but limited ones: you soon learn to ignore those differences. But symbolic constants are different in each style sheet and have to be interpreted and understood each time anew.
A touch too strong. Things change. Tutorials get out of date. C'est la vie. And, you can always use old form.... and the feature is so simple that it won't take you weeks to work it out!
People who understand CSS in principle may still have trouble understanding the indirection provided by the em unit, many have trouble with the advanced selectors in level 3, and many more won't understand, e.g., any of the properties that have to do with bi-directionality or vertical text. For each feature that is added to CSS there must be a careful balance (based on an informed guess, because these things are difficult to test) between the number of users that will be excluded by that feature and the number for whom it is essential that it be added.
I agree in the balance. There are some crazy complicated parts of CSS. However, simple variables is trivial in comparison! Also, I think it will be used a hell of a lot more frequently.
Treating symbolic constants as an independent module would make them available for use in other contexts than CSS, would make them available to precisely the people who need them without hindering other people, would allow them to be developed without impact on CSS, and allow them to be developed more easily into what they are sure to develop into anyway: full macros, able to replace anything, not just CSS values, and able to make files shorter instead of longer.
I agree about modularity. There will be issues with scope and such, and we will have to fight to keep the system as simple as possible.
However, I can't wait to be able to re-skin something by changing the variables only that represent semantic parts of my application. Search and replace isn't good enough. Having tools that see the #xxxxxx and show you a color aren't good enough. You end up reading a lot more CSS than you write, so we should help that use case. I don't think CSS should become a programming language with if statements and the like, and I doubt this is a gateway drug to that.
Thursday, July 17th, 2008
Category: CSS
, IE
Ah the age old IEPNGFix solution to the problem that we had with IE 5.5 / 6.0 not supporting alpha transparency. The first IEPNGFix solved the problem:
This script adds near-native PNG support with alpha opacity to IE 5.5 and 6. Now you can have full translucency and no more ugly grey borders! It requires only one line in your CSS file, and no changes to your website HTML. <IMG> tags and background images are both supported.
Now we have a new version that adds the ability to use CSS1 compatible background position and repeat.
Monday, June 30th, 2008
Category: CSS
, Safari
We talked about how CSS variables are next a few months back, and now they are here!
Once again, via Dylan Schiemann.
Friday, June 27th, 2008
Category: CSS
, Tip
CSS:
#indirect-example1 h4 + p,
#indirect-example2 h4 ~ p {
background-color: #CCC; color: #F00;
}
Eric Wendelin has taken a look at the general sibling combinator shown above as:
This would affect each <p> element that is a sibling of a preceding <h4> element. This is different from the Adjacent Sibling Combinator (+) in that it affects all following <p> siblings instead of just the immediate sibling. It is very well supported: IE7+, FF2+, Opera 9.5+, Safari 3+, and even Konqueror.
Thursday, June 26th, 2008
Category: CSS
, Yahoo!
Our own Christian Heilmann has created a new JavaScript library Autogrid that marries YUI Grids, the base CSS library, to allow for smart resizing:
I love YUI Grids. I know my CSS and I know how to work around diff erent problems of browsers, but I am also very much bored about having to fix and test and create these workarounds over and over again. While YUI Grids might not be perfect for all cases of web development out there, I am happy to take a pragmatic approach and just create sites that can be done with them (now you also know why I am not a designer).
One problem I keep having when I put some YUI Grids-based sites live is that people complain about me expecting a certain screen resolution or viewport size. YUI grids can either be 100% wide, which can be pretty silly on high resolutions, or optimized for resolutions of either 800×600 or 1024×768. When you optimize for 800 pixels people on higher resolutions will complain about the length of the page and when you go for 1024 people will say they have to scroll to see your side-bar on 800×600. You can’t win.
Or can you? CSS is not dynamic  it has a fixed state and you can only hope that the browser does the right thing with what you give it (well, there are conditional comments for IE, but technically they are HTML, and of course there are media queries in CSS3 and other goodies, but for the sake of the argument let’s say supporting IE6 is a base). JavaScript, on the other hand, is very dynamic and you can read out and check what is happening to the browser currently in use and react to it.
Putting this feature of JavaScript to good use you can create a YUI-Grids-based layout that remains flexible and changes according to needs. All you need to do is use some YUI Dom magic and change IDs and classes accordingly.
Christian has a demonstration page, and the full code:
JAVASCRIPT:
YAHOO.example.autoGrid = function(){
var container = YAHOO.util.Dom.get('doc') ||
YAHOO.util.Dom.get('doc2') ||
YAHOO.util.Dom.get('doc4') ||
YAHOO.util.Dom.get('doc3') ||
YAHOO.util.Dom.get('doc-custom');
if(container){
var sidebar = null;
var classes = container.className;
if(classes.match(/yui-t[1-3]|yui-left/)){
var sidebar = 'left';
}
if(classes.match(/yui-t[4-6]|yui-right/)){
var sidebar = 'right';
}
function switchGrid(){
var currentWidth = YAHOO.util.Dom.getViewportWidth();
if(currentWidth> 950){
container.id = 'doc2';
if(sidebar){
container.className = sidebar === 'left' ? 'yui-t3' : 'yui-t6';
}
}
if(currentWidth <950){
container.id = 'doc';
if(sidebar){
container.className = sidebar === 'left' ? 'yui-t2' : 'yui-t5';
}
}
if(currentWidth <760){
container.id = 'doc3';
if(sidebar){
container.className = sidebar === 'left' ? 'yui-t1' : 'yui-t4';
}
}
if(currentWidth <600){
container.id = 'doc3';
container.className = '';
}
};
switchGrid();
/*
Throttle by Nicholas Zakas to work around MSIE's resize nasties.
http://www.nczonline.net/blog/2007/11/30/the_throttle_function
*/
function throttle(method, scope) {
clearTimeout(method._tId);
method._tId= setTimeout(function(){
method.call(scope);
}, 100);
};
YAHOO.util.Event.on(window,'resize',function(){
throttle(YAHOO.example.autoGrid.switch,window);
});
};
return {
switch:switchGrid
};
}();
We continue to see JavaScript libraries working with CSS to great effect.
Monday, June 2nd, 2008
Category: CSS
, Tip

Thomas Fuchs is having some fun at RailsConf, and sent out a fun use of the new WebKit transformations using the medium of the bookmarklet:
JAVASCRIPT:
javascript:document.body.style['-webkit-transform']='rotate(180deg)';
javascript:document.body.style['-webkit-transform']='rotate('+prompt('degrees',180)+'deg)';
Use this bookmarklet (drag to bookmarks bar):
flip
or this one if you want a prompt:
flip2.
Monday, May 26th, 2008
Category: CSS
, Standards
The CSS Namespace Module has now been bumped up to a "W3C Candidate Recommendation", thanks to the work of Elika J. Etemad and Anne van Kesteren (who built on the earlier work of Peter Linss and Chris Lilley).
The module is simple, but will be a very welcome addition:
This CSS Namespaces module defines the syntax for using namespaces in CSS. It defines the @namespace rule for declaring the default namespace and binding namespaces to namespace prefixes, and it also defines a syntax that other specifications can adopt for using those prefixes in namespace-qualified names.
This example does a good job at showing the namespaces:
Given the namespace declarations:
CSS:
@namespace toto "http://toto.example.org";
@namespace "http://example.com/foo";
In a context where the default namespace applies:
toto|A:
represents the name A in the http://toto.example.org namespace. |B:
represents the name B that belongs to no namespace. *|C:
represents the name C in any namespace, including no namespace. D:
represents the name D in the http://example.com/foo namespace.
This is a good step, but what we really wait for is the support in major browsers!
Wednesday, May 21st, 2008
Category: CSS
, Ruby
We all want to use input[type=text] but browser support doesn't seem to quite be there (IE 6?).
This lead James Coglan down the path of creating a teeny Rails plugin, classy_inputs:
Good lord do I ever hate input tags. (YUI hates them too, but I’ll leave that story for another time). All the different types should really have been different tag names, and they are a total pain to use with CSS. As such, I used to end up doing tedious stuff like adding a :class option to every form element when writing Rails templates. A while back, I tried to patch Rails to get it to do this automatically, but its test suite totally baffled me at the time by applying the classes in some places but not others.
So, a quick plugin to stave off RSI:
script/plugin install
http://svn.jcoglan.com/classyinputs/trunk/classy_inputs
With that installed, any input tag created using a Rails view method will gain a class name matching its type attribute. Maybe I’ll have another stab at patching Rails, but I’m not promising anything.
Wednesday, May 14th, 2008
Category: CSS
, MooTools
Chris Schneider has created a javascript implementation of CSS Effects using the MooTools JavaScript library. It basically parses the css and mimics the new Webkit css animations.
With the introduction of CSS we could seperate the presentation layer and the content layer, but we were not able to add animations via CSS. DHTML fixed this misbehavior, but now the presentation and behaviour layer were mixed.
First I tried the concept of adding something like “-moofx-{property}: {from} {to};†to CSS. The disadvantage of this way is that you have to specify the change twice: First in regular CSS to serve the non-JavaScript-users, then for the animation.
After hearing about WebKit’s CSS Animations I changed my concept of CSS animations. Instead of setting an additional target or starting value, both properties are specified â€Ânormallyâ€Â. The only thing you have to add is a declaration.
The script uses MooTools soon to be release v1.2 and works in Safari 3, Firefox 2 and mostly Internet Explorer 7. The script degrades in Internet Explorer 6, because no dynamic pseudo-classes are supported.
You can see the script in action here.
Tuesday, May 13th, 2008
Category: CSS
, Fun
Matthew Buchanan had a little fun and created a Timelapse CSS example that lets you walk through the process of how a browser would put together a page if it was a human artist:
When building website templates, I’m constantly switching between a view of my CSS code and a view of the page I’m working on in a browser. At my most fevered I’m switching from one to the other after every couple of amendments, to ensure my additional rules are having the intended effect. Over time, were I to record this incremental buildup, it would paint a reasonably good picture of my approach to converting a design comp to a CSS layout.
With this in mind, I thought it might be useful to try to capture the process automatically and then play it back. I’ve seen this done using a collection of manual screen captures, but that didn’t seem a particularly elegant or easily reproducible solution.
As a proof of concept I cobbled together a (stylistically unsound) function to traverse the stylesheets of the current page (in reverse order) and remove a property from each rule every tenth of a second.
JAVASCRIPT:
function timelapseRemoveCss() {
var interval=0;
for(var i=document.styleSheets.length-1;i>=0;i--){
rules=document.styleSheets[i].cssRules;
for(var j=rules.length-1;j>=0;j--){
var attributes=rules[j].style.length;
for(var k=0;k<attributes ;k++){
interval+=100;
var timeout = "document.styleSheets["
+i+"].cssRules["+j+"].style"
+".removeProperty(document"
+".styleSheets["+i+"].cssRules["
+j+"].style["+0+"])";
setTimeout(timeout,interval);
}
}
}
}
Monday, May 12th, 2008
Category: Browsers
, CSS
, Performance
Are child selectors slower than more simple brethren? This is a question that Jon Sykes sought out data for after he read the work of Jim Barraud.
His conclusion?
The skinny is that child selectors are a major performance issue.
This seemed to make sense, but to me I needed some sort of proof rather than just being told it's that way by someone, so over the last two days I've tried two approaches to see if I can replicate the issue.
The first one was rather a half-assed idea that afterwards seems fundamentally flawed as a benchmark.
So I took a new approach which does seem to return some valid and rather interesting findings, particularly regarding Safari and Firefox 3 and how they react to child selectors and performance.
The tests show that there is slow down using child selectors over direct class name declarations in IE6, IE7 and Safari 3. Safari 3 being the most impacted by child selectors. Firefox 2 has some impact, and Firefox 3 doesn’t seem to be impacted at all.
That said, this is a very extreme test, it is not often you’d have 20,000 class definitions in a single page or that all of them would use 4 levels of child selector.

Next Page »