I need to style a text input like this
The requiremets are:
- fluid width (stretches to container width)
- border color changes on focus
- border color changes on error
Is there some simple way to do it with css?
What I've come up now is quite complex, requires js and it works not too smoothly -
<div class="inpt"><input type="text" /></div>
jQuery(".inpt").delegate("*", "focus blur", function() {
var elem = jQuery(this);
var elem2 = jQuery(this).parent();
setTimeout(function() {
elem2.toggleClass("focused", elem.is(":focus"));
}, 0);
});
I had to wrap an input in a div and style that div using images on :before and :after
Obviously :active doesn't work for div in this case and thus I had to toggle some class with a script.
I feel like there must be some simple solution that I'm missing. Can someone suggest anything better?