Yes you can do something similar in the CSS, Do you have a sample code you can post online somewhere? so we can give advice on your actual code?
But to achieve this, each input field needs to have a css style of
display: inline-block;
so if it fits in the provided width, it will remain in the same line, but if the text box is too large, it will goto next line.
Looking at your example, it seems you have some kind div container with "overflow: hidden". In this senario, you either remove the overflow: hidden OR you can wrap the input text boxes with another div and set the width there.
EDIT
Here's the example