cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <html>
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
    <script src="index.js"></script>
    <link rel="stylesheet" type="text/css" href="style.css">


    <script>
      var providedCases =[
        { height: 360, width: 1000 },
        { height: 600, width: 400 },
        { height: 400, width: 600 },
        { height: 400, width: 600 },
        { height: 400, width: 300 },
        { height: 400, width: 300 }
      ];

      var images = [
        { filename: "https://lh3.googleusercontent.com/4psFKP57q5i7UyIRmnXezOj6Gvyi1piET8OzcBU9o3ym-e3lp3iBySgTtcHn2QFH-dG7PiYU218un2Tz59tJNgz2fad6ZNB6Qne1GLuibhdI2uZfYCn4F8gb-9EjHEVQn2R3xWtEs555NAg25k1jG5V6mYVTv7r6CZIxL8qqhvxsFAYQyMrZ9JHN4MM_LtA_sErl-epkHh78BB6vGhfBjLxm6shO5Gv-Hoaje3RcNHB9ZCQPRYdwdB6lw5z7twZAJ1YJyWbXuNeZvaHqHk3yivH-kHSRBAlxvbd_K0aWAVb-GHQvWYtrINPX3YflVvPy9kG7rf73TmwG3WIBfsv1E6GcmKa_Hq5nNwQUKGIuhsKi0i8Hm8JHp01JEk0usDjuWWEtzFDVQh66p47I4sSH3xWeczmoxOHjUjZ7bBBATwW_EJNi1k-1dh6EEHLRNzzGvfTDN0hwaf3Y2M0JOP6fifLokIRu-gy6bhOLQHKNwdlibwBMq7OUwBPF9yVpOoq4nl0bS3gRdaD0HesQaWHMOvS7G35XNK7NEDhqI8PCjaunb0hfkgPHNssV9mBaHojQN5XMnTPeDcm88HYBPmppP6Ar3SNWO2vWRVoqFN_G5ch5cnvw=w3702-h930-no", caption: "Ljotipollur Lake, Iceland", width: 8443, height: 2116},
        { filename: "https://lh3.googleusercontent.com/mNjfnC5p5j4lFVIZcqSxKxGHcbTtY3Vf6fNF_JwcBQ1Oz1Amz35sO3y8QOOUws3UY0Pmi1bR1zecdeKWscfyOlyGUrQJJ-p6wT8DTwgDd5XDUkkb4CjaOpEsL2LlU5d9TXxd1elAUCEIkalphTUkMQrUc2fILmla7BqMB1EoXDeivW6BLgQ_myIdpjLSVuJjzuS3noZq2sJoUxjCwngcqXiURdaiDiNxp_op-BosJDq4Ucm2K0XEH4w6naB353kCkgePR1MSxoqnOxbBwcCVLPuzkrdj1r-XpfDKCJbL22DQ0kKH7jeR4en4NC9wF4IS0MSgnkF8krz0xldyn2vAZIsQ3qCu76jIBxWl7G-mPGfISlft6IvGCepEiiiMgqsvg71_MkBxozxpCYbm5bBoXOtnEGx_fo3KyitJ4jlmKMW3ByCxsFmt7QEn0I6bKNvhfT_miTSNnlQPgIdymht8hMBvfaZK13bXI5AjuxlLVOsyjCiYuhOVd4DvKLXxSWczkjBNDJ1L96srLu06D_0i6-QktHnuKBvNY7pTLwioUHxV45Ly1KrYahDZjdfmK7nAGely5LqiRXXjQe-jS6RHvR210Bs1Ye5XWw5x6iAXKMPbzd4a=w3298-h2198-no", caption: "Seljalandsfoss Waterfall, Iceland", width: 4104, height: 2736},
        { filename: "https://lh3.googleusercontent.com/Tk8xMogufAlYtst-Io0ZBvZacshdUGue03duTohlXt_wJSQfB5MQJJWuGMP1WGICf3h_tPD32d3lFMJ4jZM-hjI9-LjYDwmo_tQB5DWPX6PHWixY001Puqcz7bfZec-b6-t8I7_6gNcrsyJLTbrgoyqBKKtKIndmko1xfyv448uD0ZYc3dNl-iIQEyKn9j3_R4ccccLtgotahW6pp1xaYzJTJkANIPW4tgDegzkPsf2To3_jBwipz9vJQbldvJwGljSwY6OEbbIlFpl7_PxRNY6Env53GbK8BEZRJ4Q7N4Yc2tnOE0WyaxM4xf0CtSH3-jawp1DnBMFu8zTiqLChUxvmmXSs9glBLpMOuVDUSRxFeOmzyrJ_XWNmo5m0bdfRhFib6QN-DNIhMaO-Bmz_RiK8GDmdJJajighCT8m0n1pjC6iFSoc-7duZ0H8dokFR3be_w9PGsRZ8ZJuEx8ks1J367WY1SE1F6vcWHo0kcpWJj9Gpwdwu2yzN3VQ5fY1T0zHNwC2sD4nlQxvTboa5kRZq3gCKhHm11HGM1c30KKdepkAjwhGju6bpMQzRKa_yFIk_HdzM9v1YTVXJlZ2GJX4qJgvSGAVSfrvaDhOyApNdW7aY=w1466-h2198-no", caption: "Svartifoss, Iceland", width: 2736, height: 4104},
        { filename: "https://lh3.googleusercontent.com/vyxzp7lFlWlSqq8AoVY-lnA27UQzVpFbC7lGVbd-hE1WviDda8MIfILKlIKOF7ATnKdOqQESThQUzzFief00MgXgLJvWVtz8WpTvWceBDx4KlUeS3Vlr04chERixhFyO_kUIhdH4uwwcaMYOcIUvbh-7AHrUBQLIgDT9TQelfESJFEnNFEcWn7Uu3xlUorScFuhQ00vD6LvwKWEUPCIuMJ1Yu5oW64IbGjPemCmf7w8EF_6gsRqaTlLQ85ulNcore_IsVL_XlH6JzRPWWID8R8fXaIE8a--r02ydz5hBAQHJqWVaOVy588SXLJKjbQdCIf0CZmXEG0hW5EH0kccpiADqEF8-ymHdlDQ1WlcPSW4rjBNz2471XAe43xa_pY70e-OX1lKW2reSkrXZx7c2VxdNZuLgkP01ewJwZHglB6o8_9TSLt6QfuwDG1DeNBpInQsNgocMkKklfJbzEyJqL6Rc6zUYlUCkEYpUIHvvtL2RLK_0TfKndPP2I9jYcvuW4mTv4Y39Jcb_fwLP7Js3qFPp7sEzOXEGqaI-4fbHpHDUxCupcK27dK_8BN-PA74kE8tdi8YNJyInySNd7fcrcrl55QCGEQuSy9XLKcwOo1lRDm6r=w3298-h2198-no", caption: "Vik, Iceland", width: 4104, height: 2736},
        { filename: "https://lh3.googleusercontent.com/-gdeAOfQ71j3m54YL5qOrc5hNj2DnJPimoEiDz7_lIt2SbjWDeG5mLFyXwRDPsLdonpW_2leVN_5cjbpY9FpWO1GB8XwjUIY9_XotmvsAA4YBV23hfRWhTZ8pym7lQUORtegqIqqFT4MME1qv2GxPsJZey8g9kE-ZQe74jSG1btyzfAiX3ZlUJ6BpseaRLr-sm2iireJF73oZYJnZ2zvV4KMchzcUOMmvCheLGTKNqPLl1vBzZ6IWp2v1EK4jC6TLcabflw_BxXl0BgMikmyLvJtQSEIy_o-jtzsJNIQ0k2hDaqNbA_oQJr3mGcxOauQhmtneSd3fLLK23QXB4muC8PPYniVhs0M0mPFJAB101zewMriqVQm7tCCG2j4gWNiP2LF8NB8w610vV9w4rtJzcWUNffPp0CSiqAfHE2tSa5qOxN9frJ3U2lAg4GctHmd2dWoYw_b1J8SSxaTMWx5JL39jqiZNJr-nubBNgqoGA03r8BWILq2lVLgY05WwC5YzOb7sY1J0PRGTuiWKp4TYTG5SgblIAi7zQneMnqLPJpcGx3rzGCHPeHsOuGjhRj-hqI27nAP8ElcmiTR3KsvIEgvP4B-p3ulJE1aIhtIbwmhQRrr=w335-h223-no", caption: "Landmannalaugar, Iceland", width: 2667, height: 1778},
        { filename: "https://lh3.googleusercontent.com/xsfVIYYZe_XDh8ybvo8xnmm8cw518jBEav8TL9b6Acq8Scjrv4h_A1zutgeH3PPdxztzmT9VOKyWTrYfcZTDb_aMJPOtVb0Lt_gb5NAdyGWatsBd5N8AzVw7mclupCpdh13246Ho_g7NfTp5Ii4YP-rUmj5PoYLk2ejI17C6vPODZDTrZjjggSWtqkxvTDfl4OaigigtXSO4uQaHaKJIqFUumQlYP40irwZncVlX89stljjmCuCRv-UPFyUhFu4HmJlbxMAKZYm4vLIm80xb_0UZjszQe_XqZWNs0WEf-R7ctYyv-G_Wargq9H6_JwQWxwh55W9b9alXUciVyW8mJukb_zDzOQbAeFLXiPYTIrsU48AQQ52lPUn-16w9ChaAalOC2e-zjNd4hV87iInT2-7fnnyEhaWDlqGC6Ry_1e0nGjnQHG7_gM9pCZPWL9vyUWJvuSPJfHEhUB7T4dK4Fy9-GOaXD7YyPm5TFz5BC1YPrD7LgaWhuxLpuYffZ0Df5QAHozVD5pQmEc2gq4I3qxnqW2OgY4bk0Fjd6FPXASg6mBBlE7-Ov_9_O0oTbAWV9mjS7D7cxRMZ2JdgE-6R_Hg1FjL73WP1DbFfnFuA3Wm3FFD7=w3298-h2198-no", caption: "Landmannalaugar, Iceland", width: 2667, height: 1778},
        { filename: "https://lh3.googleusercontent.com/jF8TzmnnLnl1HMKb_uxg0H4dC1ox32zBsqsVw1OkRlXa8wVKdDbuukV3B8wwYCdLhWoP5joWPL5BmCDncmz27N7_sh3oYqPnwR0saadbpI8zsOEV8zPy4NRkpLvND-uS97SM8y7drgU1NcJKmGK66Z7_JkC7s4GgKbG2M5huymKu8VkDiI5wqmbKcRbcnfdlKXi2TuLQXC3N5KtvlEXmgwsoeOgfmm7kpNLwYxjJrmbknvG5FLANbDn25Nr0IU-QTVSU-ugb6vjaVazNn3yV_WzHtUkitZQSKM_B5YUvMM7_akkGyCiS2UwG_aPgHNq0bTuiduKU7cpq6SWPJeRRONocyUwWG3Sm69rvbAUBAgctqUOfnLEaC7oySRNDKtZ-DB3Bk_As-K_nCPT__vTdD3vuI1HPW_miOr419-ORdbVrKo0noMSq71Orh3XsAXCQHVw8QYlei94l1scZ6VXEFIHh71zY0VeMlGPiA3uhIZxeuQMkuy7X5QmfWHprxE_AnkNwL-1QPDKMUwwuhMEJr7GO30GcHvt5fWbmtQ3lFooTlFDpsy-wnFgrV8p6ydpDa3hqGGfMRVSpW1gHJ9YWkHrpwWjHNXsKRIyihmW7Ry4cojE0=w3298-h2198-no", caption: "Thingvellir, Iceland", width: 3835, height: 2557},
        { filename: "https://lh3.googleusercontent.com/KLcAh3S92RE8qIBvVia1LX-UwSgCzAoreq-NXDHngB3Nyx0lUS7cJwgrrbVVLeCfLQaF8fcLokFYxe6CTLga_4M6ztKVON60L64UkoTD6Nvpho--vMfg2MsGXON1l01HgKh2U-WkdhvBms37hY0cm7EHQxGSk2NTpN-BwpjnwcIJwr5wXCBoxpFBIB9RDfHETQxC2OmBimjyMcUNyQSY0IzfvZD_RcwfN3XjJWI4V6DEx7b361lgaAQ45-hJX04UgW-BEpu6wxJe3XfkoOu3_pMSfd4C-r7zA1gM_ine_Hb4ohIGJqPou4lonP2XN3rzqaMFnhcgT3-F2xCaqLRkm1smJkbBxSoLg4HnxgocaWj1ZLetEllxZb6pp1OXWZVMxlYc4IyAKhz9-hWlbiD3vv6xU02PvWnKU2q9UTV3AzTdNvEzVCxAMX33swJL4zlJq93ooJ_pkt7XlmAHUryL8uEqAVA3LjItEBml7r6skh_i1E0ulZgnoaW2kJSJpfTZE_lKkn99HER1OFQHnCJaJfjMwM0cXb_D3oeSyfm7WPiFywbKNp6jLDHRZav8ggOv1kheZs_UReWyoeMzaJ-OrxE-6kLW-pS8nxCGDStNa00oSM3l=w3298-h2198-no", caption: "Everglades National Park, Florida", width: 4104, height: 2736},
        { filename: "https://lh3.googleusercontent.com/5MH2VMF0bRwsCPqIUuOpGw2VjNolNfk8gb0NZv22RB3Y63akLETdiTtD5D7SslE6KbroWS70tTZJ2YM3CFcUplJcSgXonygFCf2l_yihgsNKBS_8xprCPq1268EooEpK17_bJbjWf3AQSzZqz5_XP3-BGjQrH5gka1N2kqJ8aMg9T7XaesZhl12WjiXVvpYN5aTQdh5SYzx4yqSia8AzR8IVng6AmMVhpE5mq3BRocbfKQ8ftP7r1Bp7mK0bYJM5TICoITypTy9rNlNSz8OwT9fkSAXhmBJ1XtJ6eqYwiRKrmuYyLbvINcRTn_r8jW5Air-nAUrX91Owli1zwUdb2wdtki5cbAVBFz_uVji1JOU88S1tU1mryIO1VAOiSaahQIG-prb6qCaVnQ6QhTcnPdl9-9Z123OWHGp0lOIsd7mqYwsWBuXqfFYlSxP6_vu5m97thPxoQMkwXc-WY13M8sORXhqna5dC4dVXE439oGyjmKLoZyD-qtZIeXiz7tmuka_7kaxIXPScVGQCVDezKPqlctah9Dr91Gyy1pmKu1IT0afalXsShvz4_3OjJ8p_sO8zdCx2YI2-uTqKO55x4P6fOYTsj_KsF7Ona7QkQLUjYNM3=w1440-h810-no", caption: "Sipan, Croatia", width: 1440, height: 810},
        { filename: "https://lh3.googleusercontent.com/JmHOrkVoazqZ-Ivcxs-o-c-vYD-VRD9NFy2rBJJVVdatxTb395HByWOPTQY81KnC0HKcrcGdCE2bcNdCnQU7qXfLHgWaFQlneeqSXIVrSbPehqBeP9TjRDnHIXnXOmvuoBR1VUWrQvj2lrdAw9Da00BtrV5UYAbUHHCzAPzTBFJgb5hf-hCWYUfOt8tJyHsPfNpxa0MATQpkzRB7C0nyMLEytV5p88ErAIJJqOOQk5agTNQOKpKijLA7jo6QXxuBZCGEXQePHO6aPZHk6VGSYe1EtAyGTXDF1GQ7aRWJ6vBsZstH7X5GvWtZudXR4DKKrRLtOnc1Yc4mCJrTHv9WjbxV7xtgUy1NWn9LilU4ZjHW0GTtj9ZERcGPfiIaQUd9cwMEBlCgqGXva82ndq9kUSeRE_VfUZGqSyHb4prxs1RsHHk0Ga2sANpIFXEdssgKk232K5MtqQmMcoYbsfu3wSPXNpCEOdkd4lSkQpsVPj9lzKxe_LsvgC4oz93LLgIGM2P6Ex_InPb7AoIcZAIhhtSbnVSag6UBXKThGQ3_BeitcoXdsh6qUxnNl8-mSGq63HOE5hd06p_n_GbWbGj5wJkWJ2Q08bUsqKQhnvPU9i8VlyrA=w339-h194-no", caption: "Dubrovnik, Croatia", width: 5533, height: 3168},
        { filename: "https://lh3.googleusercontent.com/lJNkwk3IJX21Klh1QjSIpr977u-wUVzCNVgSvw6dguH2xL61hZrh3711cYkZiPzgAUZiuXyDyqFQoXuB7AalfAWTpfD4HXH8WV1U5DAO3Tns1Zc8xhyD-0cbh4D5iBD9ueusZO0eNeVit3s6nInqPcNaxhFFZEDaXxGVl1MS-4hUL-6VGYN1Iv4WkYX-RSK7ly8EbkBD2ZcOsm8j9wIrKdhP83ObcmLz7wyUBmhnZBO5JKEAyyjHI5_ZWucqAZWhON5a4kug5bZgEfO2D-8A5T31YI1pqlXsORgFqCIOF7JIEvMQVjK9m4712R9cohtwvgCWL8xu5f-l7aRWyQdFL5r4pTmzafkBxJ8cQtvZm_uMpZlQgCQZt-SWITCfIrIouiIDrFi0LOJ2W8NoHQjp7M5D70mp4GWa_2lqBVkuFhCpn2lOOSvRJent51Ui8YLKcZn0QxIlzcRLwGZQMWpu7M1_0a-_MDu3u83-N1d2bGnXGfeE7bjEs8Ux6i4CHmAAR2s-FLkNz25A6lU0CPcIBcCDfvrw4HUFQMqzDXrsErtWM6KKB7pEvntqmubFkCJ8gBJUAArUtHxazfWGbxV0H3x596EIsC0r3a7YCI5c5twjcUic=w1650-h2198-no", caption: "Artipelag, Sweden", width: 3000, height: 4000},
        { filename: "https://lh3.googleusercontent.com/5G_1NmrZe09rMAlN0h2BY_JDHd-MOlQULvHSDOH7pKFrEt8VwUIFl_scnAgIDElb3IM9l9TV_zumWee0AxJF0aQgeJdhrEZwRQPold22CTE0JyPFcnYbH3pnryDRVGZ4y8AvCJnhBSMAAJK8Z3o6TVm9J-_pH-wG4PYffZM7nPXBG8rWoTDUlzlcv0Jd3G94CfaopmjpKUX5z-T5akosu18t5eWQTb0dA4ceN68ep7kNOnD9-8dWFsSnYhe4BxnFASR92NDpG_ABt1S39OIXIRDEJzKRqRQ3ioomMNpYTTG0efD7R_nPnRq0QbQUwLVyV0zeBTJCnozIku_ZSvTMYhuSGtc1T56vhNHrdoIu-qSw4wrvLmKshiOG3fDt_edxZ3pCCtt8ndh9Rh03uJrEmmynz3Ew_rRsHSNxaPubfiLPJO05zBmDfDG3CLOxNSb40BLFWm2jwGKsiHS4YlCqzjm6lLteK3IaPRI_xAxTOnLzBYdmPCKQmY6H4ryXvHjMC-TlCiPvjEmynijOxvZVkg5ZqmJaxEnauoDDyOnH1IZlRM2Jnna5LgNmv-P4UEUGK5JARzGVZ6EC_t4j0Xed3IzZfUdEtZSjU1vWoLBO2XR4Y72A=w1650-h2198-no", caption: "Century Ave, China", width: 2448, height: 3264},
        { filename: "https://lh3.googleusercontent.com/P--W77-HlkctxyZ2IjFOsyef2GFjjDtPXWIkgUkvbYvDvWvezHu3vst1VEJzGPmcx0mclnx4XOPgsS89EhH0PA_B1NX0K_WhQLAW9pN0kxypiMczzTXbi-MOWppCLNLk5YsI7KLwwOxYdOQ1rvj8M6cj6Nz6s6axAJWAvlW8j6BEfLMGu3GDXzOiIimtmPgJjYRNCT1V5PPT9XD-h-Vf0SXelZlj2sjq5_tbeNPxmrSBYPz0QQ6fbhaERHrOhnDK4Lf4WZLRh45WgJ-rm8x6BfrlA94ndDmfhrehHfU0jyh-5uAsRRNO5ijRaJ9g5TdwHo4TxGXsXXEA48UO-LtIW89H8G9eABiIA_6rOqoPFl8p3UVO7Bhc8dKLLFEMnLAO-4HnM6P31gKpuGE-E7n0P-zwge0lgfIrhVXABG0jBCmmWATcqKoD9H01MB6OnfL44AaS0DHKJTvCXY3QD0RT8xNG81Fa3keG2jjC14NvpnAnWiH2k7YHce4bw01cBn0Z-rZrc1sauhW4BUQL2fldQDTOsvu37-taBoCZzJLZZ2176_fQnbvlP_lML3aaS0EV8oBHkSXp0P0V3_-ZaBLcvXszy-4p71ZwRlJl12uohn0ok-Gs=w2932-h2198-no", caption: "Huangshan, China", width: 4000, height: 3000},
        { filename: "https://lh3.googleusercontent.com/z_Dd9tCnv7vukc8GfzngCg6CuW6dCxcTRyMehoclSalYuTgU9GYocNNod3Gufg7qPS6yiIhSme2rJ6qW32oTS2-n05kdoyCP1hBgTpsXDYRkSajXL2PB0JSWgYqDX5mIrMgRYoMwg-utYUQV3vX7STT-zF5g2RG6AxgRfpwygXpB72TckdtH_0jN8iTxPL-36Q9rE3nOs_C6n6cFKQLJ5w3VmF5edxz2j5D7bAIYtSE_ae0VcfAgPQM5Y1Bnndd0g4au3rI1OepddxZ6LEJcPsj20oDRp91eAR0Pu5KNOu-D7V3J3l-JPRfv_XJgnCv7C0UtAW9X6HGlv425CmE6x5k6kTSYYMl-79LrmepHW3BMCW5DpStj0Y8Q5764_o9BCLaJo0ywXbD4LVpA3zXPvRjn6BJFz6zj3UF5gnP5PvdRPdZh8M7_MrO2ZShlMkbOdYk6pXZM9_QTMTWtk9GC4qat-PyHCjaWHTWacwKYQCHMXcCLGJ5yNyt4B1uJlBY-uYqevS6qJGjSg2JZlRZflynJaswGHdMVSAD4rtpOXW8XmmhzpPofZ08mZe8ly1c86jurxR4yQT_svlmWwblqit7nEhxU2sj-E63NagLo09gPgvmt=w2932-h2198-no", caption: "Huangshan, China", width: 4000, height: 3000}
      ];
      

      $(document).ready(function(){
        var width = $(window).width();
      	$('.grid').css({width: width});
        makeDianPictureGrid(images, width, 400, 10);
        /*Uncomment this block if you want the placekitten version
           with supplied frame values

          makePlacekittenGrid(providedCases, 800, 360, 10);

        */

      });
    </script>
  </head>
  <body>
    <div class='grid'>
    </div>
  </body>
</html>

            
          
!
            
              body {
  margin: 0;
  padding: 0;
}
.grid-item {
  display: inline-block;
  margin: 0;
  position: relative;
  outline: 1px solid #dedede;
}
.image {
  background-color: gray;
}

.grid-item + .grid-item {
  margin-left: 10px;
}

.grid {
  margin: auto;
}

.row {
  font-size: 0;
  margin-bottom: 10px;
}

figcaption {

  box-sizing: border-box;
  padding: 20px 10px;
  width: 100%;
  display: inline-block;
  position: absolute;
  bottom: 0;
  left: 0;
  color: white;
  background-color: rgba(96, 125, 139, 0.74);
  font-family: system, -apple-system, "San Francisco", "Roboto", "Segoe UI", "Helvetica Neue", "Lucida Grande", sans-serif;
  font-size: 12px;
}
            
          
!
            
              /**
* @param {Array<Object>} array of frame objects with height/width properties
* @param {number} width of the containing element, in pixels
* @param {number} maximum height of each row of images, in pixels
* @param {number} spacing between images in a row, in pixels
* @returns {Array<Array<Object>>} array of rows of resized frames
*/
function layoutFrames(images, containerWidth, maxRowHeight, spacing) {

  var currentRowHeight;
  var currentRowWidth = 0;
  var grid = [];
  var row = [];
  var resizedFrames;

  //resize all images to be within width, height constraints
  resizedFrames = _.map(images, fit.bind(this, containerWidth, maxRowHeight));

  _.each(resizedFrames, function(frame){

    if (row.length === 0) {
      currentRowHeight = frame.height; //record first image's height
    }
    else {
      frame = scaleHeight(frame, currentRowHeight);
    }

    currentRowWidth += frame.width;
    row.push(frame);

    if (currentRowWidth < containerWidth) {
      currentRowWidth += spacing; //account for spacing
    }
    else {

      var frameGutterWidthTotal = (row.length - 1) * spacing; //account for spacing

      // row is full or overflowing, squeeze down to container width
      row  = _.map(row, function(frame){
        var ratio = (containerWidth - frameGutterWidthTotal)/
                    (currentRowWidth - frameGutterWidthTotal);
        return scaleWidth(frame, frame.width * ratio);
    });

    grid.push(row);

    //clear for next row
    row = [];
    currentRowWidth = 0;
  }
});

//push the last row if it contains contents
if (row.length) {
  grid.push(row);
}

return grid;
}

/* helper functions */

//returns scaled frame based on a target height
function scaleHeight(frame, targetHeight) {

  var width = targetHeight/frame.height * frame.width;
  return ({height: targetHeight, width: width});
}

//returns scaled frame based on a target width
function scaleWidth(frame, targetWidth) {
  var height = targetWidth/frame.width * frame.height;
  return ({height: height, width: targetWidth});
}

function fit(maxWidth, maxHeight, frame) {
  if (frame.width > maxWidth && frame.height > maxHeight) {
    frame = scaleHeight(frame, maxHeight);
    if (frame.width > maxWidth) {
      frame = scaleWidth(frame, maxWidth);
    }
  }
  else if (frame.width > maxWidth) {
    frame = scaleWidth(frame, maxWidth);
  }
  else if (frame.height > maxHeight) {
    frame = scaleHeight(frame, maxHeight);
  }
  return frame;
}

var gridItem = [
  '<figure class="grid-item">',
    '<img class = "image" src = <%= filename %> width= <%= width %> height= <%= height %> >',
    '<figcaption width= <%= width %>><%= caption %> </figcaption>',
  '</figure>'
].join('\n');

function makeDianPictureGrid(images, containerWidth, maxHeight, spacing){
  var grid = layoutFrames(images, containerWidth, maxHeight, spacing);
  var index = 0;

  var template = _.template(gridItem);

  _.each(grid, function(row){
    var $row = $('<div>').addClass('row');
    $('.grid').append($row);

    _.each(row, function(image) {
      var $gridItem = $(template(_.extend(image,{
        filename: images[index].filename,
        caption: images[index].caption
        })
      ));
      $row.append($gridItem);
      index++;
    });
  });
}

function makePlacekittenGrid(images, containerWidth, maxHeight, spacing){
  var grid = layoutFrames(images, containerWidth, maxHeight, spacing );

  var template = _.template(gridItem);

  _.each(grid, function(row){
    var $row = $('<div>').addClass('row');
    $('.grid').append($row);

    _.each(row, function(image) {
      var filename = ['http://placekitten.com', Math.round(image.width), Math.round(image.height)].join('/');
      var $gridItem = $(template({
        width: Math.round(image.width),
        height: Math.round(image.height),
        filename:  filename,
        caption: "A kitten"
      }));
      $row.append($gridItem);
    });
  });
}


            
          
!
999px
Loading ..................

Console