I was wondering if it is possible to apply styles to an empty textarea only. As a minimal example, I'd like a comments box that expands when the user clicks on it (:focus
), but stays expanded when the user entered text, but re-collapse when the box is empty.
I have already tried :empty
, but that doesn't work for inputs/textareas (only DOM elements).
#comments {
width: 150px;
height: 30px;
font-family: sans-serif;
border-radius: 5px;
outline:none;
-webkit-transition: all 1s;
-moz-transition: all 1s;
transition: all 1s;
}
#comments:not(:empty),
#comments:focus {
width: 250px;
height:100px;
border-radius: 10px;
}
<textarea type="text" id="comments" placeholder="Place a comment"></textarea>
Is there any way to make the input stay big when the user entered something in it?