Logarithmic Gutters / Dynamic Page Margins

I would like to share a code snippet for a site I'm currently developing which I thought was particularly cool.

The following code adjusts the page margins in a dynamic fashion and is nice on the liquid layout I'm designing. Basically it sets the page margins (or padding in this case) logarithmically (sort of) so in a really wide screen there's heaps of margin and on low res (1024 wide) there is very little. Percentages didn't cut it.

$(document).ready(function(){

  function logwidth() {
    var newwidth = Math.floor(Math.exp(3 * $(window).width() / 1000));
    if (newwidth < 150) {
      return newwidth;
    }
    else {
      return 150;
    }
  }

  // override defaults on doc ready
  $('#page').css('padding-left', logwidth() + 'px').css('padding-right', logwidth() + 'px');

  $(window).resize(function() {
    $('#page').css('padding-left', logwidth() + 'px').css('padding-right', logwidth() + 'px');
    // debug
    //$('body').prepend('<div>' + logwidth() + '</div>');
  });

});

Edit: I'm not sure how this would go on higher resolutions -- Mine maxes at 1680px wide.
Edit: Changed the function to check / set max allowable widths.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options