So I've created the desired answer for your problem, also here is the snippet:
document.addEventListener('DOMContentLoaded', () => {
const formSection = document.getElementById('overflow');
const textarea = formSection.querySelector('textarea');
const checkOverflow = () => {
const hasOverflow = formSection.scrollHeight > formSection.clientHeight;
formSection.classList.toggle('overflowing', hasOverflow);
};
textarea.addEventListener('input', checkOverflow);
checkOverflow(); // Initial check
});
div {
border: 1px solid #CCC;
background-color: #FFF;
margin-bottom: 1rem;
padding: 1rem;
width: 8.5in;
max-height: 7in;
}
.static-section {
display: grid;
overflow: hidden;
max-height: 3in;
width: 7.5in;
}
.static-section * {
margin-top: 0.5rem;
margin-bottom: 0.5rem;
padding: 0.5rem;
}
.static-section.overflowing {
background-color: #ffcccc !important; /* Red background for overflow */
}
textarea {
field-sizing: content;
width: 100%;
box-sizing: border-box;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Overflow Detection Example</title>
</head>
<body>
<form id="entry">
<section id="top">
<h1>HEADER</h1>
</section>
<section id="middle">
<div id="overflow" class="static-section">
<label>This section is locked at a max 3 inches. I want the background color to be red if anything makes this section overflow.</label>
<textarea placeholder="Type in this section until the following paragraph starts to go off the screen. This is when I want the background color to change."></textarea>
<p>When this information starts to go off the screen (i.e., enabling overflow - which the scrollbars are being hidden by the static-section class), I want the background color of this div to change. This will provide a visual indication that the provided response is too long.</p>
</div>
</section>
<section id="footer">
<h1>FOOTER</h1>
</section>
</form>
</body>
</html>
This will create the background red when the paragraph overflows.