Search code examples
csshtmltile

CSS: Give a div a height that is a multiple of a number?


A div has a tilable background. The height of this div will depend on its content. I need the div to stretch by a multiple of the background image's size.

For instance, the background is a 64x64 image. So, if the div's height is to increase, I want to do so by steps of 64px.

Is this possible with CSS? I've not found leads using google. Thanks for your time!


Solution

  • To my knowledge this cannot be done in CSS, but you could probably solve it with some javascript. If you have access to jQuery:

    $(function() {
        $div = $('#the_div_id');
        var remainder = $div.height() % 64;
        var newHeight = $div.height() + (64-remainder);
        $div.css('height', newHeight);
    });