I have two inputs in a div, and set tabindex=1
to make it focusable.
<div class="wrapper" tabindex="1">
<input class="input" type="text">
<input class="input" type="text">
</div>
And my SCSS:
div {
border: solid 1px lightgray;
padding:3px;
display: inline-block;
background-color: #fff;
&:focus {
outline: none;
border: solid 1px blue;
}
}
input {
border: solid 1px transparent;
&:focus {
outline: none;
border-bottom: solid 1px red;
}
}
This way, div will not focus when inputs were focus.
So, I use jQuery to make this.
(function($) {
$(".input").on("focus", function() {
$(this).parent("div").addClass("focus");
});
$(".input").on("focusout", function() {
$(this).parent("div").removeClass("focus");
});
})(jQuery);
I wonder if there is a better way to make this?
Here is my JSFiddle.