When adding a new input field, the width of the fields block increases each time.
How can I fix it without specifying the width for the fields block?
setInterval(function() {
var input = '<input type="text">';
$("#fields").append(input);
}, 2000);
body {
background: grey;
display: flex;
align-items: center;
justify-content: center;
}
#fields {
background: green;
padding: 20px;
}
#fields input {
width: 100%;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="fields">
<input type="text">
</div>
3
Answers
Use
display: block
insteadwidth: 100%
:If you do not want to modify the
width
ofinput
you canflex
the#fields
container and specifyflex-direction: column;
.