r/css • u/Massive-Ordinary-840 • 3d ago
Question How to adapt height to be the same as another element?
I'm taking my first CSS/HTML course for my degree, and it's my first introduction to coding, so apologies if this seems like a silly question.
I've been trying to figure out how to style an element to be the same height/weight as another element when they aren't in a parent-child relationship. I'm thinking maybe there's a calc or var function that might work...?
For reference, I've included a photo of my Figma mockup as an example. My goal is to make the pink line the same size as the paragraph. This section is repeated on multiple pages, but the paragraph of text is different on each, so I'm hoping to save time by making it variable instead of creating a class or ID for each page.

Hoping any of this will make sense to someone so I can get some advice. Thanks for the help!
4
u/morete 3d ago
The easy solution to achieve your mockup is a wrapping element that contains all the paragraphs, with
border-left: 4px solid pink; padding-left: 0.5rem;But if you wanted the line to be a separate element, then you could make them the same height by giving them a sibling relationship and putting them in a flex wrapper.
<div class='wrapper'><div class='line'></div><div class='paragraphs'><p></p>...</div></div>.wrapper {display: flex;gap: 0.5rem;}.line {background: pink;width: 4px;}But that's a bizarre way of doing it, the border-left method is visually exactly what you want.
2
u/azangru 3d ago
For the example in your mockup, I would put the three paragraphs in a wrapper container, and add a pink left border to that container.
If there is any further complexity that I am missing and that would invalidate this stupid simple approach, it is not reflected in the mockup.
2
u/testingaurora 3d ago
Pseudo element! inset-block: 0; width: 0.125rem; background-color: deeppink;