The idea is to improve the usage of larger formulars. Done by adding a little animation to the input-elments.
When one of the textboxes is clicked or focussed via tab appears a colored border. Signalling the user which exact box has become active.
(function() {
var inputs = document.querySelectorAll('input[type=text]');
var userTriggered = true; // Avoiding recursion.
inputs = Array.prototype.slice.call(inputs);
inputs[0].focus();
inputs.forEach(function(item) {
item.addEventListener('focus', function() {
if (userTriggered) {
item.parentNode.focus(); // Trigger animation.
setTimeout(function() {
item.parentNode.blur(); // Remove the focus from the container.
item.focus(); // Put the focus on the actual input-element.
userTriggered = false;
}, 600);
} else {
userTriggered = true;
}
});
});
})();
body {
background: linear-gradient(90deg, #9c9c9c, #cfcfcf);
}
input[type=text] {
font-family: georgia;
}
.wrap {
margin: 25px auto;
width: 850px;
}
.inputs-wrap {
display: flex;
justify-content: space-between;
}
fieldset {
margin-bottom: 15px;
}
legend {
font-size: 1.2rem;
font-weight: 800;
font-family: arial, sans-serif;
margin-bottom: 10px;
border-radius: 6px;
letter-spacing: 1px;
}
.textbox, button {
width: 180px;
margin-right: getPercentage(20, 850px);
}
button:focus {
opacity: 0.7;
}
.textbox:last-of-type {
margin-right: 0;
}
.button-wrap {
display: inline-block;
position: relative;
}
.button-wrap:after, .button-wrap:before {
content: "";
display: inline-block;
width: 0;
height: 0;
transition: all 0.6s;
position: absolute;
}
.button-wrap:focus:after {
width: 40%;
height: 60%;
border-left: 3px solid magenta;
border-bottom: 3px solid magenta;
bottom: 0;
left: -3px;
}
.button-wrap:focus:before {
width: 40%;
height: 60%;
border-right: 3px solid magenta;
border-bottom: 3px solid magenta;
bottom: 0;
right: -3px;
}
<div class="wrap">
<fieldset>
<legend>Your personal data</legend>
<div class="inputs-wrap">
<div class="button-wrap" tabindex="1">
<input type="text" class="hover-border textbox" placeholder="Please enter your first name" />
</div>
<div class="button-wrap" tabindex="2">
<input type="text" class="hover-border textbox" placeholder="Please enter your last name" />
</div>
<div class="button-wrap" tabindex="3">
<input type="text" class="hover-border textbox" placeholder="Please enter your birthday" />
</div>
<div class="button-wrap" tabindex="4">
<input type="text" class="hover-border textbox" placeholder="Please enter your home town" />
</div>
</div>
</fieldset>
<fieldset>
<legend>Some numbers</legend>
<div class="inputs-wrap">
<div class="button-wrap" tabindex="5">
<input type="text" class="hover-border textbox" placeholder="Please enter one" />
</div>
<div class="button-wrap" tabindex="6">
<input type="text" class="hover-border textbox" placeholder="Please enter two" />
</div>
<div class="button-wrap" tabindex="7">
<input type="text" class="hover-border textbox" placeholder="Please enter three" />
</div>
<div class="button-wrap" tabindex="8">
<input type="text" class="hover-border textbox" placeholder="Please enter your four" />
</div>
</div>
</fieldset>
<fieldset>
<legend>Some alphabet</legend>
<div class="inputs-wrap">
<div class="button-wrap" tabindex="9">
<input type="text" class="hover-border textbox" placeholder="Please enter A" />
</div>
<div class="button-wrap" tabindex="10">
<input type="text" class="hover-border textbox" placeholder="Please enter B" />
</div>
<div class="button-wrap" tabindex="11">
<input type="text" class="hover-border textbox" placeholder="Please enter C" />
</div>
<div class="button-wrap" tabindex="12">
<button>Send data</button>
</div>
</div>
</fieldset>
</div>
Here is the uncompiled Sass-code:
$primary-color: whitesmoke;
$wrap-width: 850px;
$marker-color: darken(magenta, 0);
$marker-duration: 0.6s;
$font-stack: arial, sans-serif;
$radius: 6px;
@mixin focusSettings($side) {
width: 40%;
height: 60%;
border-#{$side}: 3px solid $marker-color;
border-bottom: 3px solid $marker-color;
bottom: 0;
#{$side}: -3px;
}
@function getPercent($value, $context) {
@return percentage($value / $context);
}
body {
background:
linear-gradient( 90deg,
darken($primary-color, 35%),
darken($primary-color, 15%)
);
}
input[type=text] {
font-family: georgia;
}
.wrap {
margin: 25px auto;
width: $wrap-width;
}
.inputs-wrap {
display: flex;
justify-content: space-between;
}
fieldset {
margin-bottom: 15px;
}
legend {
font-size: 1.2rem;
font-weight: 800;
font-family: $font-stack;
margin-bottom: 10px;
border-radius: $radius;
letter-spacing: 1px;
}
.textbox, button {
width: 180px;
margin-right: getPercentage(20, $wrap-width);
}
button:focus {
opacity: 0.7;
}
.textbox:last-of-type {
margin-right: 0;
}
.button-wrap {
display: inline-block;
position: relative;
}
// Input[text] can't have an after- / before-
// Pseudo-Element. Therefore an container
// is needed.
.button-wrap:after, .button-wrap:before {
content: "";
display: inline-block;
width: 0;
height: 0;
transition: all $marker-duration;
position: absolute;
}
.button-wrap:focus:after {
@include focusSettings(left);
}
.button-wrap:focus:before {
@include focusSettings(right);
}
Any hints and tipps concerning possible improvements highly welcomed. Especially the design and usability.