Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why don't <textarea> and <input> elements respect max-width?

Tags:

html

css

The following HTML:

<!DOCTYPE html>
<style>
span,textarea,div {
    border: 1px solid black;
    max-width: 300px;
    height: 20px;
}
</style>
<div></div><br>
<textarea></textarea><br>
<input type=text><br>

Renders the following in Chrome and FF.

enter image description here

Why isn't the <textarea> and the <input> as wide as the <div>?

like image 400
HorseloverFat Avatar asked Nov 24 '13 13:11

HorseloverFat


Video Answer


1 Answers

Most browsers respect max-width, but INPUT and TEXTAREA elements typically have a width set by default in the user agent CSS. You can add this CSS for a consistent rendering:

input,textarea{width:100%;display:block}
like image 71
David Hellsing Avatar answered Sep 29 '22 19:09

David Hellsing