DEV Community

Paul Castañeda
Paul Castañeda

Posted on • Edited on

Equal heights

I was working on a landing page website project. There's something I need to evaluate regarding the design of their Figma.

Since the boxes have their different parent and that parent is only displayed as "flex". The only thing that comes to my mind is manipulating them using a script or jQuery. jQuery because that is one library they use from their previous projects and as a developer I need to adapt their environments.

I tried this script.


  function cBoxItemHeight() {
    function getMaxHeight(className) {
      let max = 0;
      document.querySelectorAll(className).forEach(function (el) {

        if (el.scrollHeight > max) {
          max = el.scrollHeight;
        }
      });
      return max;
    }
    function setHeight(className, height) {
      document.querySelectorAll(className).forEach(function (el) {
        el.style.height = height + "px";
      });
    }
    let max = getMaxHeight(".s4__text-coating");
    setHeight(".s4__text-coating", max);
  }
  $(window).resize(function () {
    cBoxItemHeight();
  });
  cBoxItemHeight();

Enter fullscreen mode Exit fullscreen mode

It will save you in the meantime. Hard code it later when you need to think about Vanilla JS. It also helps to follow the design in Figma when resizing the browser.

If you have any ideas. Code your power below.

Top comments (1)

Collapse
 
thedevcristian profile image
Paul Castañeda

UPDATE:

When manipulating the script above the details you have a "fixed" height for the CSS children boxes. Assure you have to change every @media(ratio:ratio){ selector:value here } responsive.
So the children box with the maximum height will be the main height of the other children boxes.