All posts tagged ‘CSS’

File Under: CSS, Web Standards

Web Developers Sound Off on WebKit Prefixes

Photo: Ariel Zambelich/Wired.com

Yesterday we told you about a disturbance in the web standards force, a supposed rash of websites that work in one and only one web browser. Instead of writing code that will work in any browser many developers are coding exclusively for WebKit, the engine that powers Safari, Chrome, iOS and Android web browsers.

The problem is bad enough that on Monday at the CSS Working Group meeting, Microsoft, Mozilla and Opera announced that each are planning to add support for some -webkit prefixed CSS properties. In other words, because web developers are using only the -webkit prefix, other browsers must either add support for -webkit or risk being seen as less capable browsers even when they aren’t.

We aren’t the only ones who think that spells disaster not just for web standards but for the long-term viability of the open web. In fact the response from the web community has all but drowned out everything else in our RSS and Twitter feeds.

Here’s our round-up of what’s being proposed, what it might mean for the web and how we might go about solving the problem:

First and foremost read the minutes from the CSS Work Group meeting, which is where all of this started. The legend for the names is at the top of the page, though you’ll need to scroll about half way down to get to the actual meat of the discussion.

The second must-read post on vendor prefixes comes from CSS Working Group Co-Chair Daniel Glazman who calls on other browser makers to not implement the -webkit prefix and asks developers to make the extra effort to build cross-browser apps. Glazman has since followed up that piece with two more, one clarifying the original post and one defending the CSS Working Group against those who argue that the reason prefixes exist is because the standards process is too slow. If you believe that the CSS spec moves to slowly, this post is well worth a read (spoiler alert: it’s typically browser makers arguing, not the standards process, that creates the hold up on new features).

Remy Sharp of HTML5Doctor fame, weighs in with a series of rough ideas, neatly summarizing the issue and looking at it from both sides. In the end Sharp seems to conclude that just about everyone is to blame, from the browsers to the working group to developers.

Rachel Andrew of the web standards project generally agrees with Glazman writing, “once again we run the risk of having sites built only for one platform, and [will] find it very hard to get that platform to go away if things move on.”

The ever-humorous Bruce Lawson, who works as a web standards evangelist at Opera Software, writes: “Personally — PERSONALLY — I’m pretty depressed about all this. I’ve spent 10 years — pretty much since IE6 came out — evangelizing cross-browser, accessible, standards-based sites. As a development community we chased the Shiny and we caused IE6 to linger around like a vindaloo fart in a windowless loo. And now we’re doing the same again.”

Over at Quirksblog mobile expert Peter-Paul Koch argues that vendor prefixes are just plain wrong: “Vendor prefixes are the most developer-hostile solution imaginable. The vendor prefix idea was flawed from the start by putting the full brunt of namespace management on web developers.” He goes on to propose an interesting idea of vendor-neutral prefixes like -alpha and -beta for experimental features.

Aaron Gustafson, a member of the Web Standards Project, has started a petition to ask Mozilla, Microsoft and Opera to not implement -webkit. Gustafson also has a one-line bash script you can use to search your code for any instances of the -webkit prefix so you can double check to make sure you’re supporting other browsers as well.

Mozilla developer Christian Heilman believes that “this mess has partly been created by developers, the least we can do is help fix it.” To that end Heilmann’s Pre-fix the web project is looking for developers willing to seek out projects on Github that only work in Webkit and then fork the project, adding the missing prefixes to the CSS, extending JS code to do proper feature detection and then sending a pull request. In other words, literally fixing the web.

JavaScript developer Peter van der Zee has some other possible solutions: “Either we strongly limit the life span or availability of the prefix by making them only available in beta versions of a browser. Or we force other vendors to pick up on the slack by giving them a certain time to come up with their own implementation of a certain feature, or forfeit that possibility after a certain amount of time.”

Finally, if you read through the CSS WG notes you’ll notice that Tantek Çelik cites developer Lea Verou as an example of web developers who use just the -webkit prefix. In fact that’s completely untrue and Çelik has since corrected his statement. Verou has long advocated using all prefixes and even created prefixfree to help automate the process.

File Under: CSS, Web Standards

WebKit Isn’t Breaking the Web. You Are

WebKit may seem like the only game in town, but it's not. Photo: Ariel Zambelich/Wired.com

It sounds like something from a galaxy far, far away, but in truth it was not that long ago that the web was littered with sites that proudly proclaimed “works best in Internet Explorer.” Thankfully those days are over. IE6 no longer dominates the web.

But, while IE6 may be a thing of the past, the root problem — websites that work in one and only one web browser — sadly, remains.

This time the culprit is WebKit, the rendering engine that powers the browsers on the iPhone, iPad and Android phones. But what’s different about this round of monoculture is that, unlike IE 6, the WebKit developers haven’t done anything wrong. It’s web developers that have created the WebKit-only web.

Instead of writing code that will work in any browser, which might mean adding an extra three lines of code to their CSS rules, some of even the largest sites on the web are coding exclusively for WebKit.

The problem is bad enough that on Monday at the CSS Working Group meeting, Microsoft, Mozilla and Opera announced that each are planning to add support for some -webkit prefixed CSS properties. In other words, because web developers are using only the -webkit prefix, other browsers must either add support for -webkit or risk being seen as less capable browsers even when they aren’t.

The danger is that if other browsers implement -webkit prefixes then the entire CSS standards effort will be broken. Instead of coding against a single CSS specification developers will need to code against changing vendor prefixes. As CSS Working Group co-chair, Daniel Glazman, says, “I don’t think this is the right way. And this is the first time in this WG that we are proposing to do things that are not the right way.”

Vendor prefixes like -webkit and -moz were designed to help web developers by allowing browser makers to implement CSS features before the official standard was published. Prefixes were intended to help speed up the process of adding new features to the web and, used properly, they have worked. Unfortunately they’ve also been widely abused.

WebKit is currently the dominant mobile browser in the mind of most web developers (that Opera is actually the single most widely used mobile browser). But even the perceived dominance of WebKit is not the real problem. The problem is — just as it was last time — that web developers are developing exclusively for WebKit.

To be clear, Firefox, IE and Opera also support these features. In most cases, the -webkit properties being used have -moz, -ms and -o prefix equivalents for use in the respective browsers. Popular CSS 3 features like border-radius, transforms, gradients and animations work in all modern browsers. Developers simply need to add those three additional lines of code to make their websites compatible with Firefox, IE and Opera. But they aren’t doing that.

That the problem lies with web developers, not the browsers, led Glazman, to put out a call for action, asking web developers to “stop designing web sites for WebKit only, in particular when adding support for other browsers is only a matter of adding a few extra prefixed CSS properties.”

Neither Glazman, nor anyone else is suggesting that Apple and Google should stop innovating or stop implementing new features as fast as they can. As Tantek Çelik, a Mozilla representative in the CSS WG, says in the minutes of Monday’s meeting, “I think it’s great that Apple wants to innovate as fast as they can…. I don’t want Apple to slow down in innovation and implementing new things. That helps the Web grow and innovate.”

At the same time both Apple and Google have set some bad examples by building a number of WebKit-only demos that might be part of what lead some developers to conclude that only WebKit supports such features. That has also spilled over into the world of tutorials where even sometimes even standards advocates showcase -webkit in their sample code while ignoring -moz-, -ms- and -o-*.

What makes the current -webkit-only epidemic all the more depressing is how easy it is to solve — just use prefixes they way they were intended. Thanks to modern toolkits you don’t even need to write any extra code. Preprocessors like SASS and LESS make it easy to output five lines of prefixed code with a single mixin. Not a fan or SASS or LESS? No problem, just use cssprefixer, which parses your CSS and adds any prefixes you need before you publish it to the web (there’s also a client-side auto-prefixing solution if you prefer).

That’s fine for your website, but what about all the rest of those top 30,000 sites you don’t control? Well, you could email the developers, let them know that their site isn’t working in the most popular mobile web browser; let them know that you can’t use their service. If you’re a programmer or web developer you can help out with Mozilla developer Christian Hellman’s effort to Pre-fix the web. Pre-fix the web is looking for developers willing to seek out projects on Github that only work in Webkit and then fork the project, adding the missing prefixes to the CSS, extending JS code to do proper feature detection and then sending a pull request. In other words, literally fixing the web.

We at Webmonkey hope it’s obvious that building WebKit-only sites is a waste of time. If you’re only interested in iOS users then take a tip from Instagram and build a native app. As Peter Linss, Hewlett-Packard’s CSS WG representative says the CSS WG minutes, “there’s no advantage to the Web to have someone write a platform-specific website.” There’s also no real advantage for the developer, especially when an automated prefixer can do all the work for you. If you want your site to embrace the web, take the time to learn the craft and embrace all of the web. Be good at what you do and do it right.

Twitter Adds Responsive Design Tools to Bootstrap 2.0

Twitter is gearing up for the release of Bootstrap 2.0, the second major version of its popular open source front-end toolkit for web developers.

Bootstrap 2.0 will arrive Jan. 31, but if you’d like to take it for a spin today you can help test the pre-release build. Just head on over to GitHub and checkout the branch, 2.0-wip.

Bootstrap is designed to help you get your website up and running as fast as possible. Somewhere between a CSS framework and a “theme,” Bootstrap offers an HTML, CSS and JavaScript base for your designs, including built-in forms, buttons, tables, grids and navigation elements. Among Bootstrap’s more impressive tricks is the grid layout tool, which is based on the 960 grid system, with support for advanced features like nested and offset columns.

Bootstrap 2.0 will solve one of the bigger complaints about Bootstrap 1.0 — it was not responsive. To embrace a more responsive approach for mobile devices, Bootstrap is moving to a flexible 12-column grid system. The 2.0 release also includes some updated progress bars and customizable gallery thumbnails, but perhaps the best news is that, at just 10kb (gzipped), Bootstrap 2.0 remains an impressively lightweight framework.

While Bootstrap offers good browser support, with all the modern options covered you should be aware that it won’t work with Internet Explorer 6. To see some real world examples of what you can do with Bootstrap, head on over to the unofficial showcase, Built with Bootstrap on Tumblr.

Photo by Mike Love/flickr/CC.

File Under: CSS

CSS1K Showcases How Developers Can Do More With Less

CSS1K: light on the file size, heavy on variety

When the web standards movement first began to take off years ago one of its primary advocates, Dave Shea, launched CSS Zen Garden to showcase what designers could do using only web standards. CSS Zen Garden proved a huge hit, drawing hundreds of contributions from web developers around the world.

The web has changed considerably since the heyday of CSS Zen Garden. Today we can do just about anything using web standards like HTML and CSS, but now there’s a new problem — websites are getting fatter, as much as 25 percent fatter in the last year alone. Much of that added weight comes from JavaScript, but CSS shares some of the blame. According to HTTP Archive, the top 1,000 sites on the web load an average 30KB worth of CSS.

Inspired by CSS Zen Garden and driven by a desire to showcase what can be done with a mere 1KB of CSS, Jacob Rask, a web developer at Opera Software, created CSS1K about six months ago. Since then the site has showcased 68 different designs, all with stylesheets under 1KB.

The site is modeled on CSS Zen Garden, with a fixed set of HTML tags and content. Using that HTML base designers can then bend the basic frame to whatever look they’ve come up with — provided the total minified size of the CSS file is only 1KB.

Call it an effort in minimalism if you like, or simply think of it as a design constraint; either way designs submitted to CSS1K demonstrate just how much is possible with very little CSS. While no one is suggesting every website needs to be so constrained, playing with CSS1K is a nice reminder that you don’t always need huge stylesheets to create a nice-looking website.

If you’d like to participate in the CSS1K fun just fork CSS1K at GitHub and send your submission as a pull request. There is essentially only one rule — you can’t use data URIs, @font-face or @import statements to skirt the 1K CSS filesize limit. Note, however, that your 1K CSS file can be minified and any browser prefixes you need don’t count toward the total (in fact, you submit your code unprefixed and CSS1K adds the prefixes for you). For the full details and file requirements, head over to CSS1K.

File Under: CSS

Visually Stunning Redesign Showcases the 3-D Power of CSS

Steven Wittens' Acko.net features an impressive and unique 3-D header.

It’s one thing to hear about the powerful new 3-D tools coming to CSS, but it’s a very different thing to actually see them used creatively in the wild. Developer Steven Wittens recently did just that when he redesigned his Acko.net website. Wittens turned to the 3-D features in CSS 3 — with a little JavaScript help — to create a visually stunning 3-D page header.

To see the 3-D in action you’ll need to be using a WebKit browser (Safari or Chrome), though the site nicely degrades to a still very readable state for Firefox and other browsers that don’t yet support the 3-D rules coming to CSS. To get the full 3-D effect be sure to scroll down the page.

Wittens has a blog post detailing exactly how he pulled off the effects and he’s even built a 3-D editor you can play around with. Of the initial inspiration Wittens writes:

This idea started with an accidental discovery: if you put a CSS perspective on a scrollable <DIV>, then 3-D elements inside that <DIV> will retain their perspective while you scroll. This results in smooth, native parallax effects, and makes objects jump out of the page, particularly when using an analog input device with inertial scrolling.

This raises the obvious question: how far can you take it? Of course, this only works on WebKit browsers, who currently have the only CSS 3-D implementation out of beta, so it’s not a viable strategy by itself yet. IE10 and Firefox will be the next browsers to offer it.

To work around some of CSS limitations in the browsers, Wittens turned to Three.js, a JavaScript 3-D engine written by Ricardo Cabello, better known as Mr. Doob. For those interested in the code behind some of the transformation happening on Acko.net, Wittens has promised to release it via GitHub in the near future.

File Under: CSS

Dabblet: An Interactive CSS ‘Playground’ in Your Browser

Dabblet: Live CSS editing (even better with monkeys)

CSS guru Lea Verou has unveiled a new project, Dabblet, which she describes as “an interactive CSS playground.”

Inspired by online editors like JSFiddle, Dabblet is an interactive testing app for CSS — write some code and instantly see the results in the same window. The site works in most modern web browsers, including Chrome, Firefox and Safari (Opera support is in the works).

Unlike JSFiddle where the emphasis is clearly on JavaScript, Verou’s app is designed from the ground up to focus on CSS. Among Dabblet’s nice features are automatic vendor prefixing for CSS 3 properties (via Verou’s -prefix-free library). The prefix-free script means you can just write, for example, border-radius instead of -moz-border-radius, -webkit-border-radius, -o-border-radius and so on.

Perhaps the most useful feature though is that Dabblet can save all of your work as GitHub gists. Not only those that making sharing your work with others easier it also ensure that even if Dabblet doesn’t last forever you’ll still have your data on GitHub.

The Dabblet source code is available on GitHub if you’d like to contribute or fork it for you own project (it’s licensed under the NPOSL 3.0 which carries a non-profit restriction).

Dabblet is simple to use, just dive in and start writing some code. However, not all of the advanced features are immediately obvious so if you’d like to see a kind of guide to Dabblet, head over to Verou’s blog where she has a basic screencast that shows Dabblet in action.

File Under: CSS

CSS Trick Applies Fixed and Liquid Layouts to the Same Page

The debate over whether to use liquid or fixed layouts on the web is one of those perennial and not-very-interesting debates like Mac vs Windows or Emacs vs Vim. What if, however, there were a simple way to offer up both a fixed width and liquid layout on the same page? Peace on the web? Well, not exactly, but it’s a pretty clever trick nonetheless.

CSS guru Daniel Glazman (co-chairman of the CSS Working Group) shows you how to use just one pseudo class on a single HTML document and still create two different layouts, one liquid, one fixed.

In a fixed-width document named index.html, you usually have a rule setting the width or max-width of the main element. Something like

#main750 {
  max-width: 750px;
}

Right? Now think :target pseudo-class and tweak your style rule as followed:

#main750:target {
  max-width: 750px;
}

Glazman’s trick relies on the :target pseudo-class to change the layout parameters when the URL includes #main750. In other words, the URL ending in just index.html would have a liquid layout while index.html#main750 would have a fixed layout.

It’s not necessarily ideal in this particular form, and it could be triggered accidentally if you have any “jump” links in your page, but :target is an often underappreciated pseudo class. Opera’s Håkon Wium Lie has another example using :target to change the background color of a page and another commenter on Glazman’s blog offers up this much more complex pure CSS image zooming example which uses (among other tricks) :target to pan around a zoomed image.

File Under: CSS, Web Standards

A Possible Future for CSS Selectors

Woolly, the CSS sheep.

CSS has some great new tools like pseudo classes and pseudo elements for selecting things just by where they are in the DOM. For example, :first-child can select the first descendant of an element or ::first-letter can select the first letter of a sentence.

Even handier are the “::nth” selectors, which allow you specify arbitrary positions for selectors like :nth-child or :nth-of-type.

In fact, the ::nth selectors for pseudo classes and pseudo elements are so handy you might wonder why there isn’t just an ::nth for everything. That’s exactly what developer Chris Coyier calls for over at CSS-Tricks, saying that CSS should broaden the scope of ::nth to include, well, everything.

Among the possibilities with additional ::nth selectors are fancy typography effects like what Lettering.js can do (but without the JavaScript) or something a seeming simple as pure CSS line numbers.

While many of Coyier’s examples are undeniably great tools, they are also fraught with problems. For example the suggested ::nth-line would be entirely dependent on the current page layout. Even something as simple as resizing a window would require the browser to recalculate the rule adding a possibly significant performance overhead. Similarly ::nth-word becomes much more complex than it sounds when you take linguistic variations into account (just what constitutes a word varies considerably by language, CSS has to account for all those variations).

On the other hand a subsequent discussion on the W3C CSS Working Group mailing list has been somewhat positive about Coyier’s ::nth-letter suggestion. Indeed ::nth-letter is perhaps the most useful of Coyier’s suggestions, but even if it did make it into the CSS specification that’s no guarantee browsers would actually implement it.

As Coyier points out, this isn’t the first time someone has suggested adding ::nth for additional elements, Anne van Kesteren called for something similar back in 2003, which doesn’t give one high hopes for getting even ::nth-letter() in this time around. Still, a developer can dream.

See Also:

File Under: CSS, Web Standards

Discover What’s New in CSS 4

CSS 3 is still slowly making its way onto the web, but the World Wide Web Consortium (W3C), the governing body that oversees the development of web standards, is already plotting the future of CSS with CSS 4. The W3C recently released the first draft of CSS 4, adding dozens of new rules to make web developers’ lives easier.

The CSS 4 spec is brand new and no web browser actually supports any of these rules yet, but if you’re curious what the next few years will mean for CSS, the first draft offers a sneak peek at what’s in store for web developers.

The biggest news in the current draft of CSS 4 is support for the much-requested parent or “subject” selector. In CSS, rules are typically applied to the innermost selected element. That is, given the chain body header h1, the actual CSS rule will be applied to the h1 element at the end of the chain. CSS 3 offers no way to, say, style the header tag but only if it has an h1 child element. CSS 4 changes that.

CSS 4 includes a means of controlling which element in the selection chain is actually being styled. The easiest way to understand the “subject” selector is by example. Say you want to style a list (ul), but only when the user has clicked on an item in the list. You add a class “clicked” to the item (ul li.clicked) when the user clicks on it, but how do you style the whole list from that class?

With the subject selector it’s simple:

$ul li.clicked {
    background: white;
}

The “$” means that the rule is applied to the ul, rather than the li.clicked as it normally would.

The dollar sign may not end up being the subject indicator and the exact syntax will likely change before the spec is finalized. But regardless of the way it ends up being implemented, the subject selector opens up a whole new realm of CSS possibilities.

Other highlights in CSS 4 include some new pseudo selectors like the :matches() pseudo-class which greatly simplifies the process of writing complex, nested CSS. For example, you could write:

:matches(section, article, aside, nav) h1 {
  font-size: 3em;
}

The :matches() syntax eliminates the need to write out section h1, article h1 and so on. It’s handy for even simple nestings like the example above, but it becomes really powerful when you’re selecting elements that are two or three levels deep. For more info on :matches(), check out our earlier write-up on Mozilla’s :any() selector, which is the basis for :matches().

Also new in CSS 4 is the :local-link pseudo-class which allows you to style links based on domain. For example, you could style all internal links with a simple selector like a:local-link(0). The number refers to the amount of the local URL path to match. For example, if the current address is http://www.mysite.com/some/post/, a:local-link(0) would match anything point to http://www.mysite.com/, a:local-link(1) would match anything pointing to http://www.mysite.com/some/ and so on.

CSS 4 offers some handy pseudo-classes for styling user interface elements based on state, including :enabled, :disabled, :checked and half a dozen others.

For more info on what’s coming in CSS 4, check out the W3C spec (fear not, it’s surprisingly readable as specs go). Also worth a read is W3C WG member David Storey’s blog where he did a nice write-up on CSS 4, including a few things not covered here, like the awesome-sounding “time-dimensional pseudo-classes.”

[CSS pumpkin by mauricesvay/CC/Flickr]

See Also:

File Under: CSS, Web Standards

CSS ‘Paged Media’ Brings Book Smarts to the Web

Håkon Lie's mock ups of CSS Paged Content. Pagination shifts as screen size changes

What if you could flip through a regular news website like a magazine?

Håkon Wium Lie, Opera Software’s CTO and creator of cascading stylesheets, has proposed a new set of CSS tools that transform longer web pages into a more book-like experience, where the reader flips from page to page instead of scrolling down one long screen.

Lie’s proposal, the Generated Content for Paged Media standard, is a mouthful. But behind the awkward name lies an intriguing idea.

It’s a concept that’s gained considerable weight with the arrival of touchscreen tablets and smartphones, both of which lend themselves to very book-like reading experience. Indeed popular magazines, including Wired, all offer platform-native applications that mimic the reading experience of a book or magazine. That’s precisely what Lie wants to make possible on the web.

“The form, the presentation of content is important,” says Lie. “The turning of the page is an event, we anticipate what is on the other side, we look forward to it.” The endless scrolling of the web lacks such events, but Lie believes CSS can bring what’s good about reading in the real world to the web.

At its core, the Paged Media standard offers web developers a way to paginate content — that is, take a single webpage and break it into multiple “pages,” with each page automatically fitted to the screen size of the device you’re using. For example, this article might be three “pages” when viewed on an iPad. However, because the pagination is done with CSS and the HTML remains as it is, there’s no added load time when you flip to the next page. So it’s not a tool that can easily be abused by publishers to mine extra pageviews. It adds all the good things about multi-page layouts and none of the bad.

The Paged Media proposal isn’t just about pages, though; there are also tools defined for gestures — swiping to turn to the next page, or, at the end of an article to the next article (all built off the existing HTML rel=next/prev tags). There are also magazine-friendly layout tools, like the ability to float elements across multiple columns of text, as well as hyphenation rules and a means of styling footnotes.

If all that sounds like a very print-oriented set of tools, well, you’re right. Lie believes that the web is undergoing a fundamental shift in metaphors, one he compares to a similar shift that happened hundreds of years ago — the shift from scrolls to books.

This shift makes particular sense on tablets. The “flipping” action to turn pages on a tablet makes sense in the same way it made sense for newspapers to be pages rather than enormous scrolls. There is, after all, no reason the newspaper couldn’t be delivered just like a webpage — an enormous roll of paper that you unroll as you read. It’s not of course, because that’s not the ideal form factor for reading in the situations that people read newspapers. Nor is vertical scrolling ideal when you’re reading with a tablet. Paging is easier than scrolling on a tablet. Both are swiping gestures, but scrolling requires a controlled swipe to a selected area, whereas paging is a much less precise, and therefore easier, gesture.

Lie tells Webmonkey that he doesn’t believe the venerable scrollbar will go away, rather that the CSS Paged Media tools will offer another way to render web content. In fact, Lie thinks Paged Media would be a natural companion for CSS media queries, perhaps becoming another element of responsive design. By pairing the two, developers could nicely paginate a longer article for a magazine-style reading experience on tablets and revert to a more traditional layout for desktop browsers.

A magazine-style reading experience isn’t necessarily right for every site, but one of the markets Lie has in mind is one that’s already trying to put the magazine on your tablet — the publishing world.

Publishers are spending ever-increasing amounts of money developing and maintaining native apps across a variety of smartphone and tablet platforms. The majority of these apps are little more than content containers, niche browsers if you will. Most of them are just trying to recreate the paged layout of their print cousins. CSS Paged Media would allow that same content to be paginated the same way in any web browser, on any platform.

It’s an ambitious goal and one that won’t happen overnight, though Lie did say that very experimental support for the Paged Media standard would be available in a coming labs version of Opera 12.

More importantly, Lie’s proposal is already on the table. While he concedes there are many things to still be worked out — including how Paged Media will fit some of its layout tools alongside CSS Regions or how users will bookmark paginated content — David Hyatt, Apple’s Safari and WebKit architect, has already expressed some support on the W3C mailing list.

That’s good news — without widespread browser support Paged Media won’t be dragging the web out of the papyrus-crusted past any time soon.

See Also: