<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>amnuts &#187; Prototype</title>
	<atom:link href="http://blog.amnuts.com/tag/prototype/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.amnuts.com</link>
	<description>php projects, javascript, and... stuff.</description>
	<lastBuildDate>Fri, 07 May 2010 09:11:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Same height for elements</title>
		<link>http://blog.amnuts.com/2007/02/09/same-height-for-elements/</link>
		<comments>http://blog.amnuts.com/2007/02/09/same-height-for-elements/#comments</comments>
		<pubDate>Fri, 09 Feb 2007 23:52:22 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Prototype]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.amnuts.com/2007/02/09/same-height-for-elements/</guid>
		<description><![CDATA[Surely this is easy, right?  Just set the height property in your css.  Well, yes and no.  That&#8217;s all well and good if you know what height the elements are going to be, but quite often you might be pulling information out of a database in to the elements and you don&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>Surely this is easy, right?  Just set the <em>height</em> property in your css.  Well, yes and no.  That&#8217;s all well and good if you know what height the elements are going to be, but quite often you might be pulling information out of a database in to the elements and you don&#8217;t know how big that information is going to be.  You can&#8217;t use the <em>overflow</em> because that&#8217;s not the designer&#8217;s concept.  No; they want three boxes on screen that all have the same height so they&#8217;re all nice and ordered and symmetrical.</p>
<p><span id="more-29"></span><br />
What about using tables?</p>
<p>Wash your mouth out!  No, of course we don&#8217;t want to use tables.  Instead that old friend of ours, javascript, comes to the rescue.  Using that fabulous library <a href="http://www.prototypejs.org/">Prototype</a>, because I&#8217;m lazy, you could do something like this:</p>
<pre lang="javascript">
<script src="prototype.js" type="text/javascript"></script>
<script type="text/javascript"> 
function resizeElements() 
{ 
    var maxH = 0; 
    var nodes = document.getElementsByClassName('max-height'); 
    for (var i = 0; i < nodes.length; i++) { 
        var h = Element.getHeight(nodes[i]);
        maxH = (h > maxH) ? h : maxH; 
    } 
    for (var i = 0; i < nodes.length; i++) { 
        Element.setStyle(nodes[i], $H({height:maxH+'px',overflow:'hidden'})); 
    } 

    maxH = 0; 
    nodes = document.getElementsByClassName("min-height"); 
    for (var i = 0; i < nodes.length; i++) { 
        var h = Element.getHeight(nodes[i]); 
        maxH = ((h < maxH) || !maxH) ? h : maxH; 
    } 
    for (var i = 0; i < nodes.length; i++) { 
        Element.setStyle(nodes[i], $H({height:maxH+'px',overflow:'hidden'})); 
    } 
} 
Event.observe(window, 'load', resizeElements, false); 
</script>
</script></pre>
<h4>What does it do?</h4>
<p>The title of the post should be enough to give it away.  It makes the elements you decide all have the same height.  If you use the class <em>max-height</em> then the elements will all be the same height as the tallest one, and if you use <em>min-height</em> they will have the same height as the shortest one.</p>
<h4>How do you use it?</h4>
<p>Simply drop in one of the classes on all the divs you want to make the same height, for example:</p>
<pre lang="html">
<div id="d1" class="max-height">
  some text
</div>
<div id="d2" class="max-height">
  more 
  more 
  more 
  more 
  more 
  more 
  more 
  more 
  more 
</div>
<div id="d3" class="max-height">
  final bit of text 
  final bit of text 
  final bit of text 
</div>
<div id="d4">
  not resized...
</div>
</pre>
<h4>And everyone is happy&#8230;</h4>
<p>The designer is happy because you&#8217;ve retained the nice symmetrical boxes.  You&#8217;re happy because you&#8217;re using nice clean code that&#8217;ll degrade nicely.  I&#8217;m happy because you&#8217;ve read this. <img src='http://blog.amnuts.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.amnuts.com/2007/02/09/same-height-for-elements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
