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

 <title>Dave Dash</title>
 <link href="http://davedash.com/tag/ems/atom.xml" rel="self"/>
 <link href="http://davedash.com/tag/ems"/>
 <updated>2012-04-07T22:42:44-07:00</updated>
 <id>http://davedash.com/</id>
 <author>
   <name>Dave Dash</name>
   <email>dd+atom1@davedash.com</email>
 </author>

 
 <entry>
   <title>Textmate Snippets for YUI em calculations</title>
   <link href="http://davedash.com/2007/05/08/textmate-snippets-for-yui-em-calculations/"/>
   <updated>2007-05-08T00:00:00-07:00</updated>
   <id>http://davedash.com/2007/05/08/textmate-snippets-for-yui-em-calculations</id>
   <content type="html">&lt;p&gt;[tags]yui, yahoo, css, snippet, textmate, ems, px[/tags]&lt;/p&gt;

&lt;p&gt;If you use &lt;a href=&quot;http://developer.yahoo.com/yui/grids/&quot;&gt;YUI grid layouts&lt;/a&gt; you'll notice that &lt;code&gt;ems&lt;/code&gt; are the preferred units and for good reason.  But ems don't make sense to people like us who want to be super precise down to the pixel... pixels make sense.&lt;/p&gt;

&lt;p&gt;So type in a number select it and run this &lt;code&gt;ruby&lt;/code&gt; script as a TextMate command (that outputs as a snippet):&lt;/p&gt;

&lt;div&gt;&lt;textarea name=&quot;code&quot; class=&quot;ruby&quot; cols=&quot;100&quot; rows=&quot;15&quot;&gt;
#!/usr/bin/env ruby
#
# This script will do the necessary YUI calculations from px to ems
#
# The result is inserted as a snippet, so it's
# possible to tab through the place holders.

# validate input
input    = ENV['TM_SELECTED_TEXT'].to_i;
width    = input.to_f/13
ie_width = width * 0.9759

print &quot;${1:width}:&quot;+width.to_s+&quot;em;*$1:&quot;+ie_width.to_s+&quot;em;$0&quot;
&lt;/textarea&gt;&lt;/div&gt;


&lt;p&gt;You'll have the proper tab stops to change the newly calculated &lt;code&gt;ems&lt;/code&gt; from &lt;code&gt;width&lt;/code&gt; to &lt;code&gt;margin-left&lt;/code&gt; or &lt;code&gt;margin-right&lt;/code&gt; or whatever it is you desire.&lt;/p&gt;
</content>
 </entry>
 

</feed>

