<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" ><channel><title>Web Directions &#187; Blog</title> <atom:link href="http://www.webdirections.org/category/blog/feed/" rel="self" type="application/rss+xml" /><link>http://www.webdirections.org</link> <description>Just another WordPress weblog</description> <lastBuildDate>Fri, 27 Jan 2012 00:02:10 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.2.1</generator> <item><title>Standards, innovation, Flash, ownership and all that</title><link>http://www.webdirections.org/blog/standards-innovation-flash-ownership-and-all-that/</link> <comments>http://www.webdirections.org/blog/standards-innovation-flash-ownership-and-all-that/#comments</comments> <pubDate>Wed, 09 Nov 2011 21:22:28 +0000</pubDate> <dc:creator>John</dc:creator> <category><![CDATA[Blog]]></category><guid isPermaLink="false">http://www.webdirections.org/?p=3906</guid> <description><![CDATA[It’s often argued (well, asserted might be a better way of putting it) that standards are an anathema to innovation, or at the very least a significant impediment to it. At its most extreme, this is used as an argument for disbanding the W3C, and even for core web technologies to become “a single source [...]]]></description> <content:encoded><![CDATA[<p>It’s often argued (well, asserted might be a better way of putting it) that standards are an anathema to innovation, or at the very least a <a href="w3c">significant impediment to it</a>.</p><p>At its most extreme, this is used as an argument for disbanding the W3C, and even for core web technologies to become “<a href="http://joehewitt.com/2011/09/22/web-technologies-need-an-owner">a single source repository [with] a good owner to drive it</a>.”</p><p>Occasionally history throws up curiously timely experiments. Right now we are seeing a very interesting one (and one with far reaching consequences) play out.</p><p>Since the middle to late 18th Century, with the <a href="http://en.wikipedia.org/wiki/Enclosure">enclosure of the commons</a>, and the rise of industrial capitalism, the belief that ownership and property rights is what has largely driven advancements in our civilisation has become almost all pervasive. It lies at the heart of the, until relatively recently alien, concept of intellectual property (increasingly seen as a bane not boon for innovation).</p><p>So, what does this have to do with the clear demise of Flash on mobile? Flash has an owner. One that had, and continues to have large revenues, teams of very smart people, deep pockets.</p><p>Despite all this, Flash failed to adapt to changing technological circumstances, and withered on the vine.</p><p>In parallel, core web technologies have slowly, inexorably grown more sophisticated, organically, iteratively, cooperatively adding capabilities that, for the most part developers clearly want and need.</p><p>Let’s take an example I used in a <a href="http://www.webdirections.org/resources/john-allsopp-the-dao-of-web-design-revisited/">recent presentation</a>. The DOM, while powerful, has long been a pain for developers to really get to grips with. Recognizing this, various libraries, and most famously jQuery, came up with more developer friendly ways of accessing it. jQuery’s use of CSS selector concepts proved immediately popular, and in short order, the W3C began work on the <a href="http://www.w3.org/TR/selectors-api/">Selectors API</a>, while browsers also within a relatively short time frame began implementing this API.</p><p>An ownership model is different. The owner of a platform or technology makes strategic decisions, and long term bets on what will be successful. Those bets may of course pay off tremendously (as in the case of iOS). But they may not, and very often do not, as in the case of Flash.</p><p>Standards bodies are not imune to the ownership model of development. XHTML2 is a decade long demonstration of that.</p><p>Technologies with the ownership model seem less capable of adapting to change, and are very dependent on initial conditions.  The cooperative, collaborative standards based approach (characterised best by the <a href="http://www.ietf.org/tao.html">IETF’s founding principle of “rough consensus and working code”</a>) often seems to build technologies that weather the storms of technological, social and political change far better.</p><p>It’s ironic, that the apparently “capitalist” “ownership” model is really much more like the central planned economic model of former socialist countries, while the W3 model more closely approximates how the societies of economically liberal countries work.</p><p>Neither model is going away soon. Each will have its successes and its failures. But I think it is time to put to bed the far too pervasive meme that standards are in some way an impediment to innovation. After all, take a look at the web. Built on standards (TCP/IP, http, HTML, CSS, EMCMAScript, the DOM), it’s doing ok. Better than OK I’d suggest.</p> ]]></content:encoded> <wfw:commentRss>http://www.webdirections.org/blog/standards-innovation-flash-ownership-and-all-that/feed/</wfw:commentRss> <slash:comments>4</slash:comments> </item> <item><title>The Next 6 Billion</title><link>http://www.webdirections.org/blog/the-next-6-billion/</link> <comments>http://www.webdirections.org/blog/the-next-6-billion/#comments</comments> <pubDate>Thu, 20 Oct 2011 02:28:07 +0000</pubDate> <dc:creator>John</dc:creator> <category><![CDATA[Blog]]></category><guid isPermaLink="false">http://www.webdirections.org/?p=3734</guid> <description><![CDATA[Some time this month, for the first time, there will be 7 Billion people alive on earth. In around 14 years, the United Nations predicts our population will reach 8 Billion. These are numbers the human mind has not evolved to intuitively understand. According to most estimates just over 2 billion currently use the internet [...]]]></description> <content:encoded><![CDATA[<p>Some time this month, for the first time, there will be 7 Billion people alive on earth. In around 14 years, the United Nations predicts our population will reach 8 Billion. These are numbers the human mind has not evolved to intuitively understand.</p><p>According to <a href="http://www.internetworldstats.com/stats.htm">most estimates</a> just over 2 billion currently use the internet regularly (in ten years this has grown from around 360 million).</p><p>The growth in the web’s use, even in purely numerical terms is almost incomprehensibly dramatic. From .4% of the world’s population in 1995, to 5.9% in 2000, 13.9% in 2005, to today’s 30.4%.</p><p>When you add in the global and cultural reach of the web — currently 11% of the population of Africa, 24% of Asia, 31% of the middle east, as well as around 40% of Europe and Oceania, and nearly 80% of North America — then it’s clear we are seeing a global phenomenon the scale and breadth of which is unlike anything see in human history.</p><p>Which is in fact <a href="http://www.w3.org/People/Berners-Lee/UU.html">no accident</a>.</p><blockquote><p> The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect</p></blockquote><p>Lately, there has been a lot of concern expressed, by intelligent, experienced people I have a lot of respect for, about the future of the web, about its very viability.</p><p>I’ve engaged folks like Joe Hewitt in <a href="http://joehewitt.com/2011/09/22/web-technologies-need-an-owner">strenuous</a>, but I believe healthy and important <a href="http://www.webdirections.org/blog/the-web-is-a-different-problem/">debate</a> about these issues.</p><p>As I considered in my recent Web Directions presentation, <a href="http://south11.webdirections.org/program/big-picture#the-dao-of-web-design-revisited">A Dao of Web Design Revisited</a> (article, slides and audio recording coming soon), I feel that many of these concerns strangely, uncannily, echo those which prompted my original <a href="http://www.alistapart.com/articles/dao/">Dao of Web Design</a> article back in 2000.</p><p>A <a href="https://twitter.com/leaverou/status/126296891876052992">recent tweet</a> by <a href="http://aralbalkan.com/">Aral Balkan</a> (once again, a passionate, intelligent contributor to the web, who has spoken at our events, and hopefully will do again), retweeted by <a href="http://leaverou.me/">Lea Verou</a> (another generous contributor to the web, and again, one of our past, and I hope future speakers) really captured for me the essence of the issue</p><blockquote><p> #oneversion #manifesto My websites will only support the latest versions of browsers. It’s the browser makers’ duty to get users to upgrade.</p></blockquote><p><a href="https://twitter.com/leaverou/status/126296891876052992">Aral Balkan, Twitter, October 20 2011</a></p><p>So, what does this tweet, and predictions of world population have to do with one another?</p><p>I love the shiny stuff of the web — the <a href="http://www.webdirections.org/blog/css3-radial-gradients/">gradients</a> and <a href="http://www.webdirections.org/blog/let-the-web-move-you-css3-animations-and-transitions/">animations</a>, the <a href="http://www.webdirections.org/blog/2d-transforms-in-css3/">transforms</a>. As someone who has developed for the web for nearly 18 years, the ever increasing sophistication of the DOM, of JavaScript, the increase in the speed of JS engines, of rendering, the arrival of mobile platforms, and micro-mobile platforms for the web excite me as a user and a developer. But, they aren’t what gets me up in the morning. They aren’t what fires me up like no other platform before (I built my first Mac apps in 1986, and have had commercially available Mac OS apps continuously since 1994, and Windows apps since  1996).</p><p>What really, at the not so tender age of 45, keeps me as passionate and excited about building stuff as I was when about 16 and got my first <a href="http://www.classic-computers.org.nz/system-80/">TRS80 clone</a> is the potential for the web to transform our world for the better. And overarching all this is the question, the challenge, how do we get the next 2 billion online, and ultimately, the next 6 billion people online?</p><p>This might not float your boat. And that’s fine. You might consider it an ideological position. And that’s your prerogative. But I know I’m not alone in believing that the potential, the promise, and in the face of overwhelming planet-wide challenges — anthropogenic climate change, global pandemics to name just two which our generation, and particularly my children’s generation will have to increasingly confront — the necessity of bringing our planet together, and enabling all of us to collaborate, share, communicate, without the friction of borders, is something only the web can hope to achieve.</p><p>Universality is a founding principle of the web. <strong>It</strong> is the manifesto the web has been built on, and I believe one of the key drivers of the almost unimaginable success of the web over these last two decades. We ignore that at the web’s peril.</p><p>The web alone, not iOS, or Android, or Windows Phone, or any other platform can possibly connect the next 6 billion. Yes, some, many of those 6 billion will be accessing the web via iOS, some via Android devices, some Windows Phone.</p><p>But, this next six billion is children in rural India, Africa, China where access to power, and networks, may be intermittent. It’s someone in Sumatra at a decade old Wintel box. It’s people who speak hundreds of different languages, with dozens of different writing systems. It’s people who are the first in their family to be able to read and write. It’s the 20% of people worldwide who can’t read or write. Yet.</p><p>So, to say “My websites will only support the latest versions of browsers”, you are in a sense saying, “I’m going to make the fact that developing for the web is harder than it would be if I concern myself with browsers other than the latest is not my problem, and not even the browser makers problem, it’s the problem of the next 6 billion. It’s not my problem, it’s the problem of the child in rural India, Africa, China.”</p><p>The truth is, the challenge of universality <strong>is</strong> daunting. It <strong>is</strong> hard work. But to me at least, paying this forward is the quid pro quo of the enormous privilege I’ve been granted to work on the web, which has given me fascinating well paid work, connections with thousands of intelligent, passionate, generous people around the world, and the opportunity to participate, in however insignificant a way, in something genuinely extraordinary, something unique. I can pay this forward by including rather than excluding people. By, in my own small way, helping ensure that the next 6 billion will be able to share in the privilege that I, you and the first 2 billion share in.</p><p>Which is not to say we shouldn’t continue to develop the capabilities of web technologies. It is not to say we shouldn’t continually explore what these technologies enable us to do.</p><p>But to me at least, we owe it to the web to do this in a way that is generous to the web in the way the web has been generous to us.</p><p>To reformulate the now famous question Steve Jobs asked of John Sculley:</p><p>Do you want to make shiny products for the privileged for the rest of your life, or do you want to come with me and change the world?</p> ]]></content:encoded> <wfw:commentRss>http://www.webdirections.org/blog/the-next-6-billion/feed/</wfw:commentRss> <slash:comments>39</slash:comments> </item> <item><title>Web Directions South 2011</title><link>http://www.webdirections.org/blog/web-directions-south-2011/</link> <comments>http://www.webdirections.org/blog/web-directions-south-2011/#comments</comments> <pubDate>Mon, 17 Oct 2011 03:16:40 +0000</pubDate> <dc:creator>John</dc:creator> <category><![CDATA[Blog]]></category><guid isPermaLink="false">http://www.webdirections.org/?p=3710</guid> <description><![CDATA[When you work on something for an extended period of time but which itself lasts itself only a brief moment, such as Maxine and I do with Web Directions, there’s an intensity to the event itself, and the strange mixture of relief (and exhaustion) coupled with nostalgia when it has come and gone. Luckily, through [...]]]></description> <content:encoded><![CDATA[<p>When you work on something for an extended period of time but which itself lasts itself only a brief moment, such as <a href="http://twitter.com/maxine">Maxine</a> and I do with Web Directions, there’s an intensity to the event itself, and the strange mixture of relief (and exhaustion) coupled with nostalgia when it has come and gone.</p><p>Luckily, through <a href="http://www.flickr.com/search/?q=wds11">photos</a>, <a href="https://twitter.com/#!/search/wds11">tweets</a>, <a href="http://weblog.200ok.com.au/2011/10/wds11-big-stonking-post.html">blog</a> and Facebook posts and even the odd <a href="http://topsy.com/vimeo.com/25355309">video</a>, increasingly an event like Web Directions is <a href="http://www.webdirections.org/resources/">captured in more than just our memory</a>.</p><p><img src="http://farm7.static.flickr.com/6152/6242763364_df1f5178fd.jpg" alt="Web Directions South crowd, engaged and enthused."></p><p>Web Directions South, held last week, was the sixth annual Web Directions event we’ve run in Sydney, and though likely we feel this every year, it was in our estimation, and indeed of so many we spoke to, and based on many tweets we’ve read the best we’ve done by far.</p><p>The atmosphere was incredibly positive, (reflected in everything from the twitter stream, to the crowds who refused to go home, staying long into the night at the closing night party).</p><p>A new generation of partner companies, almost all from Australia and New Zealand, and most of which did not exist when Web Directions started back in 2006 companies shouted great parties, competitions, and most importantly showcased the sophistication and breadth (as well as spirit of fun) of the Australian web industry.</p><p>Similarly, while many of the speakers, local and international, may have been unknown to our audience, they excelled–educating, inspiring and entertaining. From opening keynote to closing, never have we seen such uniformly positive responses to a program.</p><p>Every presentation we had the privilege to see, as well as all those we didn’t but which we heard amazing things about, was world class.</p><p>Whether you were there, or missed out, as the podcasts and slides from presentations come online, we’ll tweet about them (so if you don’t already, <a href="http://twitter.com/webdirections">you really should follow us on Twitter</a>. Meanwhile, you can catch up on <a href="http://www.webdirections.org/resources/">hundreds of past presentations</a> from our conferences around the world from the last several years.</p><p>And, as a special treat, coming soon is a slickly produced video version of <a href="http://south11.webdirections.org/program/keynotes#the-robot-readable-world">James Bridle’s amazing closing keynote</a>, thanks to <a href="http://www.huntingwithpixels.com.au/hwp/welcome">Hunting with Pixels</a>.</p><p>In the meantime, Ben Buchanan has already made available his traditional <a href="http://weblog.200ok.com.au/2011/10/wds11-big-stonking-post.html">big stonking post™</a> with detailed live notes, links, and photos from a dozen presentations. So, if you missed it, and can bare to see what you missed out on, it’s a great place to start.</p><h4>Thanks!</h4><ul><li>A huge thanks to our wonderful sponsors, partners and exhibitors</li><li>To our <a href="http://south11.webdirections.org/program/speakers">incredibly generous speakers</a></li><li>To <a href="http://www.webdirections.org/resources/">Cameron Adams</a> for the opening sequence, setting a new standard for creativity with Web Technologies</li><li>To the <a href="http://sydney.edu.au/architecture/design_lab/">Design Computing program at the University of Sydney</a> for their incredible exhibition of interactive technology</li><li>To the <a href="http://www.w3c.org.au/">W3C Australia Office</a> for once again hosting the W3C South Track</li><li>And not least to the fantastic, positive, open minded, engaged audience.</li></ul> ]]></content:encoded> <wfw:commentRss>http://www.webdirections.org/blog/web-directions-south-2011/feed/</wfw:commentRss> <slash:comments>4</slash:comments> </item> <item><title>The challenge of WYSIWYG development for the web</title><link>http://www.webdirections.org/blog/the-challenge-of-wysiwyg-development-for-the-web/</link> <comments>http://www.webdirections.org/blog/the-challenge-of-wysiwyg-development-for-the-web/#comments</comments> <pubDate>Tue, 27 Sep 2011 04:04:56 +0000</pubDate> <dc:creator>John</dc:creator> <category><![CDATA[Blog]]></category><guid isPermaLink="false">http://www.webdirections.org/?p=3696</guid> <description><![CDATA[This is the first in what I hope will be a number of articles I’m writing to clarify my thinking in the lead up to my Dao of Web Design Revisited presentation at this years Web Directions South. In the middle 1990s, by an accident of fate and coincidence far too tedious to go into [...]]]></description> <content:encoded><![CDATA[<p><em>This is the first in what I hope will be a number of articles I’m writing to clarify my thinking in the lead up to my <a href="http://south11.webdirections.org/program/bigpicture#the-dao-of-web-design-revisited">Dao of Web Design Revisited</a> presentation at this years <a href="http://south11.webdirections.org/">Web Directions South</a>.</em></p><p>In the middle 1990s, by an accident of fate and coincidence far too tedious to go into here, I found myself teaching some of the earliest web related courses at <a href="https://www.tafensw.edu.au/">TAFENSW</a>. A lot of my focus was in getting students to think conceptually about document structure, linking, interactive tables of contents and so on. Very little was about HTML. Indeed, so convinced was I that WYSIWYG editing was just around the corner, I felt it a waste of their time learning markup (this was pre CSS, but that’s another story). We used Claris HomePage, a surprisingly useful application, to develop web sites as part of these courses.</p><p>Pretty much everyone at the time felt that actually working at the markup level for the web would go the way of assembly programming.</p><p>There were reasonable precedents to this belief. Desktop publishing in the middle 1980s (really only around 10 years before this time) had revolutionized traditionally markup based print page layout (and more or less given the world the term WYSIWYG).</p><p>And, around <strong>that</strong> same time (the middle and latter half of the 1980s), I was studying Computer Science at University, where for our final year major project, we were the first cohort to no longer use COBOL (I kid you not). Rather we used a 4GL named Omnis (4GLs or <strong>Fourth Generation Languages</strong> were supposed to abstract away all the messy stuff when developing complex applications). The consensus was (and this was a classic CS program with lots of C, and algorithms and stuff) that the traditional approach to programming was going the way of assembly language.</p><p>4GLs live on in systems like 4D, but you would have shocked us all back then if you said that we’d still be using 3GLs without even garbage collection today.</p><p>So, why did WYSIWYG revolutionize print design, but not application development?</p><p>Similarly, despite the success of, above all DreamWeaver, and to a lesser extent other WYSIWYG web development tools, we’re still very much working at the codeface (I don’t think I know any professional web developers who use a WYSIWYG tool these days, though many, myself included, once did).</p><p>But why is that? Will it always be the case? Or will one day someone crack the code (literally and metaphorically) and deliver a WYSIWYG tool that liberates us from the “grind” of coding.</p><p>But first, let’s consider why WYSIWYG was so successful in the world of print. I’d suggest a big part of that success was that is possible to map every aspect of a printed page onto the screen (or better, into the internal model of the software). You can even map colors onto a grayscale screen, which many desktop publishing systems were in the mid 1980s, color screens were seriously expensive. So, there was little if any need for metaphor or abstraction. This part of the page right here, will be pantone color whatever. And this little bit over here, will be white. And so on.</p><p>The problem space of printed page layout was sufficiently constrained that everything the designer might want to do, they could do with DTP software. I’d argue that a constrained “possibility space” is a key requirement for WYSIWYG systems to really work.</p><p>So, what about the web? <a href="http://en.wikipedia.org/wiki/Douglas_Engelbart">Douglas Engelbart</a>, one of the giants of modern computing, coined the term “WYSIAYG” (what you see is <strong>all</strong> you get), which I think captures the challenge faced in developing web development tools, and software tools more generally. With desktop publishing, all you get is all you need. As we saw, the space of possible outcomes can be mapped into a set of tools.</p><p>But with the web (even leaving aside JavaScript and the DOM), the possibility space is I’d argue, too open ended to map well onto any WYSIWYG software. So the designer of development tools needs to decide what the <strong>all</strong> is. Unlike print design, where the problem was constrained by the medium, with the web, software designers constrain the problem space.</p><p>So, if <strong>you</strong> were developing a “WYSIWYG” web development tool, how would you enable your users to make the first paragraph after a heading of level 2, in the introductory section of a document bold? You could allow users to add a class (though you may or may not use that term) to that particular page object (or do you call them elements?). Or, you could provide an interface that is familiar from word processors, where the user selects text, and a bold tool, and behind the scenes the software adds a strong element (to code the user will never see). Or you might add inline style of bold to that paragraph.</p><p>And this is about as simple a scenario as it gets. No interaction. Just styled text based on document structure.</p><p>Now, what if a document is divided into chapters. And what if the designer wants the first line in the first paragraph in each chapter to be capitalized? Or every other row in a table to have a given background color?</p><p>The best possible approach to these particular challenges at the markup and CSS level is likely to use structural selectors (e.g. nth-child). But how to intuit from the users’ actions their intent, and map that intent onto the capabilities of CSS?</p><p>And we <strong>still</strong> haven’t even introduced any interactivity to the challenge yet.</p><p>This isn’t simply a theoretical issue for me. I’ve been developing the CSS Editor <a href="http://westciv.com/style_master/">Style Master</a> for well over a decade. One of the design principles for it has been to never hide the underlying CSS concepts behind metaphors and abstractions. Rather, the goal is to make understanding, and using, these powerful features of CSS easier, more productive, and more enjoyable. This same design principle informs my work on various CSS3 tools, for example my <a href="http://westciv.com/tools/gradientsnustyle/index.html">gradient</a> and <a href="http://westciv.com/tools/animations/">animation</a> tools. While other tools (and this is not a criticism, simply an observation), create metaphors (for example, provide a Photoshop-like interface for creating gradients), I emphasise a direct correspondence between the objects you manipulate, and the underlying CSS concepts.</p><p>But, to return to the question, is WYSIWYG possible for the web? I actually think that it is, but not in general. But in situations where a specific problem is sufficiently constrained, I think we can provide WYSIWYG tools. Which means the approach Adobe is taking with <a href="http://muse.adobe.com/">MUSE</a>, will run up against the same challenges that all general purpose WYSIWYG web development tools have. That’s not to say it might not be very useful, but will be so within the constraints of its capabilities, of the problem space its designers have chosen to map.</p><p>Where I do think WYSIWYG can be, and already often is very successful is in constrained problem spaces. Blog posting is a particular example. An area I’m focussing on right now is presentations, which I believe is sufficiently constrained to make a WYWIWYG approach meaningful (but even here, I think being able to bust out an editor for markup, CSS or JS is important).<br /> Ironically, you could create a WYSIWYG print design tool with web technologies, for precisely the same reason you can do it with other languages and development platforms.</p><p>In essence, the set of problems the web presents developers and designers is open ended in a way that no other system is. Viewport sizes can range from <a href="http://developer.sonyericsson.com/wportal/devworld/article/liveviewannouncement?cc=gb&#038;lc=en">128 x 128 pixels</a> (or less) to 3840 x 2160, and no doubt beyond. Pixel density, color depth, available fonts, all of these will vary dramatically. Then there’s varying levels of support for CSS, HTML, DOM, SVG. There’s varying network speeds, drastic performance differences. Different input methods (mouse, keyboard, touch, Kinect, …) And none of these are going away. They are getting “worse” (which ironically means better — because more diversity among these characteristics means more people are using the web in more ways, which is good). The fact it causes challenges for designers and developers is essentially irrelevant. That’s our problem.</p><p>The search for an over-arching WYSIWYG solution to the challenge of developing for the web reflects our ongoing misconception of what the web is. It’s a medium unlike those which it is in some ways conceptually built on — be that paper, TV or desktop platforms like Windows. It’s understandable that we want it to be more like these. We know them well, we’re comfortable with their concepts and techniques. We’ve invested hugely in technology and expertise to design and develop for them. The web continues to make us uncomfortable. As it should. It is something new, and exciting, and challenging, and unfinished. What we see is never going to be all web get. That’s the challenge, and beauty, of the web.</p> ]]></content:encoded> <wfw:commentRss>http://www.webdirections.org/blog/the-challenge-of-wysiwyg-development-for-the-web/feed/</wfw:commentRss> <slash:comments>7</slash:comments> </item> <item><title>The web is a different problem</title><link>http://www.webdirections.org/blog/the-web-is-a-different-problem/</link> <comments>http://www.webdirections.org/blog/the-web-is-a-different-problem/#comments</comments> <pubDate>Wed, 21 Sep 2011 05:30:50 +0000</pubDate> <dc:creator>John</dc:creator> <category><![CDATA[Blog]]></category><guid isPermaLink="false">http://www.webdirections.org/?p=3689</guid> <description><![CDATA[One of the most persistent criticisms of web technologies is that they evolve slowly, indeed, too slowly. Often the argument is raised that the process of standards is antithetical to “innovation” (for innovation read “making cool stuff up”). To contrast with this glacial change, we’re typically pointed toward the wonders of platforms like iOS and [...]]]></description> <content:encoded><![CDATA[<p>One of the most persistent criticisms of web technologies is that they evolve slowly, indeed, too slowly. Often the argument is raised that the process of standards is antithetical to “innovation” (for innovation read “making cool stuff up”).<p>To contrast with this glacial change, we’re typically pointed toward the wonders of platforms like iOS and Android, where change takes place at breakneck speed. Or we’re pointed toward any number of open source projects, for example SASS, to demonstrate that we can evolve web standards faster outside the W3C (afterall, CSS hasn’t kept place with SASS/LESS… therefor the W3C is clearly useless)</p><blockquote><p><a href="https://twitter.com/kneath/status/116293399845416961">Pretty sure that already happened. SCSS, Coffeescript, etc. The W3C doesn’t have influence anymore AFAIK</a></p></blockquote><p>And occasionally, this erupts in an orgy of revolutionary fervour, where we need to man the barricades, and</p><blockquote><p><a href="https://twitter.com/joehewitt/status/116292923288592384 ">dissolve the W3C</a>, and run the web like an open source project. No more specs, just commits. Does Linux need a standards body?</p></blockquote><p>I guess Joe hasn’t taken a look at the WHATWG’s “HTML“lately. An unversioned. constantly, continuously evolving potage, wherein creeps all kinds of at the every least questionable “innovations”, whose trajectory is unburdened by such trifling challenges as the need for intellectual property policies, or getting anyone to actually implement their stuff.</p><p>But let’s step back a pace. Is there really actually such a problem here? And if so, exactly what <strong>is</strong> that problem? And, are the proposals, to the extent they do exist, likely to help, or make matters worse?</p><p>Firstly, it <strong>is</strong> fair to say, that for the best part of the first decade of this century, we saw considerable stagnation in the development of web standards. The W3C went down the rabbit hole of XHTML2, and CSS 2 almost entirely stagnated (I’l have more to say on that in a second). During that time, innovation came almost entirely from developers discovering techniques which worked with existing browser capabilities, and through JavaScript libraries.</p><p>The last three or four years have however seen an explosion of innovation at the browser level. This has included:</p><ul><li>Huge improvements in the performance of JavaScript engines</li><li>Fantastic new CSS features, that have within a couple of years landed in all modern browsers</li><li>Sophisticated new APIs across a broad range of functionality, again now widespread across most if not all modern browsers (Selectors API, Geolocation, offline, localStorage, 2D and 3D canvas to name just a few)</li></ul><p>Before we throw the baby out with the bathwater, we should ask, is there a problem at all? Are we really seeing innovation — from standards proposal to widespread browser adoption in <a href="https://twitter.com/joehewitt/status/116294702000644096">the order of 10 years</a>?</p><p>Let’s take a look at an actual example. Dave Hyatt announced CSS Gradients in WebKit nightlies April 14th 2008. More or less simultaneously, Apple formally proposed these as part of CSS3. Gradients have been supported in Firefox since 3.6 (released Jan 2010), Opera since 11.1 (final release mid 2011), Internet Explorer 10 (developer releases early 2011). So, from first released and proposed as a standard to very widespread adoption in around 3 years.</p><p>We’ve seen similar timeframes for other CSS features, as well as “HTML5” features like the Selectors API, appcache, geolocation, localStorage.</p><p>So, to put it bluntly, I think the problem is overstated. We seem to have arrived at an approach that both enables the exploration and implementation of novel features in browsers, which are <strong>also</strong> widely adopted across browsers. It’s that second part that is most important, and I’ll return to it in a moment.</p><p>But I also want to quickly address why I think we seem to have thrown off the stagnation of previous years. I’d argue it comes down to stepping back from the monolithic approach of earlier W3C recommendations (CSS 1 and 2, XHTML2, SVG), toward a much more modular approach, as exemplified by CSS3, but as also seen with geolocation and the selectors API. A corollary to this is, I’d argue, that HTML5 is too monolithic and needs to be fragmented (which in some ways is happening).</p><p>But back to the real issue. The web is a different problem. It makes little if any sense to compare innovation of the web ecosystem with that of iOS, Android or other platforms. The web faces challenges far far greater (and has goals far more important). A platform such as iOS can abandon legacy applications, content and hardware, (along with their users) with little compunction. It can (and does) make developers and content creators wishing to participate jump through any number of hoops. It has a single dictatorial decision maker, beholden to no one, and nothing other than itself. And it generates extraordinary revenues, which can be reinvested into the ongoing development of the platform.</p><p>The web is different. It values interoperablity, backwards compatibility. It’s goal is to bring access to the same information to billions across the world, on all manner of devices.<br /> Its custodians are, in my opinion, scandalously under-resourced, given just how much wealth the web has created for so many, perhaps above all Google and Apple.</p><p>Without the web, Google would not exist, and Apple’s core engine of growth, iOS devices would essentially not either.</p><p>So, rather than generally criticising the W3C, or going so far as calling for its dissolution, we should focus on how well in many ways it has done an almost impossible task — getting companies which are fierce commercial rivals to sit down, work together and agree on core technologies they will each, and all, implement, even while at the same time, these same competitors are involved in significant legal conflicts with one another.</p><p>Can the W3C be improved? Certainly. But before suggesting solutions, let’s identify, and demonstrate with evidence, genuine problems. Then, when devising solutions, it pays to ask what evidence there is that those solutions will not only solve the problems identified, but also ensure the ongoing cooperation that has given rise to the web.</p> ]]></content:encoded> <wfw:commentRss>http://www.webdirections.org/blog/the-web-is-a-different-problem/feed/</wfw:commentRss> <slash:comments>18</slash:comments> </item> <item><title>2D Transforms in CSS3</title><link>http://www.webdirections.org/blog/2d-transforms-in-css3/</link> <comments>http://www.webdirections.org/blog/2d-transforms-in-css3/#comments</comments> <pubDate>Wed, 21 Sep 2011 00:59:43 +0000</pubDate> <dc:creator>John</dc:creator> <category><![CDATA[Blog]]></category> <category><![CDATA[developer]]></category> <category><![CDATA[2D Transforms]]></category> <category><![CDATA[css3]]></category> <category><![CDATA[Transforms]]></category><guid isPermaLink="false">http://www.webdirections.org/?p=3664</guid> <description><![CDATA[One of the most powerful features of CSS3 are transforms, which allow us to take any element in an HTML document, and while not changing its effect on the page layout, rotate it, translate it (move it left, right, up and down), skew it and scale it. CSS3 provides both 2D and 3D transforms, but [...]]]></description> <content:encoded><![CDATA[<p>One of the most powerful features of CSS3 are transforms, which allow us to take any element in an HTML document, and while not changing its effect on the page layout, rotate it, translate it (move it left, right, up and down), skew it  and scale it. CSS3 provides both 2D and 3D transforms, but while 2D transforms are supported in all modern browsers, including IE9 and up, 3D transforms are currently only supported in Safari, Chrome and IE10.</p><p>In this article, we’ll take a look at how to use 2D transforms and the various transform functions (such as scale and rotate). We’ll also, as always, look at some gotchas when first working with transforms, and once again, there’s a <a href="http://westciv.com/tools/transforms/index.html">tool to help you play with transforms</a> (I developed it some time ago, but I’ve updated it significantly for this article).</p><h4>What transforms do</h4><p>As in many cases, an example is worth a thousand words, so let’s take a look at a couple, to illustrate how transforms work, as well as some of their most important aspects.</p><p id="example1">When you click or tap the button below, this paragraph is rotated by 45 degrees. It’s also scaled to 75% of the size it would otherwise be. However note how the rest of the page layout is not affected. That’s because transformations don’t change the box model of an element, and so leave the page layout unchanged.</p><p><button onclick="transformElement('#example1', 'scale(.75) rotate(45deg)')">Transform It!</button></p><p style="-webkit-transform: skew(32deg, 0deg); -moz-transform: skew(32deg, 0deg); -o-transform: skew(32deg, 0deg); -ms-transform: skew(32deg, 0deg); transform: skew(32deg, 0deg)">This element has been skewed horizontally and vertically. You can still select the text, and otherwise interact with the element, as you would if it weren’t transformed.</p><h4>Transforming elements</h4><p>The syntax for CSS transforms is in many ways straightforward. There are just two new properties to contend with — <code>transform</code>, and <code>transform-origin</code>. The first specifies the transforms we want applied (scaling, rotating and so on), while the second, which is optional, specifies the origin for this transformation (for example, do we rotate around the middle of the element, its top left hand corner, and so on).</p><h4>The <code>transform</code> property</h4><p>The <code>transform</code> property takes as its value one or more <strong>transform functions</strong>, which each specify a transformation. Let’s take a look at each of these different functions in detail. Functions all take the form of a function name, with a value inside round brackets (as indeed do all CSS functions). So for example, we translate horizontally with the function <code>translateX(200px)</code>.</p><p>OK, enough preliminaries, let’s start in with some actual transforming. We’ll start with the <code>translate</code> function.</p><h5><code>translate</code></h5><p>The <code>translate</code> function moves the contents of an element to the left (negative values) or right (positive values), and/or upwards (negative values) and downwards (positive values).</p><p><code>translate</code> takes one or two comma separated values. The first is the horizontal translation value. If there is a second, this is the vertical translation value, while if there is only one value, then the vertical translation is zero (that is, the element will only be translated horizontally).</p><p>In addition to the <code>translate</code> function, there are the related <code>translateX</code> and <code>translateY</code> functions, which only translate an element horizontally, or vertically, respectively. Translate functions take length or percentage values, and like CSS properties, require units for values other than zero.</p><p>But enough theory, why not have a play with them?</p><div class="transformed"><p><img style="display: block; width: 256px; border: solid black 1px; margin: 0 auto; padding: .2em" id="translateXY" alt="web directions logo" src="http://south11.webdirections.org/wp-content/themes/conf-theme-html5/images/logo.png"></p><div class="controls"><p><code id='translateXYCSS'>transform: translate(0, 0)</code></p><p><label for="translateX">Translate X:</label> <input name="translateX" id="translateX" type="range" min="-800" max="800" step="1" title="" value="0" onchange="translateThisXY()" /></p><p><label for="translateY">Translate Y:</label> <input name="translateY" id="translateY" type="range" min="-400" max="400" step="1" title="" value="0" onchange="translateThisXY()" /></p></div></div><p>We mentioned a moment ago that transforms don’t impact the layout of a page. There’s one area where this is not exactly true. If you translate the above element completely to the right, you’ll notice a horizontal scrollbar appears (or the page can now be scrolled to the right). While the page layout has not been changed, the <code>overflow</code> property of the transformed elements containing element is affected by transforms (Safari on Mac OS X Lion is an exception to this, and perhaps indicates where this sort of UX is headed, but for now, in desktop/laptop browsers other than this, the addition of a scrollbar will impact page layout).</p><div style="overflow: auto"><p id="example2">This element is scaled by 200% when you click the button below. Its containing div has an <code>overflow: auto</code>. So, scrollbars appear when the element is transformed. In many browsers this will cause the page to reflow.</p></div><p><button onclick="transformElement('#example2', 'scale(2)')">Transform It!</button></p><h5><code>scale</code></h5><p>The <code>scale</code> function lets us zoom an element up or down in size (all the while maintaining the dimensions of its box for the purposes of the layout of the page). The function name is <code>scale</code>, and it takes a number value-with a value of .5 meaning “scale to half the current size”, and of 2 meaning “scale to twice the current size”, and so on. So, if we want to make an element 75% of its current size, we use the property <code>transform: scale(.75)</code>. And that’s really all there is to it. Why not have a play with it?</p><div class="transformed"><p><img style="display: block; width: 256px; border: solid black 1px; margin: 0 auto; padding: .2em" id="scaleMe" alt="web directions logo" src="http://south11.webdirections.org/wp-content/themes/conf-theme-html5/images/logo.png"></p><div class="controls"><p><code id='scaleCSS'>transform: scale(1)</code></p><p><label for="scaleValue">scale:</label> <input name="scaleValue" id="scaleValue" type="range" min="0.1" max="5" step="0.1" title="" value="0.5" onchange="scaleThis()" /></p></div></div><p>It’s also possible to scale horizontally and vertically independently from one another, by using two comma separated numerical values for the <code>scale</code> property. The first value scales an element horizontally, and the second, vertically. Let’s take a look.</p><div class="transformed"><p><img style="display: block; width: 256px; border: solid black 1px; margin: 0 auto; padding: .2em" id="scaleMeHV" alt="web directions logo" src="http://south11.webdirections.org/wp-content/themes/conf-theme-html5/images/logo.png"></p><div class="controls"><p><code id='scaleHVCSS'>transform: scale(1, 1)</code></p><p><label for="hScaleValue">horizontal scale:</label> <input name="hScaleValue" id="hScaleValue" type="range" min="0.1" max="5" step="0.1" title="" value="0.5" onchange="scaleThisHV()" /></p><p><label for="vScaleValue">vertical scale:</label> <input name="vScaleValue" id="vScaleValue" type="range" min="0.1" max="5" step="0.1" title="" value="0.5" onchange="scaleThisHV()" /></p></div></div><p>As with <code>translate</code> there are two related scale functions, <code>scaleX</code>, and <code>scaleY</code>. <code>scaleX</code> scales only horizontally (<code>scaleX(2)</code> is the equivalent of <code>scale(2, 1)</code>), and <code>scaleY</code>, which scales only vertically (<code>scaleY(2)</code> is the equivalent of <code>scale(1, 2)</code>).</p><h5><code>rotate</code></h5><p>Rotating text and images is a common page design technique, until now difficult to achieve on the web without considerable hackery, if at all. Transforms make rotating an element easy.</p><p>The <code>rotate</code> function takes an angle value. If you’ve worked with <a href="http://www.webdirections.org/blog/css3-linear-gradients/">CSS linear gradients</a>, in particular the newer syntax, then you’ll have seen angle units before. There are several ways you can specify an angle in CSS.</p><h6>degrees</h6><p>As you most likely remember from school math, there are 360 degrees in a circle. So, when specifying a rotation of an element, 90 degrees is a quarter turn clockwise, 180 degrees is a half turn, 270 degrees is three quarters turn clockwise, and 360 degrees is a full revolution. Here these are below.</p><p style="height: 10em; padding-left: 4em"><span style="display: inline-block; -webkit-transform: rotate(90deg); -webkit-transform-origin: 0% 50%; -moz-transform: rotate(90deg); -moz-transform-origin: 0% 50%; -o-transform: rotate(90deg); -o-transform-origin: 0% 50%; -ms-transform: rotate(90deg); -ms-transform-origin: 0% 50%; transform: rotate(90deg); transform-origin: 0% 50%">rotate(90deg)</span> <span style="display: inline-block; -webkit-transform: rotate(180deg); -webkit-transform-origin: 50% 100%; -moz-transform: rotate(180deg); -moz-transform-origin: 50% 100%; -o-transform: rotate(180deg); -o-transform-origin: 50% 100%; -ms-transform: rotate(180deg); -ms-transform-origin: 50% 100%; transform: rotate(180deg); transform-origin: 50% 100%">rotate(180deg)</span> <span style="display: inline-block; -webkit-transform: rotate(270deg); -webkit-transform-origin: 100% 100%; -moz-transform: rotate(270deg); -moz-transform-origin: 0% 50%; -o-transform: rotate(270deg); -o-transform-origin: 0% 50%; -ms-transform: rotate(270deg); -ms-transform-origin: 0% 50%; transform: rotate(270deg); transform-origin: 0% 50%">rotate(270deg)</span> <span style="display: inline-block; -webkit-transform: rotate(360deg); -webkit-transform-origin: 0% 50%; -moz-transform: rotate(360deg); -moz-transform-origin: 0% 50%; -o-transform: rotate(360deg); -o-transform-origin: 0% 50%; -ms-transform: rotate(360deg); -ms-transform-origin: 0% 50%; transform: rotate(360deg); transform-origin: 0% 50%">rotate(360deg)</span></p><p>Of course, it is possible to rotate an element by an arbitrary angle, for example 34.6 degrees, like so</p><p style="height: 10em"><span style="display: inline-block; -webkit-transform: rotate(34.6deg); -webkit-transform-origin: 0% 50%; -moz-transform: rotate(34.6deg); -moz-transform-origin: 0% 50%; -o-transform: rotate(34.6deg); -o-transform-origin: 0% 50%; -ms-transform: rotate(34.6deg); -ms-transform-origin: 0% 50%; transform: rotate(34.6deg); transform-origin: 0% 50%">rotate(34.6deg)</span></p><p>But, there are other ways we can specify rotations.</p><dl><dt>turns</dt><dd>perhaps the simplest way to specify a rotation is with the <code>turn</code> value. We can rotate an element a quarter turn clockwise with the function <code>rotate(.25turn)</code>, half a turn with .5turn, three quarters of a turn with .75 turn, and a whole turn with the function <code>rotate(1turn)</code>. WebKit and Opera support the <code>turn</code> value, while Firefox (version 6) does not.</dd></dl><p style="height: 10em; padding-left: 4em"><span style="display: inline-block; -webkit-transform: rotate(.25turn); -webkit-transform-origin: 0% 50%; -moz-transform: rotate(.25turn); -moz-transform-origin: 0% 50%; -o-transform: rotate(.25turn); -o-transform-origin: 0% 50%; -ms-transform: rotate(.25turn); -ms-transform-origin: 0% 50%; transform: rotate(.25turn); transform-origin: 0% 50%">rotate(.25turn)</span> <span style="display: inline-block; -webkit-transform: rotate(.5turn); -webkit-transform-origin: 50% 100%; -moz-transform: rotate(.5turn); -moz-transform-origin: 50% 100%; -o-transform: rotate(.5turn); -o-transform-origin: 50% 100%; -ms-transform: rotate(.5turn); -ms-transform-origin: 50% 100%; transform: rotate(.5turn); transform-origin: 50% 100%">rotate(.5turn)</span> <span style="display: inline-block; -webkit-transform: rotate(.75turn); -webkit-transform-origin: 100% 100%; -moz-transform: rotate(.75turn); -moz-transform-origin: 0% 50%; -o-transform: rotate(.75turn); -o-transform-origin: 0% 50%; -ms-transform: rotate(.75turn); -ms-transform-origin: 0% 50%; transform: rotate(.75turn); transform-origin: 0% 50%">rotate(.75turn)</span> <span style="display: inline-block; -webkit-transform: rotate(1turn); -webkit-transform-origin: 0% 50%; -moz-transform: rotate(1turn); -moz-transform-origin: 0% 50%; -o-transform: rotate(1turn); -o-transform-origin: 0% 50%; -ms-transform: rotate(1turn); -ms-transform-origin: 0% 50%; transform: rotate(1turn); transform-origin: 0% 50%">rotate(1turn)</span></p><p>For completeness, it’s worth noting that there are two other possible angle units-radians (rad), and gradians (grad). Briefly, there are 400 gradians in a full rotation (so one grad is slightly larger than one degree), while there are 2π radians in a full rotation (radians are widely used in mathematics).</p><p>Now, if you think about rotating an element, then you might wonder what point of the element the rotation takes place around. For example — is it the center? Or one of the corners?</p><p id="rotate1" onmousedown="transformElement('#rotate1', 'rotate(360deg)')" onmouseup="transformElement('#rotate1', 'none')" style="background: #aaa; width: 80%; margin: 1em auto; -webkit-transform-origin: 0 0; -webkit-transition: all 1s; -moz-transform-origin: 0 0; -moz-transition: all 1s; -o-transform-origin: 0 0; -o-transition: all 1s; -ms-transform-origin: 0 0; -ms-transition: all 1s; transform-origin: 0 0; transition: all 1s;">This element rotates around the top left hand corner when you click or tap and hold it. (<code>transform: rotate(360deg)</code>)</p><p>We can in fact specify where the rotation (and as we’ll soon see, any transformation) takes place, using the <code>transform-origin</code> property. <code>transform-origin</code> takes two length or percentage values, which specify the horizontal and vertical “origin” of the transformation. In the above example, we have <code>transform-origin: 0 0</code>. If we want to rotate around the center of the element, we use <code>transform-origin: 50% 50%</code>, while to rotate around the bottom right of the element, we use <code>transform-origin: 100% 100%</code>.</p><p id="rotate2" onmousedown="transformElement('#rotate2', 'rotate(360deg)')" onmouseup="transformElement('#rotate2', 'none')" style="background: #aaa; width: 80%; margin: 1em auto; -webkit-transform-origin: 50% 50%; -webkit-transition: all 1s; -moz-transform-origin: 50% 50%; -moz-transition: all 1s; -o-transform-origin: 50% 50%; -o-transition: all 1s; -ms-transform-origin: 50% 50%; -ms-transition: all 1s; transform-origin: 50% 50%; transition: all 1s;">This element rotates around the center of the element (<code>transform-origin: 50% 50%; transform: rotate(360deg)</code>).</p><p id="rotate3" onmousedown="transformElement('#rotate3', 'rotate(360deg)')" onmouseup="transformElement('#rotate3', 'none')" style="background: #aaa; width: 80%; margin: 1em auto; -webkit-transform-origin: 100% 100%; -webkit-transition: all 1s; -moz-transform-origin: 100% 100%; -moz-transition: all 1s; -o-transform-origin: 100% 100%; -o-transition: all 1s; -ms-transform-origin: 100% 100%; -ms-transition: all 1s; transform-origin: 100% 100%; transition: all 1s;">This element rotates around the bottom right hand corner of the element (<code>transform-origin: 100% 100%; transform: rotate(360deg)</code>).</p><p>(You might be able to guess that we can animate transformation changes, like we can most other CSS property changes using CSS Transitions. For more on this, see my article on <a href="http://www.webdirections.org/blog/let-the-web-move-you-css3-animations-and-transitions/">CSS transitions and animations</a>.)</p><p>So, let’s now put rotations and transform origin together so we can play around with them.</p><div class="transformed"><p><img style="display: block; width: 256px; border: solid black 1px; margin: 0 auto; padding: .2em" id="rotateMe" alt="web directions logo" src="http://south11.webdirections.org/wp-content/themes/conf-theme-html5/images/logo.png"></p><pre id='rotateCSS'>transform: rotate(0);
transform-origin: 0 0</pre><div class="controls"><p><label for="rotateValue">rotate:</label> <input name="rotateValue" id="rotateValue" type="range" min="-360" max="350" step="1" title="" value="0" onchange="rotateThis()" /></p><p><label for="hOriginValue">Horizontal Origin:</label> <input name="hOriginValue" id="hOriginValue" type="range" min="0" max="100" step="1" title="" value="0" onchange="rotateThis()" /></p><p><label for="vOriginValue">Vertical Origin:</label> <input name="vOriginValue" id="vOriginValue" type="range" min="0" max="100" step="1" title="" value="0" onchange="rotateThis()" /></p></div></div><p><code>transform-origin</code> can also be specified with  keywords, in place of percentage (or length) values. As with <code>background-position</code> we can use <code>left</code>, <code>center</code> or <code>right</code> for the horizontal origin position and <code>top</code>, <code>center</code> or <code>bottom</code> for vertical. Where only one value is used, this applies to the horizontal origin, and the vertical is 50% (or <code>center</code>). Where no <code>transform-origin</code> is specified, its default value is <code>50% 50%</code>.</p><h5>skew</h5><p>the last of the 2 dimensional transform functions is <code>skew</code>. Skewing is typically explained in mathematical terms, but if you recall a little school geometry, it isn’t really that complicated. Horizontal skew (the <code>skewX</code> function) takes the box of an element, and while the top and bottom edges remain horizontal, tilts the left and right edges by the specified number of degrees to create a parallelogram. Similarly, a vertical skew (<code>skewY</code>), leaves the left and right edges vertical, and creates a parallelogram with the top and bottom edges rotated by the specified number of degrees. And when you skew both horizontally and vertically, you combine both of these (where it can get really quite tricky to work out what’s going on). Does that help? You can play with the values below to get a sense of how skewing works in practice, including how it can create apparent 3D effects.</p><p>The <code>skew</code> function, like most other functions, takes one or two values. As with <code>rotate</code>, they are angle values, and where there are two values, they are comma separated.</p><div class="transformed"><p><img style="display: block; width: 256px; border: solid black 1px; margin: 0 auto; padding: .2em" id="skewMe" alt="web directions logo" src="http://south11.webdirections.org/wp-content/themes/conf-theme-html5/images/logo.png"></p><div class=" controls"><p><code id='skewCSS'>transform: skew(0, 0)</code></p><p><label for="hskewValue">horizontal skew:</label> <input name="hskewValue" id="hskewValue" type="range" min="-360" max="360" step="1" title="" value="0" onchange="skewThis()" /></p><p><label for="vskewValue">vertical skew:</label> <input name="vskewValue" id="vskewValue" type="range" min="-360" max="360" step="1" title="" value="0" onchange="skewThis()" /></p></div></div><p>Once again, as with a number of the other transform functions we’ve seen, there are two related functions — <code>skewX</code> and <code>skewY</code>, which each skew only in one dimension, and which take only a single, angle value.</p><h5>Complex transformations</h5><p>While you’ll likely never need to use it, underneath all these functions is the core of CSS transformations, based on the mathematical concept of a <strong><a href="http://www.w3.org/TR/SVG/coords.html#TransformMatrixDefined">transformation matrix</a></strong>. Each of the functions we’ve seen can be represented by a matrix value. While it’s firmly in the domain of mathematics, we can for example represent the function <code>scale(1.5,1.2)</code> by the matrix</p><pre>1.5	|	0	|	0
0	|	1.2	|	0
0	|	0	|	1 </pre><p>and directly apply this matrix value using the <code>matrix</code> function, like so</p><pre>transform: matrix(1.5, 0, 0, 1.2, 0, 0)</pre><p style="-webkit-transform: matrix(1.5, 0, 0, 1.2, 0, 0); -moz-transform: matrix(1.5, 0, 0, 1.2, 0, 0); -o-transform: matrix(1.5, 0, 0, 1.2, 0, 0); -ms-transform: matrix(1.5, 0, 0, 1.2, 0, 0); transform: matrix(1.5, 0, 0, 1.2, 0, 0); -webkit-transform-origin: 0 0; -moz-transform-origin: 0 0; -o-transform-origin: 0 0; -ms-transform-origin: 0 0; transform-origin: 0 0; ">this element has been scaled using a matrix function on the transform property.</p><p>The transform matrices for various functions are <a href="http://www.w3.org/TR/SVG/coords.html#EstablishingANewUserSpace">described in the SVG specification</a>.</p><h5>Multiple transforms</h5><p>It’s possible to apply multiple transform functions at once to an element. For example we can rotate, translate and skew an element with the single transform property:</p><pre>transform: scale(0.75) rotate(45deg) translate(132px, -149px) skew(32deg, -32deg);</pre><p id="multipleTransforms" style="background: #ccc">Click the button below to apply several transformation functions simultaneously, with the property <code>transform: scale(0.75) rotate(45deg) translate(132px, -149px) skew(32deg, -32deg);</code></p><p><button onclick="transformElement('#multipleTransforms', 'scale(0.75) rotate(45deg) translate(132px, -149px) skew(32deg, -32deg)')">Transform!</button></p><p>There is however a <a href="#translating-rotated">complicating factor</a>, which we look at in a moment.</p><h5>The Transformer Tool</h5><p>Hand coding transforms, as with much to do with CSS3, is an increasingly complex process. Not only is there a good deal of syntax to remember often for quite straightforward effects, but the outcome of at least some transforms isn’t necessarily obvious to most of us simply by looking at the CSS. So, to help you learn, and explore, CSS transforms, I’ve developed a <a href="http://westciv.com/tools/transforms/index.html">2D transform tool</a> (there’s a 3D one as well, but we’ll cover 3D in a later article).</p><p>If you’re keen to explore transformations in more detail, and how they can be made to work together, head over and take a look, and as always, let me know what you think <a href="https://twitter.com/#!/johnallsopp">via twitter</a>.</p><h4>Gotchas, tips and tricks</h4><p>Its fair to say that while now widely supported in modern browsers, 2D CSS transforms are still experimental, and quite quirky. Here are some of the difficulties you might encounter, and some tips and ideas for working with 2D transforms.</p><h5>vendor specific prefixes</h5><p>Reflecting the experimental nature of transforms, all browsers require vendor specific prefixes for the <code>transform</code> and <code>transform-origin</code> properties (note that <strong> function names are not prefixed</strong>). As all modern browsers including IE9 and up support 2D CSS transforms, using these transformation properties can get more than a little unwieldy. For example, the CSS for a simple rotation around the center of an element, if we include all vendor specific properties, would be something like:</p><pre>img{
	-webkit-transform: rotate(90deg);
	-moz-transform: rotate(90deg);
	-o-transform: rotate(90deg);
	-ms-transform: rotate(90deg);
	transform: rotate(90deg); //always include a standard for last 

	-webkit-transform-origin: 50% 50%;
	-moz-transform-origin: 50% 50%;
	-o-transform-origin: 50% 50%;
	-ms-transform-origin: 50% 50%;
	transform-origin: 50% 50%;
}
</pre><p>You might find the use of a CSS preprocessor like <a href="http://lesscss.org/">LESS</a> or <a href="http://sass-lang.com/">SASS</a> worth exploring, as they can make stylesheets far more manageable when you use a lot of vendor prefixing.</p><h5>Transforming inline elements in webkit</h5><p>According to the current version of the specification, CSS Transforms should be applied to inline, as well as block elements, but while Opera and Firefox both correctly apply transforms to inline elements, WebKit browsers (Safari 5.1, Chrome 15) currently don’t.</p><p>A workaround for this is to give inline elements which are to be transformed <code>display: inline-block</code>, which won’t affect how they are laid out in the page, but will enable these browsers to transform them.</p><h5 id="translating-rotated">Translating rotated content</h5><p>One subtle aspect of multiple transformations is that <strong>functions are performed in sequence</strong> — from first to last in the list. The order that you specify functions can make a difference. Take a look at the following paragraphs. Both have the same <code>scale</code>, <code>rotate</code> and <code>translate</code> functions applied. But, in the first, the element is translated to the right, while in the second, it is translated to the left. What’s going on?</p><p id="multipleTransforms2" style="background: #ccc">Clicking the button below  applies several transformation functions simultaneously, with the property <code>transform: scale(0.75) rotate(180deg) translate(-100px,0)</code></p><p><button onclick="transformElement('#multipleTransforms2', 'scale(0.75) rotate(180deg) translate(-100px,0)')">Transform!</button></p><p id="multipleTransforms3" style="background: #ccc">Clicking the button below  applies several transformation functions simultaneously, with the property <code>transform: scale(0.75) translate(-100px, 0) rotate(180deg)</code></p><p><button onclick="transformElement('#multipleTransforms3', 'scale(0.75) translate(-100px, 0) rotate(180deg)')">Transform!</button></p><p>Transformations don’t take place in an absolute coordinate space. Rather, “up”, “down”, “left” and “right” are relative to the current rotation (but not skew) of the element. So, if an element is rotated half a turn, and so is “upside down” then translate(0, –100px) moves it <strong>down</strong> the page 100px. If it’s rotated a quarter turn to the right, it’s moved <strong>to the left</strong>. Similarly, translating “horizontally” is always relative to the element. So, if it’s rotated by 180 degrees, then translate(100px, 0) moves the element to the left. In short, the X and Y axes of a transformation are relative not to the page, but the element’s current rotation.</p><h5>Interacting with transformed content</h5><p>While the box of an element isn’t changed by a transformation, elements that are transformed display various quirks when it comes to mouse events in various browsers, most likely due to the still experimental nature of transformations. Take the element below. It rotates a quarter turn clockwise when the mouse is over it, and then back to its original rotation when the mouse is out of it.</p><p><img style="display: block; width: 256px; border: solid black 1px; margin: 0 auto; padding: .2em" alt="web directions logo" src="http://south11.webdirections.org/wp-content/themes/conf-theme-html5/images/logo.png" id='rotate4' onmouseover="transformElement('#rotate4', 'rotate(90deg)')" onmouseout="transformElement('#rotate4', 'rotate(0)')"></p><p>Now, if the box of the element isn’t changed, then when rotated, hovering over any of the image which is outside that original box should not trigger a mouseover event, and so the element should rotate back to its original position. However, as makes intuitive sense, hovering over those parts of the rotated element that are outside the original box <strong>does</strong> cause mouseover events to be fired. But in addition, mouseover events are also fired when you hover over that part of the element’s original box which no longer has content because it has been rotated away. And if you move your mouse around the element, you’ll find in all browsers various locations where the rotation abruptly, though unintuitively, changes. Similar behavior can be observed for translation and other transformations.</p><p>In light of this, I’d suggest being extremely wary of transforming elements which users will interact with given the current state of browser support for transformations.</p><h5>Overflowing and transformations</h5><p>We mentioned earlier that while transformations don’t effect the box model of an element, and so leave the layout of a page untouched, they <strong>do</strong> effect the overflow, and if we have <code>overflow: auto</code>, they can in fact impact the page flow.</p><p>In the element below, we have an image inside a div. The div has an <code>overflow:auto</code>. When we hover over the element (apologies to touch device users), the contained image scales up in size.</p><div style="overflow: auto; border: solid thin #999"> <img style="display: block; width: 256px; border: solid black 1px; margin: 0 auto; padding: .2em" alt="web directions logo" src="http://south11.webdirections.org/wp-content/themes/conf-theme-html5/images/logo.png" id="scale1" onmouseover="transformElement('#scale1', 'scaleX(10)')" onmouseout="transformElement('#scale1', 'scale(1)')"></div><p>Now, in most browsers on most platforms (Safari on Mac OS X 10.7 is an exception) the browser adds a horizontal scrollbar to the div when you hover over the image, which adds to the height of the element, reflowing the page below it. Just something to be aware of.</p><h5>CSS Positioning and Transforms</h5><p>While I was writing this article, CSS legend Eric Meyer posted a <a href="http://meyerweb.com/eric/thoughts/2011/09/12/un-fixing-fixed-elements-with-css-transforms/">detailed critique of one interesting aspect of transforms</a>.</p><p>It has to do with the positioning of elements. When we absolutely or fixed  position an element, and give it say a top and left, these positions are offset from their containing box — which is not necessarily their parent element. Rather, the containing box is the first ancestor which itself has either relative, absolute or fixed <code>position</code>. However, adding a transform to an element <strong>also</strong> makes it a containing block for its descendent elements! As Eric observes, this can particularly cause difficulties with fixed positioning. Rather than rehash Eric’s detailed thoughts, I’ll let you <a href="http://meyerweb.com/eric/thoughts/2011/09/12/un-fixing-fixed-elements-with-css-transforms/">head over and read them first hand</a>.</p><h5>General Rendering Problems</h5><p>On different browsers you’ll find various rendering problems with transformed content. For example, with Opera, rotated text appears to be rendered in a lighter font than the same text when it isn’t rotated. I’ve also seen redrawing problems when rotating text in WebKit browsers. In Safari on iOS 4, rotated text doesn’t necessarily align smoothly along its baseline. None of these are necessarily deal breakers, but it’s worth keeping in mind. Transforms are still experimental, so don’t necessarily expect them to be perfectly supported in all circumstances just yet.</p><h5>Hardware Acceleration</h5><p>There’s a widely held belief that at least some browsers hardware accelerate the rendering of CSS transformations (hardware acceleration involves the CPU handing off execution of certain types of calculation to the GPU, which can increase rendering performance significantly, particularly on mobile devices).</p><p>At present the current state of hardware acceleration for CSS transforms across all browsers and devices is difficult to pin down. A webkit engineer I tracked down confirmed that current versions of Safari (5.1 on the desktop, iOS 4), but not necessarily other WebKit browsers:</p><ul><li>animated 2D transforms in Safari are always hardware accelerated</li><li>using 3D for static 2D transforms may improve performance, but may also increase memory use — a real issue for memory limited mobile devices in particular</li></ul><p>Now, haven’t we just spent however much effort covering 2D transforms? How could this possibly help? Well, as we’ll see in an upcoming article on 3D transforms, we can use 3D transforms to do 2D transforms (for example, there’s <code>rotate3D</code>). If squeezing maximum performance for iOS devices is a need, then it may be that using a 3D version of a transform will help.</p><p>It’s also worth noting that issues around what aspects of CSS transforms are hardware accelerated and how that acceleration works are implementation details in specific browsers, and not specified as part of CSS Transforms. As such, across browsers there’s likely to be little uniformity of approach to hardware acceleration, and even from one version of a browser to the next, approaches may change.</p><h5>Backwards Compatibility</h5><p>One of the strongest aspects of CSS3 features like gradients, border-radius, shadows and the like is that they have been typically designed so as to be easily used in a way that is backwards compatible almost automatically, or provided we keep a small number of potential challenges in mind. For example, with gradients we need to ensure we have a fallback background color or image for when gradients aren’t supported. For <code>text-shadow</code>, we need to ensure that the contrast between the text and the element background is sufficient when the shadow is not drawn.</p><p>Of all new CSS3 properties, transform is the one where backwards compatibility is the most difficult to ensure. Ironically, it’s precisely because transforms don’t affect the page layout that they cause such difficulty. For example, in order to accommodate say a heading rotated 90 degree to run horizontally along the left hand side of the text which follows it, we need to create whitespace to ensure the heading does not overlap the text. We might do that with margin, or padding. We’re also likely to want to remove the whitespace where the heading has been rotated away from, by, for example, using negative margin on the paragraph following the heading. But, what happens if transforms aren’t supported? The heading text will be overlapped by the paragraph below it.</p><p>In order to use transforms for more sophisticated page layout along these lines, a solution like <a href="http://www.modernizr.com/">Modernizr</a>, which enables different CSS to be applied based on the support, or absence of support for various CSS3 features like transforms is indispensable.</p><p>Transformations are typically most easily used in a way that is backwards compatible where animated transforms create a transition between states in an application. We’re all most likely used to sliding or flipping transitions between states in iOS and other mobile apps. CSS transforms can be used for these transitions, in conjunction with <a href="http://www.webdirections.org/blog/let-the-web-move-you-css3-animations-and-transitions/">CSS Transitions</a>, and where transforms aren’t supported (in which case it’s unlikely transitions will be as well), your users simply see an abrupt change in state.</p><p>However you plan to use transforms, as with every other aspect of web development, keep in mind those browsers which don’t support them, and ensure your user’s experience isn’t diminished to the point where information or functionality is denied them because their browser doesn’t support it.</p><h4>Browser Support</h4><p>As we mentioned, despite the still rather experimental nature of support for CSS 2D Transforms, they are now <a href="http://caniuse.com/#search=transforms">widely supported in modern browsers</a> including:</p><ul><li>Internet Explorer 9 and up</li><li>Firefox 3.5 up</li><li>Safari 3.2 up</li><li>Chrome 10 and up</li><li>Opera 10.6 and up</li><li>iOS 3.2 and up</li><li>Opera Mobile 11 and higher</li><li>Android 2.1 and up</li></ul><p>So, support is widespread, and constantly improving. While there are definitely challenges associated with using 2D Transforms, they’re a powerful, and worthwhile addition to the repertoire of developers, and will only gain in value. What are you going to do with them?</p><p>More Reading</p><ul><li>The <a href="http://www.w3.org/TR/css3-2d-transforms/">2D Transforms Specification</a></li><li><a href="http://msdn.microsoft.com/en-us/scriptjunkie/gg709742">MSDN on Transforms</a> — great to see the IE love for them!</li><li><a href="http://dev.opera.com/articles/view/css3-transitions-and-2d-transforms/">Opera’s developer center</a> on, you guessed it, Transforms</li><li>On <a href="http://extremelysatisfactorytotalitarianism.com/blog/?p=1002">Transformations in Internet Explorer</a> (before and after IE9)</li></ul> ]]></content:encoded> <wfw:commentRss>http://www.webdirections.org/blog/2d-transforms-in-css3/feed/</wfw:commentRss> <slash:comments>4</slash:comments> </item> <item><title>What do you know? Video now available</title><link>http://www.webdirections.org/blog/what-do-you-know-video-now-available/</link> <comments>http://www.webdirections.org/blog/what-do-you-know-video-now-available/#comments</comments> <pubDate>Fri, 16 Sep 2011 03:05:28 +0000</pubDate> <dc:creator>John</dc:creator> <category><![CDATA[Blog]]></category> <category><![CDATA[events]]></category><guid isPermaLink="false">http://www.webdirections.org/?p=3655</guid> <description><![CDATA[What do you know? That’s the question we posed 20 Australian designers, developers, UX folks and others for our first ever “What do you know” events in Sydney and Melbroune. The format was simple — each of the speakers had 5 minutes to tell the audience something they know — think of it as super-concentrated [...]]]></description> <content:encoded><![CDATA[<p>What do <strong>you</strong> know? That’s the question we posed 20 Australian designers, developers, UX folks and others for our first ever “<a href="http://whatdoyouknow.webdirections.org">What do you know</a>” events in Sydney and Melbroune.</p><p>The format was simple — each of the speakers had 5 minutes to tell the audience something they know — think of it as super-concentrated (and fun) lessons in all sorts of cool stuff.</p><p>The crowds had a blast, and even better, we captured everything that happened on screen that night, along with audio.</p><p>Presentations covered all manner of design, development and other web related topics. So, in 5 minutes you can learn more than you might have thought possible on</p><ul><li><a href="http://whatdoyouknow.webdirections.org/videos/fk-yeah-bezier">Bezier curves</a></li><li>Accessing the <a href="http://whatdoyouknow.webdirections.org/videos/mobile-device-api-now-with-added-fun">gyroscope and accelerometer in mobile browsers</a> (watch a live web based take battle built specially for the night!)</li><li><a href="http://whatdoyouknow.webdirections.org/videos/now-try-that-blindfolded">WCAG ARIA </a></li><li><a href="http://whatdoyouknow.webdirections.org/videos/optimising-html-email-for-mobile">Mobile HTML emails</a> (our Sydney winner!)</li><li><a href="http://whatdoyouknow.webdirections.org/videos/how-to-make-your-life-more-awesome-with-css3-media-queries">CSS3 Media Queries</a> (our Melbourne winner, and great fun)</li><li><a href="http://whatdoyouknow.webdirections.org/videos/learn-you-a-parallax-for-great-good">Parallax effects in CSS</a></li></ul><p>and much much more, including the world premier of <a href="http://whatdoyouknow.webdirections.org/videos/newton-js-box2d-raphael">Dmitry Baranovskiy’s Newton.js game dev engine</a> (featuring an Angry Birds clone he built with it)</p><p>So, head over to <a href="http://whatdoyouknow.webdirections.org/videos">the video page</a>, and check out 100+ minutes of fantastic fun interesting presentations, 5 minutes at a time.</p><p>And stay tuned, as What Do You Know might be headed to your city early 2012 (well, if you are in Australia)</p><p>And, if you like the concept, then go ahead and borrow it — maybe in house at work, or with your meet up group, or your own community What do you know event. <a href="http://whatdoyouknow.webdirections.org/contact">Drop us a line</a>, and we’ll gladly give you some thoughts about how to go about it, and help get the word out if you like!</p> ]]></content:encoded> <wfw:commentRss>http://www.webdirections.org/blog/what-do-you-know-video-now-available/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>On the (abominable) proposed HTML5 “scoped” attribute for style elements</title><link>http://www.webdirections.org/blog/on-the-abominable-proposed-html5-scoped-attribute-for-style-elements/</link> <comments>http://www.webdirections.org/blog/on-the-abominable-proposed-html5-scoped-attribute-for-style-elements/#comments</comments> <pubDate>Thu, 15 Sep 2011 03:13:10 +0000</pubDate> <dc:creator>John</dc:creator> <category><![CDATA[Blog]]></category> <category><![CDATA[developer]]></category><guid isPermaLink="false">http://www.webdirections.org/?p=3646</guid> <description><![CDATA[Over the last couple of years, I’ve had my fair share to say about the direction HTML5 has been taking, in particular being quite critical of the entire approach taken to adding richer semantics to HTML, as well as specific language choices. It must be said though, that nothing has quite riled me like the [...]]]></description> <content:encoded><![CDATA[<p>Over the last couple of years, I’ve had my <a href="http://www.alistapart.com/articles/semanticsinhtml5">fair share</a> to say about the direction HTML5 has been taking, in particular being quite critical of the entire approach taken to adding richer semantics to HTML, as well as specific language choices.</p><p>It must be said though, that nothing has quite riled me like the proposed <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/semantics.html#attr-style-scoped">“scoped” attribute for style elements</a>. To learn about it, I recommend HTML5 doctor <a href="http://html5doctor.com/the-scoped-attribute/">Jack Osborne’s much more readable version</a>, with some thoughts (and lively commentary).</p><p>So, what do I think of it? Well, I guess from the title of the post you already know. I think this is genuinely the worst suggested feature of HTML or CSS I’ve ever seen, and I would like it to see it be swiftly taken out the back and euthanised. Yep — strong language, but just so no one is possibly mistaken about this.</p><p>Why am I so emphatically opposed to it? Where to begin? There are several different lines of objection I have.</p><p>First, if we consider the separation of presentation from markup to be in anyway important, and at present it is considered a central best practice in web development, then this approach, which strikes at the heart of that practice, should be anathema. It’s long been considered that inline CSS is a last resort hack when it is difficult, or impossible to apply style using a stylesheet in the head of a document (linked or embedded). Now we’re embedding style sheets into the body of a document?</p><p>But, let’s go even more deeply than that. The development of HTML5 is <em>supposedly</em> governed by core <a href="http://www.w3.org/TR/html-design-principles">design principles</a>. This suggested approach violates several of these. Let’s take a look.</p><h4>Principle 2.2. Degrade Gracefully</h4><p>So, what happens if we use this feature in current browsers? Well, firstly none of these support the feature whatsoever.</p><p>But here’s an example I tried in a number of current browsers</p><pre>&lt;section&gt;
    &lt;style scoped&gt;
      p { color: red; }
    &lt;/style&gt;
    &lt;h2&gt;How does it work?&lt;/h2&gt;
    &lt;p&gt;Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.&lt;/p&gt;
  &lt;/section&gt;

  &lt;p&gt;other stuff&lt;/p&gt;
</pre><p>And here’s what happened.</p><p>Safari 5.1, Opera 11, Chrome, Firefox 6, and IE7 up  all recognise the style element, and then style <strong>both p elements</strong> red — so scoping is not honoured — let’s call this <strong>not</strong> graceful degradation.</p><h4>Principle 2.3. Do not Reinvent the Wheel</h4><p>We currently <strong>can</strong> scope style in an HTML document. We use these new fangled things call CSS selectors. Even without touching the HTML above we could style the paragraphs in the given section like so</p><pre>section:first-of-type>p{
  color: red
}
</pre><p>Or we could add <code>class</code> or <code>id</code> as appropriate to our section. I’d need to see a pretty compelling use case here, that demonstrates a need that can’t otherwise be solved using existing CSS/HTML practices and technologies, before beginning to even think there’s a problem to be solved, let alone that this might be a good solution to that problem.</p><h4>Principle 3.1. Solve Real Problems</h4><p>In over 15 years of web development, I’ve not seen a problem this is a solution to. If you are going to violate widely held long standing best practice, you need to do a bit better than invent a rare problem, then solve it in a way that opens the floodgates to terrible practice.</p><p>Truthfully, and I have paid a fair bit of attention for close to 15 years in the CSS space, <strong>I have never ever once heard anyone articulate this need</strong>. Sure, it’s probably happened, but it’s far from a pressing concern.</p><h4>Principle 3.2. Priority of Constituencies</h4><blockquote><p>In case of conflict, consider users over authors over implementors over specifiers over theoretical purity</p></blockquote><p>So, users get broken pages in older browsers with style scope. Authors who want to use it would need to hack around the fact that this not only doesn’t work in older browsers, it causes rendering challenges. Seems we are focussing at the level of theoretical “purity”, or maybe, the whims of specifiers here.</p><p>Is this what versionless HTML development is about? Design principles violated left right and center, and an unwanted, unneeded and harmful addition to HTML, seemingly at the whim of one of the authors of HTML5?</p><p>And the first place we hear about it is in a draft of the future HTML specification. I wonder what other hidden gems await discovery in that document?</p><p>You know, it’s not like there aren’t some pressing real world problems to there for HTML to address.</p><p>If you feel remotely strongly as I do, you can <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/semantics.html#attr-style-scoped">submit a comment on the draft HTML specification at the WHATWG here</a>.</p> ]]></content:encoded> <wfw:commentRss>http://www.webdirections.org/blog/on-the-abominable-proposed-html5-scoped-attribute-for-style-elements/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>Bring back the CSS bike shedding property!</title><link>http://www.webdirections.org/blog/bring-back-the-css-bike-shedding-property/</link> <comments>http://www.webdirections.org/blog/bring-back-the-css-bike-shedding-property/#comments</comments> <pubDate>Mon, 05 Sep 2011 23:55:59 +0000</pubDate> <dc:creator>John</dc:creator> <category><![CDATA[Blog]]></category><guid isPermaLink="false">http://www.webdirections.org/?p=3642</guid> <description><![CDATA[There’s not necessarily a lot of whimsy in the world of web standards. A great deal of value, a lot of hard work by really smart people, but not whimsy. Well, recently there’s been a little bit of whimsy in the otherwise dry, but very useful CSS3 Text module, with the “bikeshedding” property. But sadly, [...]]]></description> <content:encoded><![CDATA[<p>There’s not necessarily a lot of whimsy in the world of web standards. A great deal of value, a lot of hard work by really smart people, but not whimsy.</p><p>Well, recently there’s been a little bit of whimsy in the otherwise dry, but very useful CSS3 Text module, with the “bikeshedding” property. But sadly, no more. bikeshedding is now more prosaically named “white-space-collapsing”, and I for one think this is wrong. So wrong, that I’m campaigning for the <strong>reinstatement of the bike shedding name</strong>.</p><p>If like me, you want to bring a little bit of whimsy back to web standards, then join the campaign by commenting below, and <strong>bring back bikeshedding</strong>!</p> ]]></content:encoded> <wfw:commentRss>http://www.webdirections.org/blog/bring-back-the-css-bike-shedding-property/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>HTML5 selectors API — It’s like a Swiss Army Knife for the DOM</title><link>http://www.webdirections.org/blog/html5-selectors-api-its-like-a-swiss-army-knife-for-the-dom/</link> <comments>http://www.webdirections.org/blog/html5-selectors-api-its-like-a-swiss-army-knife-for-the-dom/#comments</comments> <pubDate>Fri, 02 Sep 2011 01:11:32 +0000</pubDate> <dc:creator>John</dc:creator> <category><![CDATA[Blog]]></category> <category><![CDATA[developer]]></category> <category><![CDATA[DOM]]></category> <category><![CDATA[html5]]></category> <category><![CDATA[querySelector]]></category> <category><![CDATA[querySelectorAll]]></category> <category><![CDATA[selectors API]]></category><guid isPermaLink="false">http://www.webdirections.org/?p=3638</guid> <description><![CDATA[In the infancy of JavaScript, there was little if any concept of an HTML document object model (DOM). Even though JavaScript was invented to enable web developers to manipulate parts of a web page, and in the original implementation, in Netscape 2.0, developers could only access the form elements, links, and images in a page. [...]]]></description> <content:encoded><![CDATA[<p>In the infancy of JavaScript, there was little if any concept of an HTML document object model (DOM). Even though JavaScript was invented to enable web developers to manipulate parts of a web page, and in the original implementation, in Netscape 2.0, developers could only access the form elements, links, and images in a page. Useful for form validation, and first widely used for image rollover techniques (think :hover, before CSS), but far from the general purpose tool to create modern web applications we now know (and love/hate).</p><p>Newer iterations of the DOM provided developers with access to far more than just that original limited range of elements, as well as the ability to insert, modify and delete elements in an HTML document. But, cross-browser implementations very often differed, and full support for the W3C’s DOM standards have arguably been treated as far more optional than CSS or HTML support.</p><p>One of the many reasons for the success of JavaScript libraries like jQuery and Prototype, on top of their easing the pain of cross-browser development was how they made working with the DOM far less painful than it had previously been, and indeed how it was with the standard DOM. Being able to use arbitrary CSS selector notation to get matching elements from a document made the standard DOM methods seem antiquated, or at the every least, far too much like hard work.</p><p>Luckily, the standards and browser developers took notice. The W3C developed the Selectors API, a way of easily accessing elements in the DOM using standard CSS selector concepts, and browser developers have baked these into all modern  browsers, way back to IE8.</p><p>In this short (by my standards) article, we’ll look at the Selectors API, how you use it, browser support, and some little things you might like to keep in mind while using it. Rest assured, it’s now widely supported, so in many cases, you can safely use it, potentially with a fallback for older browsers (IE7 and older specifically) via libraries like jQuery (or more lightweight selector engines like <a href="http://sizzlejs.com/">Sizzle</a>, which provides this functionality for jQuery, and other libraries).</p><h3>The Selectors API</h3><p>The Selectors API, which many would consider to be part of HTML5, is in fact a separate, small specification from the W3C. It provides only two new methods, <code>querySelector</code>, and <code>querySelectorAll</code>, for the <code>Document</code>, <code>Element</code>, and <code>DocumentFragment</code> objects (typically, you’ll use these methods on the <code>document</code> or <code>element</code> objects.) But do these methods make life easier for developers?</p><p>Before the Selectors API, to access an object in the DOM we could use these methods:</p><ul><li><code>getElementById</code> (from DOM Level 2 Core) — available for the <code>document</code> element</li><li><code>getElementsByClassName</code>, standardized in HTML5, after long non standard browser support, which is supported on <code>document</code>s and <code>element</code>s</li><li><code>getElementsByTagName</code>, from DOM Level 2 Core, available on the <code>document</code> and <code>element</code> objects</li></ul><p>And there are some legacy ways of accessing elements on a page, which date from the earliest days of JavaScript:</p><ul><li><code>links</code> is a property of the document object which contains all anchor (<code>a</code>) and <code>area</code> elements with an <code>href</code> attribute</li><li><code>anchors</code> is a property of the document object which contains all <code>a</code> elements</li><li><code>forms</code> is a property of the document object which contains all form elements</li></ul><p> We can also “traverse” the DOM, using:</p><ul><li><code>childNodes</code>, a property of the <code>document</code> and <code>node</code> objects</li><li><code>nextSibling</code>, a property of a <code>node</code>, which contains the element directly following  it in the same parent element</li><li><code>parentElement</code>, a property of a node, which contains its parent element.</li></ul><p>and related DOM traversal properties and methods.</p><p>But, what developers really often want to be able to do (as the success of jQuery and other libraries has shown) is simply say “give me all the elements which match this selector”, or “give me the first element which matches this selector”. And that’s precisely what the simple, powerful Selectors API does. It doesn’t completely do away with the need for DOM traversal, and legacy methods and properties, but it goes a long, long way.</p><h4>querySelector</h4><p><code>querySelector</code> is a method of the document or any element, which returns the first descendent element which would be selected by its one argument, a CSS selector string. We can use this in place of the <code>document.getElementById('content')</code> like so: <code>document.querySelector('#content')</code> (like me, you’ll probably find yourself forgetting to add the <code>#</code> from time to time in <code>querySelector</code>, something which doesn’t throw an error, so can be frustrating to track down).</p><p>And we can do things like find the first <code>header</code> element in an HTML5 document, with <code>querySelector('header')</code>. So far so good. But where <code>querySelector</code> really shines is we can use <strong>any</strong> selector (attribute, structural, dynamic, UI, and even selector groups) with it. In most cases, this makes traversing the DOM, and locating a specific element far simpler, and most likely far quicker, as we won’t be looping in JavaScript and accessing all kinds of DOM properties, rather, the query is taking place inside the browser’s far faster native DOM engine.</p><h4>querySelectorAll</h4><p>Often, when working with the DOM, we want to manipulate several elements at once, For example, we might want to unobtrusively attach an event listener to all the links with a given <code>class</code> value. Here, <code>querySelectorAll</code> is your friend. Just like <code>querySelector</code>, it takes a single string as an argument, which is a CSS selector. Instead of returning a single element, it returns a NodeList (a kind of JavaScript array) of matching elements. We can then iterate through this array, and manipulate these objects.</p><p>For example, we could use it to replace <code>document.links</code> like so:</p><pre>document.querySelectorAll('area[href], a[href]')</pre><p>This finds all <code>area</code> elements with the <code>href</code> attribute set, as well as all <code>a</code> elements with this attribute set as well (notice how we’ve used a selector group, which is quite acceptable with the Selectors API).</p><p>Matching elements are returned in the order they appear in the DOM parse tree.</p><h4>Document or Element?</h4><p>I mentioned that both the <code>document</code>, and <code>element</code> objects implement these two methods — what’s the difference? Well, as you might have guessed, these methods find elements that are descendants of the object you query on. So, if you use the method on a paragraph element, it will only find the descendant elements of that paragraph which match the selector. Other elements in the document which might match it won’t be returned. But, if you use the methods on the document, then any matching element in the document can be found.</p><h3>Gotchas</h3><p>If you’ve really got your hands dirty with the DOM, you’ll know that when DOM methods return a NodeList, it is live—that is, the members of the list change, depending on the state of the document.</p><p>Let’s say we get all the elements with a <code>class</code> of “nav” using <code>document.getElementsByClassName('nav')</code>, and it returns 5 elements, which we keep in a variable.</p><p>Now, if we add a new element with <code>class</code> nav, or remove one of the existing elements with a <code>class</code> of nav, the NodeList in our variable will be updated to reflect these changes (that’s why it is called a <strong>live</strong> NodeList).</p><p>But <code>querySelector</code> and <code>querySelectorAll</code> are different. While they return a NodeList, it is <strong>static</strong>. So, if we similarly get all elements with a <code>class</code> of nav using <code>document.querySelectorAll('.nav')</code>, then regardless of what we subsequently do to the DOM, the length and contents of the NodeList won’t change. Which means, it’s always best to query the DOM just before you need the elements, rather than holding on to elements if your DOM is going to change.</p><p>There’s also a performance consideration. Tests of various browsers indicate that <code>querySelectorAll</code> is slower than <code>getElementByTagName</code> (though not it would appear in Opera). But, it’s also possible that once available, manipulating the static NodeList may be higher performance than manipulating a dynamic NodeList. And this issue will likely only have an impact in extreme cases. I’d certainly not recommend prematurely optimising by using <code>getElementsByTagName</code>, <code>getElementsByClass</code>, <code>getElementById</code> and so on in place of <code>querySelectorAll</code>, but it is worth noting you might be able to squeeze a little more performance out by doing so if you really need to.</p><p>And it is worth noting too that <code>querySelector</code> and <code>querySelectorAll</code> don’t work with every kind of selector. While pseudo-class selectors (like <code>:visited</code>) work with these methods, pseudo-element selectors, like <code>:first-letter</code>, <code>:first-line</code>, <code>:before</code> and <code>:after</code> although permissible as arguments, will return <code>null</code> in the case of <code>querySelector</code>, and an array of length zero for <code>querySelectorAll</code>.</p><p>A little gotcha this aging developer has found I’m so used to <code>getElementById</code> and <code>getElementsByClassName</code> that I find myself forgetting the <code>#</code> or <code>.</code> required in the selector string in <code>querySeletor</code> and <code>querySelectorAll</code>. As I mentioned a moment ago, it can be frustrating, as this won’t throw an error, but simply return null or an empty NodeList.</p><h3>Support</h3><p>All modern browsers, including IE8 and up support both <code>querySelector</code> and <code>querySelectorAll</code>. It is however worth noting that the results returned are dependent on what selectors the browser supports. IE8 supports CSS2.1 selectors, though not CSS3 selectors. IE9 supports many CSS3 selectors, but not a number of the UI related pseudo-classes, such as <code>:required</code> and <code>:invalid</code>. IE CSS support for versions 5 through 9 is <a href="<a href=&quot;http://msdn.microsoft.com/en-us/library/cc351024(v=vs.85).aspx#selectors&quot;>">extensively covered here by Microsoft</a>.</p><p>So, keep in mind, even where these methods are supported, what they return is only as good as the CSS selector support in that browser.</p><h3>The Wrap-up</h3><p>If you’re more of a web designer who’s always been a little intimidated by the thought of wading through the DOM in search of elements (trust me, even seasoned developers often wince at the thought), then <code>querySelector</code> and <code>querySelectorAll</code> are a boon for you. Or, if you’re a developer who finds yourself going straight for jQuery or another library as soon as the DOM is involved, the Selectors API might just save you a few KBs, additional files and fussing around. And, if you’re one of those seasoned DOM experts, I’m sure there’s plenty of times you’ll breathe a sigh of relief that rather than wading through an entire document with <code>childNodes</code>, <code>nextElementSibling</code> and the like, a single call to <code>querySelectorAll</code> will return all the elements you want. I reckon these two are my favourite, and now most used DOM methods, and I’m only surprised they aren’t more widely covered, as they really are like a Swiss Army Knife for the DOM. Perhaps we need a “top 2 Selectors API methods” article. Then again…</p><h3>Reading</h3><p>Here’s a few articles and other resources which delve into the Selectors API.</p><ul><li>The <a href="http://www.w3.org/TR/selectors-api">Selectors API specification</a> from the W3C</li><li>Selectors API at <a href="http://my.opera.com/core/blog/selectors-api">Opera Developers Center</a>, by Lachlan Hunt, one of the authors of the spec.</li><li>Selectors API at<a href="http://hacks.mozilla.org/2009/06/dom-selectors-api/"> Mozilla Hacks</a></li><li>Thoughts on performance from <a href="http://www.nczonline.net/blog/2010/09/28/why-is-getelementsbytagname-faster-that-queryselectorall/">JS performance guru Nicholas Zakas</a> (the comments are well worth reading)</li></ul> ]]></content:encoded> <wfw:commentRss>http://www.webdirections.org/blog/html5-selectors-api-its-like-a-swiss-army-knife-for-the-dom/feed/</wfw:commentRss> <slash:comments>4</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 4/6 queries in 0.003 seconds using disk: basic
Object Caching 766/766 objects using disk: basic

Served from: www.webdirections.org @ 2012-02-07 15:02:16 -->
