Saturday, July 4, 2009

How To Make Your Columns Of Equal Height

From this tutorial, you will be able to make all of your columns in your template of equal height. Having all columns with the same height can make your template look much more organized and in place to your readers. As we all know, bloggers default templates doesn't supply this option, but you will be able to modify it with one simple script. As always, make sure you download your current existing template just in case it doesn’t turn out as expected.

You will need this file for this tutorial
1. sameheight.js

Steps to follow:
1. Login to your Blogger dashboard

2. Go to Layout > Edit HTML (do not click on “expand widgets” box)

3. Search for the section code: ]]></b:skin>

4. Add the following section code right after it:

<script src='http://www.blogspotvision.com/bspotvision/scripts/sameheight.js' type='text/javascript'/>

<script type='text/javascript'>
function adjustLayout()
{
// Get natural heights
var cHeight = xHeight(&quot;main-wrapper&quot;);
var lHeight = xHeight(&quot;sidebar2&quot;);
// Find the maximum height
var maxHeight =
Math.max(cHeight, Math.max(lHeight));
// Assign maximum height to all columns
xHeight(&quot;main-wrapper&quot;, maxHeight);
xHeight(&quot;sidebar2&quot;, maxHeight);
// Show the footer
xShow(&quot;footer&quot;);
}
window.onload = function()
{
xAddEventListener(window, &quot;resize&quot;,
adjustLayout, false);
adjustLayout();
}
</script>

5. You will need to replace the link in red, with the link you uploaded the script to.

6. With the script right under it, all blues represent the main-wrapper(where your posts are located), all the orange represents your second column, which is, in most cases, your sidebar. You will need to replace the bolded and crossed out code above with yours. Main-wrappers are AKA main or main-content. Sidebar2 are AKA sidebar, right-column, or left-column.

Note: If you have more than two columns in your template, you will need to add another variable, which will represent another column. For example:

<script type='text/javascript'>
function adjustLayout()
{
// Get natural heights
var cHeight = xHeight(&quot;main-wrapper&quot;);
var lHeight = xHeight(&quot;sidebar2&quot;);
var gHeight = xHeight(&quot;anothersidebar&quot;);
// Find the maximum height
var maxHeight =
Math.max(cHeight, Math.max(lHeight, gHeight));
// Assign maximum height to all columns
xHeight(&quot;main-wrapper&quot;, maxHeight);
xHeight(&quot;sidebar2&quot;, maxHeight);
xHeight(&quot;anothersidebar&quot;, maxHeight);
// Show the footer
xShow(&quot;footer&quot;);
}
window.onload = function()
{
xAddEventListener(window, &quot;resize&quot;,
adjustLayout, false);
adjustLayout();
}
</script>

Note: Everything in red needs to be added for a third column and remember to change the crossed out “anothersidebar” to your other column’s id.

3 comments:

  1. How do I upload the script to a different link?
    It says I should replace www.blogspotvision.com/bspotvision/scripts/sameheight.js', but I don't know how. Is this necessary. It works perfect right now. Thanks for the code, and any answer is appreciated!

    ReplyDelete
  2. Hey Natalie, to upload the script to a different link, you will have to have your own hosting service, ie. godaddy. Although it is working perfect right now, I would have to say it is necessary to get your own host, because if too many people uses that same link, the hosting server will, in time, crash, leaving all of us(or whoever has the given link) with a broken link and uneven columns. I really don't mind if you use my link, but instead of the link given above, please use this link instead, just to prevent crashes:

    www.blogspotvision.info/sameheight.js

    Thanks, and I'm glad that the post was a help to you.

    ReplyDelete
  3. Can you do this by making the code inline instead of having to upload it. Is that possible and if so how.

    Thanks

    ReplyDelete