Consider the following HTML + CSS code:
<section style='max-width: 300px; padding: 10px; background-color: beige'>
<form style='background-color: blue'>
<input type='text' style='width:100%'>
<textarea style='width: 100%'></textarea>
<button type='submit' style='float: right'>send</button>
</form>
<hr>
</section>
Since the submit <button>
is overflowing its parent <form>
element, I would expect that overflow: hidden
should (at best) clip the button and turn the rest invisible:
<section style='max-width: 300px; padding: 10px; background-color: beige'>
<form style='background-color: blue; overflow: hidden'>
<input type='text' style='width:100%'>
<textarea style='width: 100%'></textarea>
<button type='submit' style='float: right'>send</button>
</form>
<hr>
</section>
However, this is not the case. Instead of clipping the overflowing content, the parent element <form>
was increased in order to contain all its content, including the overflowing <button>
.
Over the web there are some hints about the reason for that. Example: "The overflow property only works for block elements with a specified height.", w3schools. Even so I'm still unsure of the reason why this happened.
Question
Why this happened?