Jump to content

Make image description equal height

Recommended Posts

 

Demo video

 

Paste this code to Settings -> advanced -> Code injection -> header

<!-- jQuery 3 -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>

<script>
document.head.insertAdjacentHTML("beforeend", `<style>
/* CSS BELOW ⬇️⬇️⬇️⬇️⬇️ */

.image-caption strong {
    display: inline-block;
}


/* CSS ABOVE ⬆️⬆️⬆️⬆️⬆️ */
</style>`);


$( document ).ready(function() {
    /**
 * Equal Heights Plugin
 * Equalize the heights of elements. Great for columns or any elements
 * that need to be the same size (floats, etc).
 *
 * Version 1.0
 * Updated 12/10/2008
 *
 * Copyright (c) 2008 Rob Glazebrook (cssnewbie.com)
 *
 * Usage: $(object).equalHeights([minHeight], [maxHeight]);
 *
 * Example 1: $(".cols").equalHeights(); Sets all columns to the same height.
 * Example 2: $(".cols").equalHeights(400); Sets all cols to at least 400px tall.
 * Example 3: $(".cols").equalHeights(100,300); Cols are at least 100 but no more
 * than 300 pixels tall. Elements with too much content will gain a scrollbar.
 *
 */
 
(function($) {
    function equalHeights (minHeight, maxHeight) {
        tallest = (minHeight) ? minHeight : 0;
        this
        .height('auto')
        .each(function() {
            if($(this).height() > tallest) {
                tallest = $(this).height();
            }
        });
        if((maxHeight) && tallest > maxHeight) tallest = maxHeight;
        return this.each(function() {
            $(this).height(tallest).css("overflow","auto");
        });
    }

    $.fn.equalHeights = function(minHeight, maxHeight) {

        var $this = this;

        $(window).resize(function(){
            equalHeights.call($this, minHeight, maxHeight);
        });

        equalHeights.call($this, minHeight, maxHeight);
        return this;
    };
})(jQuery);


 $(".image-caption strong").equalHeights();
    
}); </script>

 

Feel free to get in touch if you need to hire a pro 🙂

Edited by codeandtonic

Freelance Squarespace developer making plugins like Full-Width Blocks, Hover effects for grid gallery and the Darkmode plugin. I know Squarespace inside out and I'm able to solve pretty much any Squarespace code problem.

Get in touch here!

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.