<?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/layout/atom.xml" rel="self"/>
 <link href="http://davedash.com/tag/layout"/>
 <updated>2012-01-17T21:54:19-08:00</updated>
 <id>http://davedash.com/</id>
 <author>
   <name>Dave Dash</name>
   <email>dd+atom1@davedash.com</email>
 </author>

 
 <entry>
   <title>Table based layouts?  In this day in age?  Really?  How about grids?</title>
   <link href="http://davedash.com/2007/10/05/table-based-layouts-in-this-day-in-age-really-how-about-grids/"/>
   <updated>2007-10-05T00:00:00-07:00</updated>
   <id>http://davedash.com/2007/10/05/table-based-layouts-in-this-day-in-age-really-how-about-grids</id>
   <content type="html">&lt;p&gt;[tags]css, yui, grids, table, layout[/tags]&lt;/p&gt;

&lt;p&gt;I think there are three kinds of people:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;People who learned tables for layouts and went to CSS+&lt;code&gt;div&lt;/code&gt;s.&lt;/li&gt;
&lt;li&gt;People who learned tables for layouts and never needed to learn CSS+&lt;code&gt;div&lt;/code&gt;s (or insisted that this was way too complicated)&lt;/li&gt;
&lt;li&gt;People who never learned tables.&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;I would argue in some ways the second class of people are right, tables are a lot easier.  Until you run into issues... and until you need to maintain your template code.&lt;/p&gt;

&lt;p&gt;Luckily there's grids.  Grids are easier than tables and easy to maintain and look at.  You can achieve just about anything with &lt;a href=&quot;http://developer.yahoo.com/yui/grids/&quot;&gt;grids&lt;/a&gt;.&lt;/p&gt;

&lt;!--next page--&gt;


&lt;!--more--&gt;


&lt;p&gt;Personally I like using &lt;a href=&quot;http://developer.yahoo.com/yui/&quot;&gt;Yahoo's YUI&lt;/a&gt; to get grid support.  It's a CSS framework in the same way that &lt;a href=&quot;http://jquery.com&quot;&gt;jQuery&lt;/a&gt; is a javascript framework or that &lt;a href=&quot;http://symfony-project.com/&quot;&gt;symfony&lt;/a&gt; is a PHP5 framework.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://developer.yahoo.com/yui/&quot;&gt;YUI&lt;/a&gt; will normalize all your elements and give you a standard way to change the size of text and elements and give you &lt;a href=&quot;http://developer.yahoo.com/yui/grids/&quot;&gt;grids&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So it helps to think of your layout in terms of grids... or columns.  &lt;a href=&quot;http://developer.yahoo.com/yui/grids/&quot;&gt;YUI grids&lt;/a&gt; supports some common combinations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;.yui-g&lt;/code&gt; - 2 equal size containers (nest to get 4).&lt;/li&gt;
&lt;li&gt;&lt;code&gt;.yui-gb&lt;/code&gt; - 3 equal size containers&lt;/li&gt;
&lt;li&gt;&lt;code&gt;.yui-gc&lt;/code&gt; - 2/3 - 1/3&lt;/li&gt;
&lt;li&gt;&lt;code&gt;.yui-gd&lt;/code&gt; - 1/3 - 2/3&lt;/li&gt;
&lt;li&gt;&lt;code&gt;.yui-ge&lt;/code&gt; - 3/4 - 1/4&lt;/li&gt;
&lt;li&gt;&lt;code&gt;.yui-gf&lt;/code&gt; - 1/4 - 3/4&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Granted, this doesn't cover every scenario, but it's a start, and it's easy to build off of to create your own special sizes.&lt;/p&gt;

&lt;p&gt;So to create some magical columns you do the following:&lt;/p&gt;

&lt;div&gt;&lt;textarea name=&quot;code&quot; class=&quot;html&quot;&gt;
&lt;div class=&quot;yui-g&quot;&gt;
  &lt;div class=&quot;yui-u first&quot;&gt;&lt;/div&gt;
  &lt;div class=&quot;yui-u&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/textarea&gt;&lt;/div&gt;


&lt;p&gt;&lt;code&gt;yui-g&lt;/code&gt; can be substituted for any of the above classes.  &lt;code&gt;yui-u&lt;/code&gt; is your columns or grid cells.  &lt;code&gt;first&lt;/code&gt; indicates the first column since &lt;code&gt;:first&lt;/code&gt; isn't understood by some popular browsers.&lt;/p&gt;

&lt;p&gt;Now you know grids.  It's less complicated than the tabular equivalent:&lt;/p&gt;

&lt;div&gt;&lt;textarea name=&quot;code&quot; class=&quot;html&quot;&gt;
&lt;table class=&quot;layout&quot;&gt;
  &lt;tr class=&quot;first_row&quot;&gt;
    &lt;td class=&quot;col1&quot;&gt;&lt;/td&gt;
    &lt;td class=&quot;col2&quot;&gt;&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;
&lt;/textarea&gt;&lt;/div&gt;


&lt;p&gt;With the framework in place, it's a lot easier to quickly adjust your layouts, and the readability is huge especially as your layouts grow.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Equal height columns with jQuery</title>
   <link href="http://davedash.com/2007/05/22/equal-height-columns-with-jquery/"/>
   <updated>2007-05-22T00:00:00-07:00</updated>
   <id>http://davedash.com/2007/05/22/equal-height-columns-with-jquery</id>
   <content type="html">&lt;p&gt;[tags]css, jQuery, layout, javascript, equal, columns, equal columns[/tags]&lt;/p&gt;

&lt;p&gt;I've seen a few examples of how to equalize column heights using javascript, and none of them seem appealing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://www.tomdeater.com/jquery/equalize_columns/&quot;&gt;jquery.equalizecols.js&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;This required a few other libraries, and I wanted more flexibility (e.g. where the column should grow in order to equalize)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.projectseven.com/tutorials/css/pvii_columns/index.htm&quot;&gt;Project 7&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;The Project 7 approach was the most interesting, but the code seemed a bit messy and not so open source friendly (even thought it might have been).  It would let you specify which element was to grow inside a column.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.html.it/articoli/nifty/index.html&quot;&gt;Nifty Corners&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;I had trouble with the syntax, but I liked how it just created a new element out of thin air...&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;So I wrote my own:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$(&quot;#col1, #col2&quot;).equalizeCols();
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;will equalize the columns as expected&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$(&quot;#col1, #col2&quot;).equalizeCols(&quot;p,p&quot;);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;will equalize the columns and add the extra space after the &lt;code&gt;p&lt;/code&gt; tag in &lt;code&gt;#col1&lt;/code&gt; or &lt;code&gt;#col2&lt;/code&gt; (whichever is shorter).&lt;/p&gt;

&lt;p&gt;Here's our function:&lt;/p&gt;

&lt;div&gt;&lt;textarea name=&quot;code&quot; class=&quot;js&quot;&gt;

(function($) {
  $.fn.equalizeCols = function(children){
    var child = Array(0);
    if (children) child = children.split(&quot;,&quot;);
    var maxH = 0;
    this.each(
      function(i) 
      {
        if (this.offsetHeight&gt;maxH) maxH = this.offsetHeight;
      }
    ).css(&quot;height&quot;, &quot;auto&quot;).each(
      function(i)
      {
        var gap = maxH-this.offsetHeight;
        if (gap &gt; 0)
        {
          t = document.createElement('div');
          $(t).attr(&quot;class&quot;,&quot;fill&quot;).css(&quot;height&quot;,gap+&quot;px&quot;);
          if (child.length &gt; i)
          {
            $(this).find(child[i]).children(':last-child').after(t);
          } 
          else 
          {
            $(this).children(':last-child').after(t);
          }
        }
      }  
    );
    
  }
})(jQuery);

&lt;/textarea&gt;&lt;/div&gt;


&lt;p&gt;This requires jQuery of course, and it hasn't been tested much.&lt;/p&gt;
</content>
 </entry>
 

</feed>

