Is it feasible to adjust the position of an absolutely positioned element based on the height of the element above it? The objective is to align elements with the class
"pgafu-post-categories"
one line above an H2 heading, even when the lengths vary.
.pgafu-post-categories {
position: absolute;
top: -82px;
width: fit-content;
white-space: nowrap;
padding: 4px 16px;
font-size: 14px;
}
<div class="row">
<div class="column">
<div class="image-wrapper"></div>
<h2>Small title</h2>
<div class="pgafu-post-categories">category</div>
</div>
<div class="column">
<div class="image-wrapper"></div>
<h2>Long two <br> lines title</h2>
<div class="pgafu-post-categories">category</div>
</div>
<div>
The simplest solution would involve moving the
<div class="pgafu-post-categories">
above the <h2>
in the HTML code, but editing the HTML code is not an option. Is there a CSS-based approach to achieve this?
Edit: Perhaps it's also viable to use jQuery or JavaScript to calculate the height of the H2 element and then adjust the position of the absolutely positioned element accordingly?