There are a variety of approaches to achieve the desired outcome, each yielding different levels of success based on the chosen method:
Using display: inline-block;
on the inputs along with white-space: no-wrap;
to prevent text wrapping—as suggested by @Muhammad—does indeed accomplish the goal of keeping everything on a single line.
However, this solution has its restrictions as it relies on default browser sizes for elements and may result in oversized or misaligned containers on certain devices/resolutions/window sizes, therefore neglecting the user experience aspect.
The Flex-box CSS technique is another viable option, steadily gaining wider browser support and soon to be a preferred choice in the future. While it can be effectively implemented across multiple browsers with appropriate CSS fallbacks or Javascript shims (potentially provided by frameworks), for a foolproof and universally functional solution, consider using percentage widths alongside floats and responsive media queries:
See below for the CSS code and guidelines:
Explore the Fiddle link to experiment with the setup. (The container's color changes at breakpoints, so try resizing your window.)
/* Setting the box-model to ensure predictable width assignments */
* { box-sizing: border-box; }
#loginArea {
border-radius: 25px;
font-family: 'russo_oneregular';
font-size: 20px;
padding: 20px;
background-color: #000000;
color: #ffffff;
position: absolute;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-50%);
}
/* Default Styles (at full width)
Assign calculable sizes to form fields:
We have 3 fields (1 double-sized) and a button:
So, dividing container width (100%) by 5 = 20% per element;
Account for spacing (margin-right),
thus reduce each element by 1% and set margin-right to 1%;
additionally, adjust width for double-width entry separately (40% = 39% + 1%)
*/
#searchForm input {
float: left;
width: 19%;
margin: .25em 1% .25em 0;
}
#searchForm input#my_object {
width: 39%;
}
/* Employ Media Queries for enhanced form layouts
Switch to alternative field sizes for improved user experience
at various break-point sizes (indicated by background color changes) */
/* Mobile Styles */
@media only screen and (max-width : 480px) {
#loginArea {background-color:red;}
/*Full-width, no margin, stacked; */
#searchForm input {
width: 100%;
margin-right: 0;
}
#searchForm input#my_object {
width: 100%;
}
}
/* Phablet (In-between-sized mobile styles)
-- equivalent to mobile for consistency)
*/
@media only screen and (min-width : 481px) and (max-width : 767px) {
#loginArea {background-color:yellow;}
/* Full-width, no margin, stacked; */
#searchForm input {
width: 100%;
margin-right: 0;
}
#searchForm input#my_object {
width: 100%;
}
}
/* Tablet Styles */
@media only screen and (min-width : 768px) and (max-width : 1024px) {
#loginArea {background-color:green;}
/* Name side-by-side, Event stacked full-width below;
Implementing 1% padding on both left and right for balance
*/
#searchForm input {
width: 48%;
margin: .25em 1%;
}
#searchForm input#my_object {
width: 98%;
}
}