Skip to content

Instantly share code, notes, and snippets.

@david-cako
Last active March 22, 2017 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save david-cako/8102cafc635754e5efa40c1e34d32727 to your computer and use it in GitHub Desktop.
Save david-cako/8102cafc635754e5efa40c1e34d32727 to your computer and use it in GitHub Desktop.
bootstrap 4 expanding text fields (flexbox) | demo here: https://jsfiddle.net/dum1rkxq/
#text-field {
flex: 1 1 0;
}
#neighbouring-div {
margin-left: 10px;
}
<div class="container-fluid">
<div class="row" style="width: 400px">
<input id="text-field" type="text" class="form-control">
<div id="neighbouring-div">
<button type="button" class="btn btn-primary">
submit
</button>
<button type="button" class="btn btn-danger">
cancel
</button>
</div>
</div>
</div>
$('#text-field').focus(function() {
var filenameInput = $(this);
var newWidth = $(this).css("width");
$("#neighbouring-div").fadeOut(100, function() {
filenameInput.css("flex", "0 1 " + newWidth);
filenameInput.animate({
"flex-grow": "1"
}, 250);
});
}).blur(function() {
$(this).animate({
"flex-grow": '0'
}, 250, function() {
$(this).css("flex", "1 1 0");
$("#neighbouring-div").fadeIn(200);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment