When I begin writing text in the textarea, I want the outer div, with a class box, to have its border turned solid instead of dashed, but somehow the :focus doesn’t apply in this case. If it works with :active, how come it doesn’t work with :focus?
Any ideas why?
(Note. I want the DIV’s border to turn solid, NOT the textareas)
div.box
{
width: 300px;
height: 300px;
border: thin dashed black;
}
div.box:focus{
border: thin solid black;
}
<div class="box">
<textarea rows="10" cols="25"></textarea>
</div>
While this can’t be achieved with CSS/HTML alone, it can be achieved with JavaScript (without need of a library):
JS Fiddle demo.
Incidentally, with a library, such as jQuery, the above could be condensed down to:
JS Fiddle demo.
References:
getElementsByTagName().onfocus.onblur.parentNode.tagName.toString().toLowerCase().style.focus().blur().parent().css().