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.

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

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.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay