Skip to content
Drempd Logo
  • home
  • portfolio
  • web design journal
  • blog
    • adventure
    • san diego
    • projects
    • website design
    • code notes
  • contact
Blog Web Dev Responsive Tiles

Responsive Tiles

By Forrest Smith - Drempd.com

For a couple of projects, I wanted to create tiles that automatically resized themselves based on the screen size, or space available within the page. If there is enough room, I wanted the system to automatically insert another tile to the row.

The javascript/jquery:

//Resizes tiles to completely fill the width of a container div (.tile-container).  

var tileMinWidth = new Array();

function resizeTiles() {

    $('.tile-container').each(function (i, obj) {

        if (!tileMinWidth[i]) {
            tileMinWidth[i] = $(obj).find('.tile').width();
        }

        var containerWidth = $(obj).width();
        var rowElements     = Math.floor(containerWidth / tileMinWidth[i]);
        var tileWidth       = 100 / rowElements;

        $(obj).find('.tile').css({ 'width': tileWidth + '%' });

        //If it's the end of the row, clear it:
        $(obj).find(\".tile:nth-child(" + (rowElements + 1) + ")").css("clear", "left");

    });

}

$(window).resize(resizeTiles);
$(document).ready(resizeTiles);

2/23/14 – Updated this so there can be different groupings of tiles on the same page, with different minimum widths per tile, and different widths that they are allowed to spill into. I also set it to \’clear\’ the divs if it’s the beginning of a new row, to get rid of weird div floating issues if the tiles aren\’t of all the same height.

Posted on January 31, 2014August 26, 2022 in Web Dev

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

I love to create and explore. Whether building a website or app, taking a long walk through the mountains, or playing with a random idea, I've found that there will never be enough time to experience it all. But that won't stop me from trying.

Follow me on Bluesky
Contact

Web Design & Development

  • Portfolio
  • San Diego Website Design
  • Custom Web Design
  • Responsive Web Design
  • Website Maintenance
  • Freelance Web Designer
  • Web Design Posts
  • Website Checklist

Projects

  • Zindash
  • Opti
  • Saphire CSS
  • Ergo Blocks

Blog

  • Adventure
  • San Diego
  • Website Design
  • Projects
  • Arch + Urban
  • Technology
  • Code Notes

Galleries

  • Arch + Urbanity
  • Life
drempd | san diego, ca
© 2026 Drempd All rights reserved.