If you want a JS solution, see here:
You cannot bind "resize" to elements, instead use ResizeObserver
Also note that you should use some inline-type element/styling.
div
elements are display: block
by default, hence I've added display: inline-block;
to show this point.
In the snippet, I made #footerA
editable (like an input) so that you can change the div
's content.
const footerA = document.getElementById("footerA");
const footerB = document.getElementById("footerB");
const resizeObserverCallback = () => {
footerB.style.width = `${footerA.getBoundingClientRect().width}px`;
}
if (footerA && footerB) {
new ResizeObserver(resizeObserverCallback).observe(footerA)
}
.footer {
background-color: orange;
display: inline-block;
}
<div id="footerA" class="footer" contenteditable="true">aaaa</div>
<div id="footerB" class="footer">bb</div>
This question could be a duplicate of this question