Bootstrap forms - Cannot make the label and input inline - html

I am working on a personal project, and I need to make some changes to my current form but I cannot get it working so far.
I need the label and input to be inline. Here is a screenshot how the form should look like.
And here is my current code:
.personal_details {
max-width: 503px;
float: none;
margin: 0 auto;
padding: 40px;
border-radius: 5px;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="personal_details">
<form class="personal_details">
<div class="form-group">
<label for="firstName">First name</label>
<input type="text" class="form-control" id="inputFirstName" />
</div>
<div class="form-group">
<label for="lastName">Last name</label>
<input type="text" class="form-control" id="inputLastName" />
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="text" class="form-control" id="inputEmail" />
</div>
<div class="form-group">
<label for="phone_nummber">Account type</label>
<select class="form-control" name="profile_type">
<option value="Basic" selected>Freelancer</option>
<option value="Company">Employer</option>
</select>
</div>
<button class="btn btn-primary mt-4 px-5" type="submit">EDIT</button>
</form> <!-- Form ends here -->
</div>

Related

Inline Checkbox and Input Element in Bootstrap

I'm trying to inline input and checkbox using Bootstrap
My code is:
<!-- Bootstrap-3.4.1 -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
<!-- Body -->
<form class="form " style=" width:250px; height:250px;">
<div class="form-group">
<input class="form-control " id="mawbNoCheck" type="checkbox" style="height: 34px;width:20px;">
<label style="width:100%;"> <input class="form-control" maxlength="50" id="txtMawb" placeholder="MAWB No" type="text" disabled /></label>
</div>
<div class="form-group">
<input class="form-control" id="collectionDatecheck" type="checkbox" style="height: 34px;width:20px;">
<label style="width:100%;"><input class="form-control date-picker" id="txtCollectionDate" maxlength="50" placeholder="Toplama Tarihi" type="text" disabled /></label>
</div>
<div class="form-group">
<input class="form-control " id="manifestDateCheck" type="checkbox" style="height: 34px;width:20px;">
<label style="width:100%;"><input class="form-control date-picker" id="txtManifestDate" maxlength="50" placeholder="Manifesto Tarihi" type="text" disabled /></label>
</div>
<div class="form-group ">
<a class="btn btn-success">Güncelle</a>
</div>
</form>
But it looks like this:
Just set display:inline-flex !important;
<style>
form div.form-group{
display:inline-flex !important;
}
</style>
.form-group {
position: relative;
}
label {
position: absolute;
top: 0;
left: 35px;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
<form class="form " style=" width:250px; height:250px;">
<div class="form-group">
<input class="form-control " id="mawbNoCheck" type="checkbox" style="height: 34px;width:20px;">
<label style="width:100%;"> <input class="form-control" maxlength="50" id="txtMawb" placeholder="MAWB No" type="text" disabled /></label>
</div>
<div class="form-group">
<input class="form-control" id="collectionDatecheck" type="checkbox" style="height: 34px;width:20px;">
<label style="width:100%;"><input class="form-control date-picker" id="txtCollectionDate" maxlength="50" placeholder="Toplama Tarihi" type="text" disabled /></label>
</div>
<div class="form-group">

Fieldset with aligned items using bootstrap not aligned properly

I'm working on a wire frame and trying to create the HTML based on it. This is the structure I'll be require to build:
This is what I have done so far but the alignment is not correctly rendered. I have used the two column grid approach and then used the form-inline classes, however the label and text boxes are not getting aligned in one row.:
<style>
.body {
padding: 1px 1px 1px 1px;
}
.column {
float: left;
width: 50%;
}
.customLegend {
border: 1px solid #000;
padding: 2em 0 1em;
margin-top: 2em;
position: relative;
}
.customLegend legend {
border: 0;
background: #fff;
width: auto;
transform: translateY(-50%);
position: absolute;
top: 0;
left: 1em;
padding: 0 .5em;
}
</style>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="container body">
<fieldset class="customLegend">
<legend>Sources</legend>
<div class="row">
<!-- Left Section -->
<div class="column">
<div class="form-inline">
<div class="form-inline">
<label>Initial Reporter </label>
<input type="text" class="form-control" />
</div>
<div class="form-inline">
<label class="lbl">First Name </label>
<input type="text" class="form-control" />
</div>
<div class="form-inline">
<label class="lbl">Phone Number </label>
<input type="text" class="form-control" />
</div>
<div class="form-inline">
<label class="lbl">Title </label>
<input type="text" class="form-control" />
</div>
<div class="form-inline">
<label class="lbl">Address </label>
<textarea class="form-control"> </textarea>
</div>
<div class="form-group">
<label class="lbl">Qualification </label>
<select class="form-control">
<option value="0"> </option>
<option value="1">One</option>
<option value="2">Two</option>
</select>
</div>
<div class="form-group">
<label class="lbl">Primary Source </label>
<input type="checkbox" class="form-control" />
</div>
<div class="form-group">
<label class="lbl">P I Usage </label>
<select class="form-control">
<option value="0"> </option>
<option value="1">One</option>
<option value="2">Two</option>
</select>
</div>
</div>
</div>
<!-- Right Section -->
<div class="column">
<div class="form-inline">
<div class="form-group">
<label class="lbl">Ok to Contact? </label>
<select class="form-control">
<option value="0"> </option>
<option value="1">Yes</option>
<option value="2">No</option>
</select>
</div>
<div class="form-group">
<span class="form-inline">
<label>Last Name </label>
<input type="text" class="form-control" />
</span>
</div>
<div class="form-group">
<span class="form-inline">
<label>Email </label>
<input type="text" class="form-control" />
</span>
</div>
<div class="form-group">
<span class="form-inline">
<label>Company </label>
<input type="text" class="form-control" />
</span>
</div>
<div class="form-group">
<span class="form-inline">
<label>Country </label>
<input type="text" class="form-control" />
</span>
</div>
<div class="form-group">
<span class="form-inline">
<label>Zip/Postal </label>
<input type="text" class="form-control" />
</span>
</div>
<div class="form-group">
<span class="form-inline">
<label>City </label>
<input type="text" class="form-control" />
</span>
</div>
<div class="form-group">
<span class="form-inline">
<label>State/Region </label>
<input type="text" class="form-control" />
</span>
</div>
<div class="form-group">
<span class="form-inline">
<label>Phone Number 2 </label>
<input type="text" class="form-control" />
</span>
</div>
<div class="form-group">
<span class="form-inline">
<label>FAX </label>
<input type="text" class="form-control" />
</span>
</div>
</div>
</div>
</div>
</fieldset>
<button class="btn btn-primary">Create New Source</button>
</div>
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
Check the Jsfiddle here
You need to replace the column by col-6 and the hierarchy of the bootstrap divs should change to following
<div class="container">
<div class="row">
<!-- Left Section -->
<div class="col-6">
</div>
<div class="col-6">
</div>
</div>
</div>

Text field in same line HTML

How to make multiple text fields in the same line.
This is my code:
<div class="col-lg-2">
<div class="form-group">
<label>Working experience</label>
<input type="text" class="form-control " placeholder="Year"/>Year
<input type="text" class="form-control " placeholder="Month"/>Month
<input type="text" class="form-control " placeholder="Day" />Day
</div>
</div>
It's by default. input is inline element.
<div class="col-lg-2">
<div class="form-group">
<label>Working experience</label>
<input type="text" class="form-control " placeholder="Year" />Year
<input type="text" class="form-control " placeholder="Month" />Month
<input type="text" class="form-control " placeholder="Day"
Day
</div>
</div>
In bootstrap you can put all of the fields that you want on a single line within a single form-group
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="form-group">
<label for="birthday" class="col-xs-3 col-sm-2 control-label">Birthday</label>
<div class="col-xs-3">
<input type="text" class="form-control" placeholder="year"/>
</div>
<div class="col-xs-3">
<input type="text" class="form-control" placeholder="month"/>
</div>
<div class="col-xs-3">
<input type="text" class="form-control" placeholder="day"/>
</div>
</div>
It seems, you are using Bootstrap, if yes, then;
Add class .form-inline to the <form> element.
else, Add these css properties to <form>,
display: inline-block;
width: auto;
You can try this way too.
<!DOCTYPE html>
<html>
<head>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
</head>
<body>
<div class="col-lg-2">
<div class="form-group" >
<label style="width:25%; float:left;">Working experience</label>
<div style="width:25%; float:left;">
<input type="text" class="form-control " placeholder="Year"/>Year
</div>
<div style="width:25%; float:left;">
<input type="text" class="form-control " placeholder="Month"/>Month
</div>
<div style="width:25%; float:left;">
<input type="text" class="form-control " placeholder="Day"/>Day
</div>
</div>
</div>
</body>
</html>
Use Bootstrap:
<form class="form-inline" action="/action_page.php">
<label>Working experience : </label>
<div class="form-group">
<input type="text" class="form-control" id="year" placeholder="Year" name="year">
</div>
<div class="form-group">
<input type="text" class="form-control" id="month" placeholder="Month" name="month">
</div>
<div class="form-group">
<input type="text" class="form-control" id="day" placeholder="Day" name="day">
</div>
</form>
You could use inline form class.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<form class="form-inline">
<div class="form-group">
<label>Working experience</label>
<input type="text" class="form-control" placeholder="Year">
<input type="text" class="form-control" placeholder="Month">
<input type="text" class="form-control " placeholder="Day">
</div>
</form>
Use Expand snippet to see actual result.

Bootstrap 3: Div does not work as before

I have section divs inside my form. And Each section can have multiple fields. It works fine with Bootstrap 2.3 css. When I replaced it with Bootstrap 3.0 css, all the fields came out of the section div. I tried inspecting the element but could not find any difference.
CSS
.section {
position: relative;
margin: 15px 0;
padding: 39px 19px 14px;
background-color: #fff;
border: 1px solid #649300;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
}
HTML
<div class="section" name="amount">
<span class="section-title">Amount Information</span>
<div class="span6 form-inline">
<label class="pocLabel">
Amount Of</label>
<input type="text" name="amount" required="">
</div>
<div class="span6 form-inline">
<label class="pocLabel">
Customer First Name</label>
<input type="text" name="firstName" required="">
</div>
<div class="span6 form-inline">
<label class="pocLabel">
Customer Last Name</label>
<input type="text" name="lastName" required="">
</div>
<div class="span6 form-inline">
<label class="pocLabel">
Middle intials</label>
<input type="text" name="middleIntials" required="">
</div>
<div class="span6 form-inline">
<label class="pocLabel">
Date</label>
<input type="text" id="datepicker" class="datepicker" name="date">
</div>
<div class="span6 form-inline">
<label class="pocLabel">
Street Address</label>
<input type="text" name="address">
</div>
<div class="span6 form-inline">
<label class="pocLabel">
City</label>
<input type="text" name="city">
</div>
<div class="span6 form-inline">
<label class="pocLabel">
State</label>
<input type="text" name="state">
</div>
<div class="span6 form-inline">
<label class="pocLabel">
State 2</label>
<input type="text" name="state">
</div>
</div>
Bootstrap 3 has obsoleted the spanX classes. Replace those with col-lg-X classes.
See this migration guide from v2.x to v3 of Bootstrap.
Try closing your input tags, leaving them open may cause problems.
Example:
<input type="text" name="state"></input>
Or:
<input type="text" name="state" />

Form inline inside a form horizontal in twitter bootstrap?

What's the best way to design a form that looks like this (please see link below) in twitter bootstrap without any homemade classes ?
Is it possible to set a inner form-inline inside a form-horizontal like the below example:
Don't nest <form> tags, that will not work. Just use Bootstrap classes.
Bootstrap 3
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="inputType" class="col-md-2 control-label">Type</label>
<div class="col-md-3">
<input type="text" class="form-control" id="inputType" placeholder="Type">
</div>
</div>
<div class="form-group">
<span class="col-md-2 control-label">Metadata</span>
<div class="col-md-6">
<div class="form-group row">
<label for="inputKey" class="col-md-1 control-label">Key</label>
<div class="col-md-2">
<input type="text" class="form-control" id="inputKey" placeholder="Key">
</div>
<label for="inputValue" class="col-md-1 control-label">Value</label>
<div class="col-md-2">
<input type="text" class="form-control" id="inputValue" placeholder="Value">
</div>
</div>
</div>
</div>
</form>
You can achieve that behaviour in many ways, that's just an example. Test it on this bootply
Bootstrap 2
<form class="form-horizontal">
<div class="control-group">
<label class="control-label" for="inputType">Type</label>
<div class="controls">
<input type="text" id="inputType" placeholder="Type">
</div>
</div>
<div class="control-group">
<span class="control-label">Metadata</span>
<div class="controls form-inline">
<label for="inputKey">Key</label>
<input type="text" class="input-small" placeholder="Key" id="inputKey">
<label for="inputValue">Value</label>
<input type="password" class="input-small" placeholder="Value" id="inputValue">
</div>
</div>
</form>
Note that I'm using .form-inline to get the propper styling inside a .controls.
You can test it on this jsfiddle
For bootstrap 3 example above works but is overcomplicated, rather than using form-group use form-inline for the fields you want inline.
Eg:
<div class="form-group">
<label>CVV</label>
<input type="text" size="4" class="form-control" />
</div>
<div class="form-inline">
<label>Expiration (MM/YYYY)</label><br>
<input type="text" size="2" class="form-control" /> / <input type="text" size="4" class="form-control" />
</div>
This uses twitter bootstrap 3.x with one css class to get labels to sit on top of the inputs. Here's a fiddle link, make sure to expand results panel wide enough to see effect.
HTML:
<div class="row myform">
<div class="col-md-12">
<form name="myform" role="form" novalidate>
<div class="form-group">
<label class="control-label" for="fullName">Address Line</label>
<input required type="text" name="addr" id="addr" class="form-control" placeholder="Address"/>
</div>
<div class="form-inline">
<div class="form-group">
<label>State</label>
<input required type="text" name="state" id="state" class="form-control" placeholder="State"/>
</div>
<div class="form-group">
<label>ZIP</label>
<input required type="text" name="zip" id="zip" class="form-control" placeholder="Zip"/>
</div>
</div>
<div class="form-group">
<label class="control-label" for="country">Country</label>
<input required type="text" name="country" id="country" class="form-control" placeholder="country"/>
</div>
</form>
</div>
</div>
CSS:
.myform input.form-control {
display: block; /* allows labels to sit on input when inline */
margin-bottom: 15px; /* gives padding to bottom of inline inputs */
}
Since bootstrap 4 use div class="form-row" in combination with div class="form-group col-X". X is the width you need. You will get nice inline columns. See fiddle.
<form class="form-horizontal" name="FORMNAME" method="post" action="ACTION" enctype="multipart/form-data">
<div class="form-group">
<label class="control-label col-sm-2" for="naam">Naam: *</label>
<div class="col-sm-10">
<input type="text" require class="form-control" id="naam" name="Naam" placeholder="Uw naam" value="{--NAAM--}" >
<div id="naamx" class="form-error form-hidden">Wat is uw naam?</div>
</div>
</div>
<div class="form-row">
<div class="form-group col-5">
<label class="control-label col-sm-4" for="telefoon">Telefoon: *</label>
<div class="col-sm-12">
<input type="tel" require class="form-control" id="telefoon" name="Telefoon" placeholder="Telefoon nummer" value="{--TELEFOON--}" >
<div id="telefoonx" class="form-error form-hidden">Wat is uw telefoonnummer?</div>
</div>
</div>
<div class="form-group col-5">
<label class="control-label col-sm-4" for="email">E-mail: </label>
<div class="col-sm-12">
<input type="email" require class="form-control" id="email" name="E-mail" placeholder="E-mail adres" value="{--E-MAIL--}" >
<div id="emailx" class="form-error form-hidden">Wat is uw e-mail adres?</div>
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="titel">Titel: *</label>
<div class="col-sm-10">
<input type="text" require class="form-control" id="titel" name="Titel" placeholder="Titel van uw vraag of aanbod" value="{--TITEL--}" >
<div id="titelx" class="form-error form-hidden">Wat is de titel van uw vraag of aanbod?</div>
</div>
</div>
<from>
I know this is an old answer but here is what I usually do:
CSS:
.form-control-inline {
width: auto;
float:left;
margin-right: 5px;
}
Then wrap the fields you want to be inlined in a div and add .form-control-inline to the input, example:
HTML
<label class="control-label">Date of birth:</label>
<div>
<select class="form-control form-control-inline" name="year"> ... </select>
<select class="form-control form-control-inline" name="month"> ... </select>
<select class="form-control form-control-inline" name="day"> ... </select>
</div>
to make it simple, just add a class="form-inline" before the input.
example:
<div class="col-md-4 form-inline"> //add the class here...
<label>Lot Size:</label>
<input type="text" value="" name="" class="form-control" >
</div>