<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[Web Development | Divya Manian]]></title>
  <link href="http://nimbupani.github.com/categories/web-development/atom.xml" rel="self"/>
  <link href="http://nimbupani.github.com/"/>
  <updated>2013-12-12T19:27:38+05:30</updated>
  <id>http://nimbupani.github.com/</id>
  <author>
    <name><![CDATA[Divya Manian]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[Diversity in Conferences]]></title>
    <link href="http://nimbupani.github.com/diversity-in-conferences.html"/>
    <updated>2013-05-09T16:54:00+05:30</updated>
    <id>http://nimbupani.github.com/diversity-in-conferences</id>
    <content type="html"><![CDATA[<p>I have resisted the urge to contribute my thoughts every time drama around women and  minorities in technology occurs. I thought instead I would share with you some of the actions I have taken in various roles to try to make diversity more visible in conferences around web technology.</p>

<h1>As a Conference Organizer</h1>

<p>It was only when I took responsibility of selecting speakers for W3Conf that I realised how many of my first choices were just names I had heard of. It became very clear that merit played almost no part in the speaker selection: visibility did.</p>

<p>I also noticed my initial reluctance to choose first-time speakers as I didn't want my conference to "fail" (I am guessing this is fairly a common concern), and hence tried to select popular speakers. This does help drive some registrations from those who want to see such speakers in person. But then again, having only 1 or 2 of them would suffice.</p>

<p>If you are looking for these popular speakers to promote your event and boost the registrations through such promotions, you can forget that. Unless each speaker tirelessly blogs, tweets, and talks about your event at regular intervals, the impact of them talking about your event is fairly minimal. If this was a reason for you to choose only popular speakers, then you should probably try another tactic.</p>

<p>Many conference organizers also fear having speakers who are boring or who might get stage fright and hence are very cautious in only chosing those who have proven themselves worthy as speakers. For W3Conf, I was confident that getting speakers who were interesting and worked on interesting projects was more important than their ability to speak or present.</p>

<p>I was very happy to see this was validated as the passion of each of the speakers came across as a far more compelling force than their articulation or their ability to punctuate their words with pauses.</p>

<h2>Where to find these people?</h2>

<p>I am very lucky to be in a place (metaphorically and physically) that puts me in touch with interesting people on a fairly regular basis without even trying to find them. Even then, I blanked when I was starting with who to select for the speakers for W3Conf.</p>

<p>One of the tricks I employed was to find an acknowledged expert in a field I was looking for a speaker in, and trawl the list of people <strong><em>they</em></strong> follow. I followed links to open-source projects and then reached out to them via email or Twitter.</p>

<p>I also asked people I trusted for names of people who were not well known but worked on interesting projects.</p>

<h2>What about diversity?</h2>

<p>It was always at the back of my mind to make this conference as diverse as possible. I didn't set out wanting to tick off a quota, but rather having a healthy mix of people from various backgrounds working on interesting stuff.</p>

<h2>What about quotas for conferences?</h2>

<p>I have come across conference organizers having a check list ("we hope to have 2 women speakers in our conference"). While it would be a good success metric, I do not think having it as the only factor helps anyone. People who are requested to speak at conferences in that manner get disgusted at being token speakers.</p>

<p>If you are a conference organizer, don't reach out to people suggesting they have been contacted only because you are obligated to fill your quota.</p>

<h2>What about reverse call for speakers?</h2>

<p>The idea looks great at first glance, but I am afraid the same challenge of only recalling popular names that had impressed the conference organizers would manifest itself even more significantly in the audience. Most of them wouldn't know which speaker would be worth listening to because they would have even less of an opportunity to come across people working on interesting projects. I also think one of the primary reasons people attend conferences is to find out about what interesting projects exist.</p>

<h1>As a Speaker</h1>

<p>Over the last two years I have given more than 20 talks, which has given me some level of visibility/name recognition in web technology. This means I get asked to speak many times at conferences most of which I have to decline because of work schedule conflicts.</p>

<p>I also know from my experience how much effort it is to select speakers, so I always ask the organizers if they would like some suggestions on who would be good speakers for their conference. Almost always they welcome suggestions and I send a list of those who I think should be heard from more. Invariably they are a mix of people who are less-prominent, but do exceptional work. Diversity is at the heart of such lists.</p>

<h1>As an Employee of a Company that Sponsors Events</h1>

<p>I work at Adobe which sponsors many events. I am also in a position to recommend events to sponsor. I try to recommend relevant events that may not be prominent but work on having as many people as possible from diverse backgrounds to attend or speak. They may or may not have charters that state their commitment to diversity, but nevertheless their actions speak louder than words.</p>

<p>I am also trying to push for sponsorships of events that show clear commitment to diversity in their speakers and/or attendance profiles. One thing I have learnt over the course of working at American companies is your views are most often heard, and while immediate actions may not be possible, the more people who strongly present the case, the earlier shifts can happen. So, if you think you are a mere cog in the wheel of a large corporation, think again. You have more power than you think.</p>

<p>It always helps when reaching out to the people who actually sponsor events at your company to make a strong case based on facts instead of complaining about the lack of diversity in sponsored events of the past.</p>

<p>If you find yourself in one of these roles, and want to showcase the diversity in our web world, please do try out these and let me know how they worked for you.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Using decimal percentage values in responsive design]]></title>
    <link href="http://nimbupani.github.com/using-decimal-percentage-values-in-responsive-design.html"/>
    <updated>2013-03-26T04:24:00+05:30</updated>
    <id>http://nimbupani.github.com/using-decimal-percentage-values-in-responsive-design</id>
    <content type="html"><![CDATA[<p>At work I get many samples of code to be reviewed, most of them with a warning 'only works in Chrome'. Nevertheless, I open these pages in Safari &amp; mostly they work. Yesterday I came across something that didn't. This post is a result of that investigation.</p>

<p>The page layout was broken in Safari and as I turned on the Inspector, I noticed the way the values were being specified:</p>

<pre>
margin: 0 0 0 6.3124621208203820812122%;
width: 48.121212121212121212121212%
</pre>


<p>(The values are not the same as the ones I saw in the code, but the number of decimals used is similar)</p>

<p>I was stupified.</p>

<h2>Unreadable Code</h2>

<p>When values are so large, it becomes really hard to actually understand the exact round number equivalent. It took me a while to realise that the margin was supposed to be approx. 6% of the (pause) 48% width. I know I am not that bad at calculating numbers in my head!</p>

<p>Over-preciseness never worked in WebKit until very recently. WebKit <a href="http://trac.webkit.org/wiki/LayoutUnit">recently enabled subpixel units</a> that would allow the painting of half a pixel. So what are these precise decimals doing?</p>

<h2>History</h2>

<p>I expressed <a href="https://twitter.com/divya/status/316284818675625985">my disappointment at having such unreadable code</a> on twitter (where else do you rant?!), and I received feedback that this is how 'responsive design' is done, and for pointers linked to the <a href="http://alistapart.com/article/responsive-web-design">original article by Ethan Marcotte</a> who pointed to <a href="http://alistapart.com/article/fluidgrids">initial post on fluid design</a>.</p>

<p>The use of percentages stem from the Fluid Grids post, where it has been argued:</p>

<pre>
(target pixel value / context pixel value) * 100 = length value in percentage
</pre>


<p>This percentage value is typically pasted to the whole 10 decimal places (or more!) that you get when you use a calculator in typical 'responsive' websites.</p>

<h2>Why we do it</h2>

<p>The article has a footnote on rounding that states that, by over-specifying the values you avoid Rounding errors because you give sufficient information to the browser to round up or down.</p>

<p>All browsers have since fixed the rounding issue, so this may no longer apply. Even discounting that fact, let us see how many decimal values you need for the errors to be significant enough to cause layout errors. Given the previous math, the target pixel size becomes:</p>

<pre>
target pixel value = length value in percentage * context pixel value
</pre>


<p>Lets calculate what the target pixel width would be with just 2 decimal places, when the context is 1000px &amp; 5000px respectively. 5000px is an outlier given even <a href="http://en.wikipedia.org/wiki/Retina_Display">Retina Display resoution does not exceed 2560 pixels</a>:</p>

<pre>
16.67% * 1000px = 166.7px
16.67% * 5000px = 833.5px
</pre>


<p>Let us try to calculate the same result with 3 decimal places:</p>

<pre>
16.667% * 1000px = 166.67px (-0.03 from previous value)
16.667% * 5000px = 833.35px (-0.15 from previous value)
</pre>


<p>How about for 4 decimal places?</p>

<pre>
16.6667% * 1000px = 166.667px (-0.003 from previous value)
16.6667% * 5000px = 833.335px (-0.015 from previous value)
</pre>


<p>While the difference in the approximation seems significant enough to consider using 3 decimal places, the move to 4 decimals or more seems irrelevant. The values are fairly trivial even for impossible pixel widths.</p>

<h2>How should we do it?</h2>

<p>If your intent is to inform the browser to take accurate action based on a fraction. Why not provide that fraction? CSS provides a handy <code>calc</code> function that allows you to pass in any calculation, and the browser will calculate appropriately. This would result in:</p>

<pre>
h1 {
 width: calc(1/6 * 100%);
}
</pre>


<p>Do note <a href="http://caniuse.com/calc"><code>calc</code> is supported in most browsers</a> except Opera (which will soon when it switches to WebKit) or older iOS or Android browsers.</p>

<p>But in the interest of graceful degredation, we can always provide:</p>

<pre>
h1 {
 width: 16.667%;
 width: calc(1/6 * 100%);
}
</pre>


<h2>A note about ems</h2>

<p>As <a href="https://twitter.com/scottjehl/status/316350378809647105">Scott Jehl pointed out</a> the decimal values raise in significance as soon as you start using them directly on em units like so:</p>

<pre>
h1 {
 font-size: 36em;
 margin: 0 0 0 0.009em;
}
</pre>


<p>I would only want you to consider using <code>rem</code> as a unit instead, &amp; avoiding confusing complicated scenarios ems bring with them.</p>

<h2>Think before you use!</h2>

<p>In HTML5 Boilerplate, most of the code we add or delete have valid proven reasons for their existence or non-existence, so to see something be accepted as common methodology without scrutiny was disconcerting. Many have suggested they have previously come across problems with smaller decimal values, but there is no reproducable test case.</p>

<p>If you have one, please do <a href="http://twitter.com/divya">let me know on twitter</a>.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Using background clip for text with CSS fallback]]></title>
    <link href="http://nimbupani.github.com/using-background-clip-for-text-with-css-fallback.html"/>
    <updated>2013-02-02T14:25:00+05:30</updated>
    <id>http://nimbupani.github.com/using-background-clip-for-text-with-css-fallback</id>
    <content type="html"><![CDATA[<p>I was looking at the lovely design of <a href="http://polygon.com">polygon</a> when their use of <code>background-clip</code> &amp; <code>background: linear-gradient(…)</code> immediately suggested a JS-free fallback for using the non-standard <code>background-clip: text</code>.</p>

<h2>What it is</h2>

<p><code>background-clip</code> is a CSS property that was <a href="https://www.webkit.org/blog/164/background-clip-text/">originally introduced in WebKit (in 2008)</a> that allows backgrounds specified on elements to clip to the text content of the element like so:</p>

<p><img src="http://s3.amazonaws.com/nimbublips/1359844612.png" alt="" /></p>

<p>by merely using the following code:</p>

<pre>body{
 color: transparent;
 background: url(path/to/bg/image) repeat;
 -webkit-background-clip: text;
}
</pre>


<p>However, <code>background-clip: text</code> is not part of any standard yet – but <a href="http://dev.w3.org/csswg/css3-background/#the-background-clip">other values such as <code>border-box</code> or <code>content-box</code> are</a>.</p>

<h2>The Problem</h2>

<p>It is no surprise to find people using non-standard properties in HTML, and it is no big deal if it fails gracefully in other browsers. Unfortunately, <code>background-clip: text</code> fails rather spectacularly in non-WebKit browsers:</p>

<p><img src="http://s3.amazonaws.com/nimbublips/1359844975.png" alt="" /></p>

<p>The above is how it appears (when you use <a href="http://placekitten.com">placekitten</a> to generate the background image) in Firefox. You cannot even read the text! This is clearly a disastrous situation.</p>

<h2>Current Solutions</h2>

<p>The most commonly used solution is to use <a href="http://modernizr.com">Modernizr</a> to detect if <code>background-clip: text</code> is available, and then use a class <code>backgroundcliptext</code> to apply <code>background-clip:text</code> selectively – <a href="http://polygon.com">Polygon</a> does this too.</p>

<h2>Purely CSS solution</h2>

<p>While looking at the code, I suddenly realized that if you use only the <code>-webkit-</code> prefixed value for <code>background</code> property, then <code>background-clip: text</code> would only apply when <code>-webkit-</code> prefixed values are supported in browsers – effectively curtailing its use to WebKit browsers:</p>

<pre>body {
 color: transparent;
 background: -webkit-linear-gradient(transparent, transparent),
             url(path/to/bg/image) repeat;
 -webkit-background-clip: text;
}</pre>


<p>Hurray! We are almost there! The background no longer appears in non-WebKit browsers:</p>

<p><img src="http://s3.amazonaws.com/nimbublips/1359845371.png" alt="" /></p>

<p>…until you test in Opera, which also <a href="http://my.opera.com/ODIN/blog/opera-12-10-is-out">supports <code>-webkit-</code> prefixes for site compatibility</a>. But, it is easy to solve for by merely adding <code>-o-</code> prefixed background value:</p>

<pre>body {
 color: transparent;
 background: -webkit-linear-gradient(transparent, transparent),
             url(path/to/bg/image) repeat;
 background: -o-linear-gradient(transparent, transparent);
 -webkit-background-clip: text;
}</pre>


<p>But, wait, the <code>color: transparent</code> would make the text invisible in all browsers! Let us change that to a readable color:</p>

<pre>body {
 color: red;
 background: -webkit-linear-gradient(transparent, transparent),
             url(path/to/bg/image) repeat;
 background: -o-linear-gradient(transparent, transparent);
 -webkit-background-clip: text;
}</pre>


<p>But now the color fills the text, and the clipped background is no longer shown in WebKit browsers :(</p>

<p><img src="http://s3.amazonaws.com/nimbublips/1359845928.png" alt="" /></p>

<h2><code>text-fill-color</code> to the rescue</h2>

<p><a href="https://www.webkit.org/blog/85/introducing-text-stroke/"><code>text-fill-color</code> (introduced in 2006)</a> fills text with a color when used in conjunction with a <code>text-stroke</code>. It behaves exactly like <code>color</code> except we now have the advantage of having it apply only to WebKit browsers! Nirvana!</p>

<pre>body {
 color: red;
 -webkit-text-fill-color: transparent;
 background: -webkit-linear-gradient(transparent, transparent),
             url(path/to/bg/image) repeat;
 background: -o-linear-gradient(transparent, transparent);
 -webkit-background-clip: text;
}</pre>


<p>Here is how it appears in WebKit browsers and non-WebKit browsers respectively:</p>

<p><img src="http://s3.amazonaws.com/nimbublips/1359846393.png" alt="" /></p>

<p>You only have to use 2 extra css properties, to make it fail-safe in all browsers and need not run a feature-detection script. Currently, only Opera requires the background reset using the <code>-o-</code> prefix, but if more browsers start supporting <code>-webkit-</code> prefix then each of those browsers need a reset (e.g. <code>background: -moz-linear-gradient(transparent, transparent);</code>). But I don't think this will happen.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Markup-free icon fonts using unicode-range]]></title>
    <link href="http://nimbupani.github.com/markup-free-icon-fonts-with-unicode-range.html"/>
    <updated>2012-12-25T08:58:00+05:30</updated>
    <id>http://nimbupani.github.com/markup-free-icon-fonts-with-unicode-range</id>
    <content type="html"><![CDATA[<p>I used icon fonts extensively while designing <a href="http://fripfrap.io">fripfrap.io</a>. Unfortunately, icon fonts require tags wrapped around where they should be placed, and I went on a quest to find out if we can adaptively render icon fonts without any extra markup.</p>

<h2>Icon Fonts</h2>

<p>Icon fonts are easy clean way to render icons across all sizes of text. The other advantage is you can apply all the text controls that are available including <code>text-shadow</code>, <code>vertical-align</code>, <code>font-size</code> to tweak the output as you like, instead of fiddling around in SVG or with image sprites (<a href="http://blog.pictonic.co/post/32869817328/svgs-are-cool-but-icon-fonts-are-just-10-of-their">here are more details on why icon fonts are better</a>). The typical usage of icon fonts as pioneered by <a href="http://lab.simurai.com/buttons/">@simurai</a> is:</p>

<pre>[data-icon]::before {
    content: attr(data-icon);
}</pre>


<p>Then, when you generate custom icon fonts using services like <a href="http://icomoon.io/app">icomoon</a>, you can specify a character that will be used to represent that icon and use that as the value of the icon in the mark-up. For example, to render the twitter icon, I select the Twitter icon from one of the various free icons available on icomoon, and then set the character to be 't' in the app, and download the font:</p>

<p><img src="http://s3.amazonaws.com/Gyazo/1356408460.png" alt="" /></p>

<p>In your markup, you declare:</p>

<pre>&lt;b data-icon=t>subscribe on twitter&lt;/b>
</pre>


<p>This markup in combination with the CSS we declared earlier, would <a href="http://codepen.io/nimbupani/pen/fdlLe">render the twitter icon like so</a>:</p>

<p><img src="http://s3.amazonaws.com/Gyazo/1356408772.png" alt="" /></p>

<h2>Problem with Using Icon Fonts via Generated Content</h2>

<p>The first problem with this technique is Screen readers would read the alphabet used for the property <code>content</code>. This means, a person who uses a screen reader to navigate would hear 't twitter' rather than just 'twitter'. This obviously is not so fun.</p>

<h2>Using Private Use Area for Icon Fonts</h2>

<p>Fonts are basically key value pairs, with the key being the character and the value a glyph (a path representation). For example, you see these letters in this post because the browser comes across a character, looks up the table for the font specified, &amp; uses that glyph to render that character (e.g. 'a' or 'b' or '.'). The universal standard that is being increasingly adopted is called <a href="http://www.joelonsoftware.com/articles/Unicode.html">Unicode</a>.</p>

<p>There is a whole range of key-value pairs within the Unicode table that are deliberately empty and that range is called Private Use Area (PUA).</p>

<p>We can use this area to reference icon fonts. Using <a href="http://icomoon.io/app">Icomoon's icon font generator</a>, you can specify your icon as the glyph to represent a character from this PUA range:</p>

<p><img src="http://s3.amazonaws.com/Gyazo/1356429440.png" alt="" /></p>

<p><a href="http://icomoon.io/#docs#screenreaders">Icomoon's documentation covers more details on how to use this</a>. Essentially, it is as simple as specifying the character used for the icon to be one from the Private Use Area (PUA) and using the HTML entity equivalent as a value for the <code>data-icon</code> attribute:</p>

<pre>&lt;b data-icon='&amp;#xe000;'>subscribe to twitter&lt;/b></pre>


<p>This would solve the problem of having screen readers read out icon fonts incorrectly, but it still leaves us with an extra set of tags, attribute (<code>data-icon</code>) &amp; associated style that I think we could do without. This we can do with the CSS property called <code>unicode-range</code>.</p>

<h2>Unicode Range</h2>

<p>I previously mentioned <code>unicode-range</code> in my <a href="http://nimbupani.com/jscamp-css-next.html">round-up of what is new in CSS</a>, &amp; how it can be used to <a href="http://24ways.org/2011/creating-custom-font-stacks-with-unicode-range/">enhance an existing ampersand</a>. I also have been wondering if unicode-range in combination with icon fonts set in Private Use Area could be used to render icons.</p>

<p>The markup then would merely be:</p>

<pre>&amp;#xe000; subscribe to twitter</pre>


<p>While the font-face declaration would change to:</p>

<pre>@font-face {
    font-family: 'icons';
    src: url(path/to/font.woff) format('woff');
    <b>unicode-range: U+E000-U+E005;</b>
}</pre>


<p>Then, when you define the base font:</p>

<pre>body {
   font-family: <b>icons</b>, sans-serif;
}</pre>


<p>This would render the icons inline with no other additions. This is nice, but previously with the <code>data-icon</code> process we could very easily hide or show icons based on Media/Feature queries by simply doing:</p>

<pre>@media (max-width: 400px) {
    [data-icon]::before { content: none; }
}</pre>


<p>But with inline icons, removing the font from the <code>font-family</code> would leave you with the empty rectangular glyph ():</p>

<p><img src="http://s3.amazonaws.com/Gyazo/1356426010.png" alt="" /></p>

<p>Does this mean, using unicode-range for fonts is a bust? Do we still need markup around these icons? There is a way out!</p>

<h2>Layout Font to the Rescue</h2>

<p>When I was wondering how to prevent this on Twitter, <a href="http://twitter.com/derschepp">Christian Schaefer</a> suggested the use of <a href="https://github.com/jonathantneal/layout-webfont">Layout Font</a> (a font that <a href="http://www.jonathantneal.com/">Jonathan Neal</a> invented to solve the problem of white-space impacting layouts using <code>display: inline-block</code> in CSS). The layout font merely replaces every glyph with what appears to be a "no space" in the font table. This will mean browsers when using this font would represent white space effectively as no space.</p>

<p>Now I was trying to figure out how to transform this font into one that would have this same "no space" as the value for all unicode characters. At this juncture, <a href="http://twitter.com/keyamoon">Keyamoon</a> came to the rescue by creating a <a href="http://codepen.io/Keyamoon/pen/bnwDL">base-64 encoded version of the layout font</a>.</p>

<p>And so, we are satisfied! Here is an example of how to use icon fonts with <code>unicode-range</code> but with a graceful fallback in case we do not want to render these icons any more.</p>

<pre>@font-face {
    font-family: space;
    src: url(data:application/x-font-woff;charset=utf-8;base64,d09GRk9UVE8AAAOYAAsAAAAABUwAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABDRkYgAAABCAAAAIQAAACQ1P+0gUZGVE0AAAGMAAAAGgAAABxjhaFsR0RFRgAAAagAAAAbAAAAIAAvAARPUy8yAAABxAAAAEsAAABgP9zcNGNtYXAAAAIQAAAAOgAAAUrgERK3aGVhZAAAAkwAAAAuAAAANvsbcvdoaGVhAAACfAAAAB0AAAAkBBD942htdHgAAAKcAAAACAAAAAgAAAAAbWF4cAAAAqQAAAAGAAAABgACUABuYW1lAAACrAAAAN4AAAGJ242MgnBvc3QAAAOMAAAADAAAACAAAwAAeJw9zUEKwjAQRuF/kkhKDa2WKgqjZ8gJXHoBj+CqSJtNK3gCkdnmsLMQFEHdvdX3CM6BiIrunPqUBpAB4aBsdGd14yRYCW5fYntqXiL/CF4umnWcMa41AwvGbcnwjEcD+zEK1FhPQ3eMMX7x3wOgOwyRmVc6umfW7CtpZSWhfANCyyLweJxjYGBgZACCk535hiD6zD9JWRgNAEIVBfQAAHicY2BkYGDgA2IJBhBgYmCEQhYwjwEABFUANAB4nGNgZvzCOIGBlYGD0YcxjYGBwR1Kf2WQZGhhYGBiYGVmgAMBBJMhIM01hcHhA8MHBsYH/x8w6DE+YFBoYGBghCtQAEJGAGqIDSIAeJxjYGBgZoBgGQZGBhBwAfIYwXwWBg0gzQakGRmYGBg+MPz/D1IAoQUYoeqBgJGNAcEZoQAAbecGtwAAeJxjYGRgYADiTz08rvH8Nl8ZuJkYQODMP0lZBP3/ARMD4wMgl4MBLA0AIQUKSgAAeJxjYGRgYHzw/wGDHgMQ/GNgAnIZUAETAG2yA/MAAAAAAAAAAAAAAAAAUAAAAgAAeJx1jjFOAzEQRd8mmyAUhKgQpQsKml3ZVqocYEVNkT6KrNVKSSw5SZOD0HIESo7BATgCl+DHcUMRSyM/f/+ZP8Ad71ScT8UND4VH4pfCY545Fa6lfxaeMOO78FT6r5xVfSvlPnedeSR+KjzmFVu4lv5ReMIjX4Wn0n8YWBPZqiI7GNZxG6PgjUDPkQ0rkp6hP25Wgi77DvlOcgQMnlZphoXq/7yL5pnT4HQ3KpuJLu4OXUx9ML61ZmFKssjPG+cbb51c19ZbKjix1/8lxuUVWIa0HzTEtfZq7x+jCTpIAAB4nGNgZsALAAB9AAQ=) format('woff');
}

body { font-family: <b>icons</b>, sans-serif; }

@media (max-width: 400px) {
    body { font-family: <b>space</b>, sans-serif; }
}</pre>


<p>You can see this <a href="http://nimbu.in/private-use-unicode">adaptive icon font in action here</a>.</p>

<h2>Browser Support</h2>

<p>Why do you trouble me with reality? :| I previously erroneously stated that <code>unicode-range</code> is supported amongst all browsers, but this is not the case. It is only supported in Safari &amp; Chrome.</p>

<p>This method maybe useful when <code>unicode-range</code> is more widely supported, but all I wanted to do was to find new ways to kill fluffy markup.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[JSCamp: CSS Next]]></title>
    <link href="http://nimbupani.github.com/jscamp-css-next.html"/>
    <updated>2012-12-01T06:09:00+05:30</updated>
    <id>http://nimbupani.github.com/jscamp-css-next</id>
    <content type="html"><![CDATA[<p>I talked at <a href="http://jscamp.asia">JSCamp</a> on 28th November 2012, on some of the newer features of CSS. I gave the talk without slides, so here is a description of all that I covered.</p>

<h2>No CSS3 or CSS4</h2>

<p>Before I delve into what the newer features of CSS that I am very interested in are, I want to clarify a myth that persists on how there are varying ‘versions’ of CSS like CSS3 and CSS4. <a href="http://www.xanthir.com/b4Ko0">Tab Atkins wrote in detail about why there is no CSS3</a>. Essentially, work after <a href="http://www.w3.org/TR/CSS21/">CSS 2.1 specification</a> has been split into independent modules that can all reach stability independent of each other, so specifications can become stable and recommendations faster.</p>

<h2>Typography</h2>

<p>The <a href="http://dev.w3.org/csswg/css3-fonts/">Font Module</a> has a couple of interesting features that are worth looking at.</p>

<h3>Open Type Features</h3>

<p><a href="http://timepiece.inostudio.de/"><img src="http://s3.amazonaws.com/Gyazo/1354317414.png" alt="" /></a></p>

<p>Open Type Fonts have a features file that exposes ligatures (and other features) to applications that understand and enable these. Till recently browsers did not have the ability to expose these features that would allow you to use these ligatures from within stylesheets. But now you can.</p>

<p>To do this, you would have to use <code>font-feature-settings</code> like so (you must add the appropriate prefixes <code>-ms</code>, <code>-webkit-</code> &amp; <code>-moz-</code> &amp; <code>-o-</code> when Opera supports it):</p>

<pre>h1 {
 font-feature-settings: 'liga';
}</pre>


<p>This tells the browser to enable Common Ligatures in the Open Type font.</p>

<p>Georg Seifert of <a href="http://glyphsapp.com">Glyphs</a> has created a very cool font that <a href="http://timepiece.inostudio.de/">exploits these ligatures to create a lovely clock</a>.</p>

<h3>Unicode Range</h3>

<p>Fonts are essentially a table of glyphs that represent each code point. Browsers look up the table for each code point and render that glyph on the screen.</p>

<p>The @font-face rule used to specify web fonts can include a declaration for <a href="http://dev.w3.org/csswg/css3-fonts/#unicode-range-desc"><code>unicode-range</code></a>. When this property is declared, the browser knows that the font specified in the <code>@font-face</code> rule must only be used when that range of <a href="http://www.joelonsoftware.com/articles/Unicode.html">unicode code points</a> are found in text. This way, <a href="http://rishida.net/blog/?p=760">you can control the rendering of English letters when they occur in conjunction with letters of another language</a> instead of defaulting to system fonts. Here is how you would use them:</p>

<pre>@font-face {
  font-family: myJapanesefont;
  src: local('Bookman Antiqua');
  unicode-range: U+41-5A, U+61-7A, U+C0-FF;
}</pre>




<pre>h1 {
  font-family: myJapanesefont, MS-Mincho;
}</pre>


<p>But this property is also useful if you want to specify better ampersands or use fonts as icons.</p>

<h3>Better Ampersands</h3>

<p>A few years ago, it was all the rage to use a different font for the ampersands (&amp; symbol) than the current one. The way this was done was to wrap the symbol in a <code>&lt;span class='amp'&gt;</code> and then use a different font-family for the class <code>.amp</code>. With <code>unicode-range property</code>, you could merely use the @font-face rule to specify the font you want to use for that particular character (specified with <code>unicode-range</code>) and not bother at all with adding extra tags.</p>

<p>This method is described in detail by Drew McLellan in his <a href="http://24ways.org/2011/creating-custom-font-stacks-with-unicode-range/">24 Ways article</a>.</p>

<p><a href="http://nimbu.in/jscamp/unicode-range.html">Demo of using Baskerville font for &amp; symbol</a>.</p>

<h3>Font Icons</h3>

<p>The unicode tables have a private-use space allocated that would allow any font creator to use that space to create glpyhs that are not standard (e.g. glyphs that do not represent Latin, or other language characters or standardized symbols). Using this area of the table, you could create icons in a font, and only have these icons render on screen when the font itself is used.</p>

<p>This is what <a href="https://github.com/blog/1135-the-making-of-octicons">GitHub uses</a> for their <a href="https://github.com/styleguide/css/7.0">Octicons</a>.</p>

<h2>Layout</h2>

<h3>Exclusions</h3>

<p><a href="http://dev.w3.org/csswg/css3-exclusions/">Exclusions</a> would allow you to wrap text within a specified shape. Currently an implementation of <code>shape-inside</code> property that would allow text to wrap <em>within</em> a path is available in Chrome Canary. <a href="http://twitter.com/bear_travis">Bear Travis</a> wrote <a href="http://betravis.github.com/shape-tools/polygon-drawing/">a tool for determining polygon shapes</a> that can be used for generating the path. In brief, you would use it as such:</p>

<pre>.crow {
  shape-inside: polygon(0 0, 0 100%, 100% 100%, 100% 0);
}</pre>


<p><a href="http://nimbu.in/jscamp/shape-inside.html">Demo of shape-inside</a> (<em>turn on 'Enable Experimental WebKit Features' in chrome:flags in Chrome Canary to see this</em>)</p>

<h3>Regions</h3>

<p><a href="http://dev.w3.org/csswg/css3-regions/">Regions specification</a> has features that allows your content to be separate from the layout structure.</p>

<p>First you declare which elements will be part of the named flow of content:</p>

<pre>.news-items {
  flow-into: newsflow; /* name of the flow */
}</pre>


<p>Then, you declare which elements will be the recepients of the content within the named flow:</p>

<pre>.news-items-container {
  flow-from: newsflow; /* name of the flow */
}</pre>


<p>This means, all elements that have the class <code>news-items-container</code> will no longer display content they originally had, but will only display content that flows into them through the named flow called <code>newsflow</code>.</p>

<p>The <a href="http://blogs.adobe.com/webplatform/2012/09/27/web-inspector-support-for-css-regions/">Web Inspector in Chrome Canary</a> has a way to debug which elements are part of a flow and which are recepients of a flow.</p>

<p><a href="http://nimbu.in/jscamp/regions.html">Demo of regions</a> (<em>turn on 'Enable Experimental WebKit features' in chrome:flags in Chrome Canary to see this</em>)</p>

<h2>Graphics</h2>

<h3>Native Filters</h3>

<p>It is now possible to use image processing functions such as <code>greyscale</code>, <code>sepia</code>, <code>blur</code> on HTML and SVG elements. You can do this by using a CSS property known as <code>filter</code> like so:</p>

<pre>.banner {
  filter: blur(10px);
}</pre>


<p>These are known as <em>native</em> filters as the functions are provided out of the box by browsers. You can use this feature in Safari 6, Mobile Safari &amp; Chrome.</p>

<p>Here is how blur has been used to <a href="http://codepen.io/vcurd">simulate depth of field</a>.</p>

<h3>Custom Filters</h3>

<p>Instead of using browser-provided filters, you can use your own. To do this, you would use <a href="http://www.w3.org/TR/filter-effects/#feCustomElement">GLSL shaders</a> - that are typically used in WebGL - via custom filter function.</p>

<pre>.banner {
 filter: custom(url(/path/to/shader.vs));
}</pre>


<p>The above declaration tells the browser to create vertice maps for each element that matches the selector, run them through the shader provided within the custom function and finally render the results on the screen. The interesting thing is these shaders can also take custom arguments that would determine the extent to which you want to apply these shaders.</p>

<p><a href="http://twitter.com/alteredq">Altered Qualia</a> has a <a href="http://alteredqualia.com/css-shaders/article">great in-depth article on how to write and use Shaders for Custom Filtering</a>. You can also play with some of the custom filters on <a href="http://html.adobe.com/webstandards/csscustomfilters/cssfilterlab/">CSS FilterLab</a></p>

<p><a href="http://nimbu.in/jscamp/custom-filters.html">Demo of Custom Filters</a> (<em>turn on 'Enable CSS Shaders' in chrome:flags in Chrome Canary to see this</em>).</p>

<h3>Blend Modes</h3>

<p>In Photoshop and other Graphic Editing tools, there has always been an option to specify how each layer interacts with other layers below it. This is typically specified using a dropdown of blend modes that have values such as 'overlay', 'multiply', 'darken', 'lighten', 'difference', etc.</p>

<p>My team at Adobe has been working on a <a href="http://adobe.github.com/web-platform/demos/compositing/">specification and a prototype build</a> out that brings the power of those blend modes to the web via CSS. This would happen via specifying the property <code>blend-mode</code> on the elements you want to target:</p>

<pre>.banner h1 {
    blend-mode: difference; 
}</pre>


<p><a href="http://adobe.github.com/web-platform/demos/compositing/blend-photogallery/index.html">Demo of blend modes</a> (<em>use this <a href="https://github.com/adobe/webkit/downloads">prototype build of Chromium</a> to view this</em>).</p>

<h2>Responsible Styling</h2>

<p>You must use styles responsibly, especially properties such as flex box which can lead to drastically unreadable results in unsupported browsers. Previously, <a href="http://modernizr.com">Modernizr</a> came to the rescue. But now, there is a <a href="http://www.w3.org/TR/css3-conditional/">specification that adds conditional rules natively via <code>@supports</code></a>:</p>

<pre>@supports (font-feature-settings: ‘liga’) or
          (-webkit-font-feature-settings: 'liga') or
          (-moz-font-feature-settings: 'liga=1') {
  h1 {
    font-family: 'A Common Ligatured Font', serif;
  }
}</pre>


<p>Browsers that understand <code>@supports</code> would then check if any of the declarations (<code>font-feature-settings: 'liga'</code> or <code>-webkit-font-feature-settings: 'liga'</code>) is supported and if so, render the styles for the <code>h1</code> selector within the <code>@supports</code> rule. This way of writing CSS may be familiar to you via Media Queries.</p>

<p>This is a great way to do feature-detection natively and specify different rules when advanced features are supported while providing a basic but readable experience on other browsers. <a href="http://dev.opera.com/articles/view/native-css-feature-detection-via-the-supports-rule/">Chris Mills has written in greater depth about this rule on dev.opera.com</a></p>

<p><code>@supports</code> rule is available in Opera and Firefox (under a flag), and <a href="http://trac.webkit.org/changeset/131783">soon in WebKit</a>.</p>

<p><a href="http://nimbu.in/jscamp/supports.html">Demo of @supports rule</a> (<em>use Opera or Firefox 17+ with 'layout.css.supports-rule.enabled' set to true in <code>about:config</code></em>).</p>

<h2>Non-standard but interesting</h2>

<h3>Canvas as Background Image</h3>

<p>WebKit browsers have had, for more than 2 years, <a href="https://www.webkit.org/blog/176/css-canvas-drawing/">support for writing to a canvas that is used as a background image for elements</a>. This is specified as such:</p>

<pre>.banner {
  background-image: canvas(contextForCanvas);
}</pre>


<p>Instead of writing the pixels to the context of a Canvas element, you would write it to the context of that background image (<code>contextForCanvas</code>):</p>

<pre>
var context = document.getCSSCanvasContext(‘2d’, contextForCanvas, canvasWidth, canvasHeight);
</pre>


<p><a href="http://nimbu.in/jscamp/css-canvas.html">Demo of canvas as <code>background-image</code></a> (<em>please use Safari or Chrome to view this</em>)</p>

<h3>Elements as Background Image</h3>

<p>The use of canvas as a background image is somewhat similar to a <a href="https://hacks.mozilla.org/2010/08/mozelement/">Mozilla proposal to have elements as background images</a>:</p>

<pre>
.banner {
  background-image: element(#elementID);
}</pre>




<pre>
&lt;div class='banner'&gt;This is a banner&lt;/div&gt;
&lt;p id='elementID'&gt;This is the element that will be a background.&lt;/p&gt;
</pre>


<p><a href="http://twitter.com/simurai">Simurai</a> created <a href="http://jsfiddle.net/simurai/JKZTu/21/show/">this interesting kalaidescope effect using this property</a>.</p>

<p>Personally, I find the <code>element</code> function confusing and easy to make mistakes with (e.g. adding a twitter widget to a supposedly empty element suddenly has it appear as a background to another element). Hopefully, some middle-ground between canvas as a background image and elements as a background image will be arrived at.</p>

<h2>In Conclusion</h2>

<p>There are lots of new and interesting features out there and it would be <em>awesome</em> if you could take the time to play with them and <a href="http://lists.w3.org/Archives/Public/www-style/">provide feedback</a>. There are plenty of new features I did not cover because I thought I was out of time (I wasn’t!) like <a href="http://css-tricks.com/old-flexbox-and-new-flexbox/">Flexbox</a>, <a href="http://dev.w3.org/csswg/css3-grid-layout/">Grid Layout</a>, <a href="http://css3.bradshawenterprises.com/blog/css-variables/">Variables</a>, <a href="https://developer.mozilla.org/en-US/docs/CSS/calc">Calc()</a>, and more.</p>

<p>My talk was just several browsers each with pinned tabs of each demo. <a href="http://nimbu.in/jscamp/">Here is a list of all of the demos I showed</a>.</p>
]]></content>
  </entry>
  
</feed>
