JSFiddle - React, Tailwind, and code Playground

by Marian Rick

HTML

<div id="container">
    <div id="image"></div>
    <div id="sub_container">
        <div class="sub_text">
            <b>Resize this window. On Load both divs will align perfectly, after resize they get lost.</b> Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
        </div>
    </div>
</div>

CSS

#container {
    position: absolute;
    bottom: 0;
    top: 0;
    left: 0;
    right: 0;
    background: lightgrey;
    font-family: sans-serif;
}
#sub_container {
    position: absolute;
    bottom: 0;
    left: 20px;
    right: 20px;
}
.sub_text {
    margin-top: 1em;
    margin-bottom: 1em;
}
#image {
    position: absolute;
    left: 0; 
    right: 0;
    top: 0;
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center;
    background-image: url(https://unsplash.it/800/1000/?image=601);
}

JavaScript

var maxHeight = 0; // Initialize height to zero
var $text_boxes = $('#sub_container'); 
$text_boxes.each(function() { 
   maxHeight = parseFloat($(this).outerHeight()) > maxHeight ? parseFloat($(this).outerHeight()) : maxHeight;
});

// Append to Head
$('head').append('<style type="text/css">#image {bottom:'+maxHeight+'px;}</style>');

// As soon as #sub_container changes its height the alignment does not work anymore. Because of that I want to recalculate:

// Check if the user has finished resizing
var id;
$(window).resize(function() {
    clearTimeout(id);
    id = setTimeout(doneResizing, 500);
});
function doneResizing(){
  // Now I want to replace the <style> tag with the new calculated value   
}