Cross-Browser Responsive Content with CSS Regions

In a recent post I described how you could use CSS Regions to easily create responsive content. One of the limitations mentioned though was that CSS Regions at present are natively supported only on Webkit nightly and Chrome Canary and Chrome Stable.

There is however the CSS Regions polyfill code up on GitHub to consider. I looked at that last year and it was a bit slow and problematic at the time.  It turns out though that there have been several improvements to the code in the interim and it works quite nicely and is quite performant now.  Let’s take a look…

Check out this Pen!

You can’t see it when the Codpen has been embedded in this post, but I’ve included cssregions.min.js in the JS tab.

Take a look at the CSS Tab.  Notice the new -adobe-flow-into and -adobe-flow-from CSS attributes:

#source {
  -adobe-flow-into: main-thread;
  -webkit-flow-into: main-thread;
  flow-into: main-thread;

.region {
  -adobe-flow-from: main-thread; 
  -webkit-fow-from: main-thread;
  flow-from: main-thread;

These new attributes are recognized by the polyfill.  They work the same as the -webkit-flow-into/from and flow-into/from attributes.  The polyfill code will detect and use any native implementations that exist so you don’t have to do anything special.  Everything should work exactly as it did before on WebKit and Chrome, but now it will also work on iOS4+, Android 4+, Firefox, Safari 5+, and Opera.   That’s right, mobile too!

Go ahead and view this post with the other browsers and devices listed above. The Codepen demo should work just fine (let me know if it doesn’t!).



Responsive Content Using CSS Regions

CSS Regions allow content to flow across multiple areas of the display, called regions.  The beauty of CSS Regions is that you can separate the content from the layout.  And with that comes the ability to create some responsive content very easily.

Update August 29, 2013: 

I have a new post describing Cross-Browser Responsive Content Using CSS Regions.  I describe there how you can do exactly what is described here, but also use the CSS Regions polyfill to get CSS Regions support on many other browser and devices.

Continue reading

Practical Gradient Map Use Case

I’ve been writing a few posts about the new gradientmaps.js library, and it occurred to me that gradient maps are a little hard to get your head around.  How would you use them in a real-world scenario?  From a pure creativity standpoint, they’re a no-brainer.  But are there any practical use cases?

Here’s a thought.  Say you’re selling shirts on your website.  You’re able to print the shirts in a myriad of colors and want to let the consumer pick the color they want.  In order to implement this, you could have an image for every possible color, or you could do the following (only works in Chrome & Firefox at present, sorry):

Check out this Pen!

In the above example, when you click on the color button and select a color, that new color is used as the right edge of a color gradient which starts with black.  So, if you choose red, the color gradient will go from black to red.  The image of the shirt you see has a transparent background.  And, if you’ll notice if you look at the JS tab, the start of the gradient is actually transparent itself “rgba(0, 0, 0, 0)”.  This is so we don’t recolor the background itself.

The resulting gradient is then applied to the image using:

GradientMaps.applyGradientMap($('img').get(0), gradient);

gradientmaps.js makes use of SVG filters being applied to HTML content.  At present that is only supported on Chrome and Firefox.

Pretty easy, and pretty useful. Play around with it and let me know what you think.

Implementing the Duotone Filter with an SVG Filter

In a recent post I described a duotone CSS Custom Filter I had built that allowed you to take a black and white image, and remap the black and white colors to two other specified colors.  Say you have a t-shirt website.  You could provide a single black and white image, and users could choose the color they want.

In the original implementation I used CSS Custom Filters, which are a little overkill for this use, and they are currently only supported on Chrome.  Here we’re going to do the same thing, using an SVG Filter.  SVG Filters are currently supported on both Chrome and Firefox and stand a much better chance of being implemented in other browsers sooner rather than later.

In particular, we’re going to use the ComponentTransfer filter primitive, described in more detail in this post.

Let’s take a look at the following SVG implementation (best viewed on Chrome and/or Firefox):

Check out this Pen!

When you click on either the black or white color remapping buttons, JavaScript is executed which recalculates the transfer functions for the feComponentTransfer filter primitives for each color channel.

In the following demo:

Check out this Pen!

We don’t use any JavaScript.  Instead, we’re using the SVG animate primitive to animate the table values of each transfer function (feFuncR, feFuncG, feFuncB).

For both of these examples, click on the HTML, CSS and JS tabs to see what’s going on and let me know if you have any questions.

As you can see, SVG filters are extremely powerful and worth learning more about.  Using them to manipulate HTML content is currently only supported on Chrome and Firefox but it looks very promising that they’ll be supported on all browsers before too long.

Advanced Gradient Map Usage

As you can read here, I’ve just open sourced gradientmaps.js, a library that allows you to apply Photoshop-like gradient maps to HTML content in Chrome and Firefox.

Now that the library is out there, let’s have a little fun. Continue reading

Announcing gradientmaps.js


I’ve just released gradientmaps.js on Github. You can use this library to apply gradient maps to any HTML content using SVG filters. You can find all the details on the Adobe Web Platform team blog:

The library makes use of SVG filters. As indicated on this table of browser support for CSS graphics, applying SVG filters to HTML content is currently supported only on Chrome and Firefox at present.

Check it out, it’s a ton o’ fun.