improve input form with horizontal labels and vertical labels - html

could you have a look at the HTML/CSS-code and result behind this link?
the CSS part:
div2 {display: table-cell; vertical-align: middle; border: 0px solid red; }
input {margin: 5px; }
label1 {margin-left: 140px; }
label2 {margin-left: 100px; }
label3 {margin-left: 90px; }
label {margin-left: 10px; margin-right: 20px; }
the HTML part:
<div1>
<label1>First name</label1>
<label2>Last name</label2>
<label3>Date of birth</label3>
</div1>
<div2>
<label for='name'>Person 1:</label>
<input type='text' id='name' />
<input type='text' id='name' />
<input type='text' id='name' />
<br>
<label for='name'>Person 2:</label>
<input type='text' id='name' />
<input type='text' id='name' />
<input type='text' id='name' />
<br>
<label for='name'>Person 3:</label>
<input type='text' id='name' />
<input type='text' id='name' />
<input type='text' id='name' />
<br>
<label for='name'>Person 4:</label>
<input type='text' id='name' />
<input type='text' id='name' />
<input type='text' id='name' />
<br>
<label for='name'>Person 5:</label>
<input type='text' id='name' />
<input type='text' id='name' />
<input type='text' id='name' />
</div2>
Is there a way to automatically align the labels on top so they exactly match with the colomns below? Looking forward to your suggestions. Regards, Piotr

use display: table or table
* {
padding;
0;
margin: 0;
}
.wrapper {
display: table;
table-layout: fixed;
}
.row {
display: table-row;
}
.cell {
display: table-cell;
vertical-align: middle;
border: 0px solid red;
padding: 5px 10px;
vertical-align: middle;
}
.row:nth-child(1) {
text-align: center;
}
.row:nth-child(1) .cell {
padding-bottom: 0;
}
.row:nth-child(1) .cell label {
margin-bottom: 0;
}
input, label {
display: block;
width:100%;
margin: 5px 0;
}
label {
margin-left: 5px;
margin-right: 15px;
}
<div class="wrapper">
<div class="row">
<div class="cell"></div>
<div class="cell">
<label>First name</label>
</div>
<div class="cell">
<label>Last name</label>
</div>
<div class="cell">
<label>Date of birth</label>
</div>
</div>
<div class="row">
<div class="cell">
<label for='name'>Person 1:</label>
</div>
<div class="cell">
<input type='text' id='name' />
</div>
<div class="cell">
<input type='text' id='name' />
</div>
<div class="cell">
<input type='text' id='name' />
</div>
</div>
<div class="row">
<div class="cell">
<label for='name'>Person 2:</label>
</div>
<div class="cell">
<input type='text' id='name' />
</div>
<div class="cell">
<input type='text' id='name' />
</div>
<div class="cell">
<input type='text' id='name' />
</div>
</div>
<div class="row">
<div class="cell">
<label for='name'>Person 3:</label>
</div>
<div class="cell">
<input type='text' id='name' />
</div>
<div class="cell">
<input type='text' id='name' />
</div>
<div class="cell">
<input type='text' id='name' />
</div>
</div>
<div class="row">
<div class="cell">
<label for='name'>Person 4:</label>
</div>
<div class="cell">
<input type='text' id='name' />
</div>
<div class="cell">
<input type='text' id='name' />
</div>
<div class="cell">
<input type='text' id='name' />
</div>
</div>
<div class="row">
<div class="cell">
<label for='name'>Person 5:</label>
</div>
<div class="cell">
<input type='text' id='name' />
</div>
<div class="cell">
<input type='text' id='name' />
</div>
<div class="cell">
<input type='text' id='name' />
</div>
</div>
</div>

Related

laying out tables in css

I have been playing with trying to get a bingo card layout working in html. I want to learn more effective ways to layout content in css. There are lots and lots of examples online but I am getting not sure which ways are the best to take.
In this case I have been hacking to display a bingo card. The idea is to input numbers at the moment. I want to layout this nicely - then eventually print it off.
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bingo</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+KR&display=swap" rel="stylesheet">
</head>
<body>
<h1>Card</h1>
<p>15 numbers out of 30</p>
<div class="card">
<div class="card-grid">
<div class="card-row">
<div class="card-number">
<input type="text" class="editable-number" value="1">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="10">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="30">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="50">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="70">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="">
</div>
</div>
<div class="card-row">
<div class="card-number">
<input type="text" class="editable-number" value="">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="23">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="41">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="64">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="83">
</div>
</div>
<div class="card-row">
<div class="card-number">
<input type="text" class="editable-number" value="9">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="19">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="39">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="59">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="70">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="90">
</div>
</div>
</div>
</div>
</body>
</html>
css
:root {
--number-width: 60px;
--row-height: 40px;
}
body {
font-family: "Noto Sans KR", sans-serif;
font-size: 1em;
}
.card {
max-width: 600px;
padding: 10px;
background-color: rgb(255, 5, 5);
border: solid 3px black;
border-radius: 5px;
}
.card-grid {
}
.card-row {
display: block;
margin-bottom: 5px;
}
.card-number {
display: inline-block;
width: var(--number-width);
max-width: var(--number-width);
background-color: white;
}
.editable-number {
width: var(--number-width);
height: var(--row-height);
text-align: center;
border: none;
font-size: 1.5em;
}
result
bingo-result
questions
I want to center the numbers in the grid. I did play with the css transform but that rendered content outside of the red div rectangle.
What is the best approach to take with laying out such a tabular view in html - without a table?
Ideally I want to scale this up to do more things as I learn.
Use CSS CSS Flexbox Layout
:root {
--number-width: 60px;
--row-height: 40px;
}
body {
font-family: "Noto Sans KR", sans-serif;
font-size: 1em;
}
.card {
max-width: 600px;
padding: 10px;
background-color: rgb(255, 5, 5);
border: solid 3px black;
border-radius: 5px;
}
.card-grid {
/* CSS Flexbox Layout using display: flex*/
display: flex;
flex-direction: column;
overflow: hidden;
}
.card-row {
margin-bottom: 5px;
display: flex;
flex-direction: row;
justify-content: space-around;
}
.card-number {
display: inline-block;
width: var(--number-width);
max-width: var(--number-width);
background-color: white;
overflow: hidden;
}
.editable-number {
width: var(--number-width);
height: var(--row-height);
text-align: center;
border: none;
font-size: 1.5em;
box-sizing: border-box;
}
<div class="card">
<div class="card-grid">
<div class="card-row">
<div class="card-number">
<input type="text" class="editable-number" value="1">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="10">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="30">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="50">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="70">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="">
</div>
</div>
<div class="card-row">
<div class="card-number">
<input type="text" class="editable-number" value="">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="23">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="41">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="64">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="83">
</div>
</div>
<div class="card-row">
<div class="card-number">
<input type="text" class="editable-number" value="9">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="19">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="39">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="59">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="70">
</div>
<div class="card-number">
<input type="text" class="editable-number" value="90">
</div>
</div>
</div>
</div>
give card-grid a fixed width and give it and margin auto

How to create multiple rows which contains two text boxes and labels above them in html/css?

I want to create three rows. In each row I want to have two textboxes with labels above them. Right now, I have this html code:
.firstRow, .secondRow, .thirdRow {
display: inline-block;
}
label, .textBox {
display: block;
}
<div class="firstRow">
<label for="name1">Name1</label>
<input class="textBox" formControlName="name1" />
<label for="name2">Name2</label>
<input class="textBox" formControlName="name2" />
</div>
<div class="secondRow">
<label for="name3">Name3</label>
<input class="textBox" formControlName="name3" />
<label for="name4">Name4</label>
<input class="textBox" formControlName="name4" />
</div>
<div class="thirdRow">
<label for="name5">Name5</label>
<input class="textBox" formControlName="name5" />
<label for="name6">Name6</label>
<input class="textBox" formControlName="name6" />
</div>
The outcome is in this link:
https://jsfiddle.net/Lcav5xje/
What should I change?
Here is the snippet using simple display:flex;
also no need to add separate class for every row
.row {
display: flex;
}
.form-grp {
margin: 10px
}
.form-grp label {
display:block;
}
<div class="row">
<div class="form-grp">
<label for="name1">Name1</label>
<input class="textBox" formControlName="name1" />
</div>
<div class="form-grp">
<label for="name2">Name2</label>
<input class="textBox" formControlName="name2" />
</div>
</div>
<div class="row">
<div class="form-grp">
<label for="name3">Name3</label>
<input class="textBox" formControlName="name3" />
</div>
<div class="form-grp">
<label for="name4">Name4</label>
<input class="textBox" formControlName="name4" />
</div>
</div>
<div class="row">
<div class="form-grp">
<label for="name5">Name5</label>
<input class="textBox" formControlName="name5" />
</div>
<div class="form-grp">
<label for="name6">Name6</label>
<input class="textBox" formControlName="name6" />
</div>
</div>
You can use grid to align the items.
example:
.row {
display: block;
}
.grid {
display: grid;
grid-template-rows: 1fr 1fr; /*Two columns*/
grid-auto-flow: column /*to align the input under the label*/;
justify-content: start; /*sticked to the left*/
grid-gap: 0 10px; /*horizontal space between inputs*/
}
<div class="row">
<div class="grid">
<label for="name1">Name1</label>
<input class="textBox" formControlName="name1" />
<label for="name2">Name2</label>
<input class="textBox" formControlName="name2" />
</div>
<div class="row">
<div class="grid">
<label for="name3">Name3</label>
<input class="textBox" formControlName="name3" />
<label for="name4">Name4</label>
<input class="textBox" formControlName="name4" />
</div>
</div>
<div class="row">
<div class="grid">
<label for="name5">Name5</label>
<input class="textBox" formControlName="name5" />
<label for="name6">Name6</label>
<input class="textBox" formControlName="name6" />
</div>
</div>
Try this code..
Demo
.firstRow,
.secondRow,
.thirdRow {
display: inherit;
}
.inner {
display: inline-block;
vertical-align: top;
}
<div class="firstRow">
<div class="inner">
<label for="name1">Name1</label>
<input class="textBox" formcontrolname="name1">
</div>
<div class="inner">
<label for="name2">Name2</label>
<input class="textBox" formcontrolname="name2">
</div>
</div>

How to divide html page

I want to make a html page with three sections and inside each section divide it to left and right. In each section I have three boxes and I want to put two boxes on the left and one box on the right following is the css and html code:
.leftbox {
width: 50%;
padding: 5px;
float: left;
}
.rightbox {
width: 50%;
padding: 5px;
float: right;
}
<div id="rotationFormPopup" class="rotationFormPopup" style="width: 900px; display: none; background: #FFF; border: 1px solid; padding: 10px; margin-top: 100px;">
<h2 class="popup-header">Rotation Forms</h2>
<div class="newRotation-sections">
<h3>Details</h3>
<div class="newRotation-section-1" style="margin-top: 10px;">
<div class="leftbox">
<span>Mob</span> <br />
<input type="text" class="newRotation-mob" style="width: 100%;"><br /><br />
<span>Paddock</span> <br />
<input type="text" class="newRotation-paddock" style="width: 100%;"><br /><br />
</div>
<div class="rightbox">
<span>Date</span> <br />
<input type="text" class="newRotation-date" style="position: relative; display: inline-block; float: left; width: 100%; margin-top: 10px;"><br /><br />
</div>
</div>
<h3>Fencing options</h3>
<div class="newRotation-section-2" style="margin-top: 10px;">
<div class="leftbox">
<span>Available Today</span> <br />
<input type="text" class="newRotation-available" style="width: 100%;"><br /><br />
<span>Paddock Allocation %</span> <br />
<input type="number" class="newRotation-alloc" value="50" style="width: 100%;"><br /><br />
</div>
<div class="rightbox">
<span>Required Result</span> <br />
<input type="text" class="newRotation-result" style="width: 100%;"><br /><br />
</div>
</div>
<h3>Assign As Task</h3>
</div>
</div>
</div>
I receive the below result, I don't know why the fencing options jump to the right side.
Here is the image of my work:
I wrote up this using the Bootstrap Framework. It matches your image exactly.
There's a Codepen if you want to fork and play around with it. It's responsive, too.
/* Roboto Font */
#import url('https://fonts.googleapis.com/css?family=Roboto');
html, body {
height: 100%;
}
body {
font-family: 'Roboto', sans-serif;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" type="text/css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.bundle.min.js"></script>
<div class="container p-5">
<div class="row">
<div class="col-sm-12">
<h5 class="title text-uppercase bg-success text-white p-1">Rotation Forms</h5>
<h4 class="mb-3 mt-3">Details</h4>
</div>
<div class="col-sm-12 col-md-6">
<div class="form-group">
<label for="mob">Mob</label>
<input type="text" class="form-control" id="mob" placeholder="Enter Mob">
</div>
<div class="form-group">
<label for="paddock">Paddock</label>
<input type="text" class="form-control" id="paddock" placeholder="Enter Paddock">
</div>
</div>
<div class="col-sm-12 col-md-6">
<div class="form-group">
<label for="date">Date</label>
<input type="date" class="form-control" id="date" placeholder="Enter Date">
</div>
<h4 class="mb-3 mt-3">Fencing Options</h4>
<div class="form-group">
<label for="avail">Available Today</label>
<input type="text" class="form-control" id="avail" placeholder="NaN">
</div>
<div class="form-group">
<label for="allocation">Paddock Allocation %</label>
<input type="number" class="form-control" id="allocation" placeholder="100">
</div>
<div class="form-group">
<label for="result">Required Result</label>
<input type="text" class="form-control" id="result" placeholder="NaN">
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12 col-md-6">
<h4 class="mb-3 mt-3">Assign As Task</h4>
<div class="form-group">
<label for="assign">Assign to</label><br>
<button type="submit" class="btn btn-success btn-md" id="assign">Add</button>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="checked">
<label class="form-check-label" for="checked">I want to see this too.</label>
</div>
<button type="button" class="btn btn-success btn-md">Save</button>
<button type="button" class="btn btn-success btn-md">Cancel</button>
</div>
</div>
</div>

How to display html form next to each other and in rows?

I am currently trying to get two forms next to each other and then two more forms under it all aligned. If anyone has any suggestions to help me out that would be great. Here is my source code in a jsfiddle.
I am trying to get the name and company input next to each other and then the phone and email below it with the comment textbox at the base. I was trying the 40% width and it sort of helped to get the first row. I was thinking of going the table route as I could probably get that working fine for the forms being aligned but I know tables is not the correct route for coding this.
https://jsfiddle.net/xtwistedmetal/two7hgtm/1/
or
<style type="text/css">
#mc_embed_signup {
background: #fff;
clear: left;
font: 14px Helvetica, Arial, sans-serif;
}
.mc-field-group1 {
display: inline-block;
width: 40%;
}
.mc-field-group2 {
display: inline-block;
}
</style>
<div id="mc_embed_signup">
<form method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate="" action="websitehere">
<div id="mc_embed_signup_scroll">
<div align="center">
<h2> Wholesale Contact Form</h2>
</div>
<div class="mc-field-group1">
<label for="mce-FNAME">Name </label>
<input type="text" value="" name="FNAME" class="required" id="mce-FNAME" />
</div>
<div class="mc-field-group1">
<label for="mce-MMERGE3">Company Name </label>
<input type="text" value="" name="MMERGE3" class="required" id="mce-MMERGE3" />
</div>
<div class="mc-field-group2">
<label for="mce-EMAIL">Email Address </label>
<input type="email" value="" name="EMAIL" class="required email" id="mce-EMAIL" />
</div>
<br>
<div class="mc-field-group2">
<label for="mce-MMERGE2">Phone Number </label>
<input type="text" name="MMERGE2" class="" value="" id="mce-MMERGE2" />
</div>
<div class="mc-field-group">
<label for="mce-COMMENTS">Comments </label>
<!-- <input type="text" value="" name="COMMENTS" class="required" id="mce-COMMENTS" /> -->
<textarea id="mce-COMMENTS" name="COMMENTS" cols="47" rows="3"> </textarea>
</div>
<div id="mce-responses" class="clear">
<div class="response" id="mce-error-response" style="display: none;"></div>
<div class="response" id="mce-success-response" style="display: none;"></div>
</div>
<div class="clear" align="center">
<input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button" />
</div>
</div>
</form>
</div>
You can try an approach like below
.form-group:after{
content: "";
display:table;
clear:both;
}
.form-group-half{
width:44%;
padding:0 3%;
float:left;
}
.form-group-half > label{
display:block;
}
.form-group-half > input,
.form-group-half > select,
.form-group-half > textarea {
width:100%;
}
<div class="form-group">
<div class="form-group-half">
<label>Field 1</label>
<input type="text" name="field1">
</div>
<div class="form-group-half">
<label>Field 2</label>
<input type="text" name="field2">
</div>
</div>
<div class="form-group">
<div class="form-group-half">
<label>Field 3</label>
<input type="text" name="field3">
</div>
<div class="form-group-half">
<label>Field 4</label>
<input type="text" name="field4">
</div>
</div>
HTML ;
<div id="mc_embed_signup">
<form method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate="" action="websitehere">
<div id="mc_embed_signup_scroll">
<div align="center">
<h2> Wholesale Contact Form</h2>
</div>
<div class="mc-field-group1" style=>
<div style="width:40%">
<label for="mce-FNAME">Name </label>
<input type="text" value="" name="FNAME" class="required" id="mce-FNAME" />
</div>
<div style="width:40%">
<label for="mce-MMERGE3">Company Name </label>
<input type="text" value="" name="MMERGE3" class="required" id="mce-MMERGE3" />
</div>
</div>
<div class="mc-field-group2">
<div style="width:40%">
<label for="mce-EMAIL">Email Address </label>
<input type="email" value="" name="EMAIL" class="required email" id="mce-EMAIL" />
</div>
<div style="width:40%">
<label for="mce-MMERGE2">Phone Number </label>
<input type="text" name="MMERGE2" class="" value="" id="mce-MMERGE2" />
</div>
</div>
<br>
<div class="mc-field-group">
<label for="mce-COMMENTS">Comments </label>
<!-- <input type="text" value="" name="COMMENTS" class="required" id="mce-COMMENTS" /> -->
<textarea id="mce-COMMENTS" name="COMMENTS" cols="47" rows="3"> </textarea>
</div>
<div id="mce-responses" class="clear">
<div class="response" id="mce-error-response" style="display: none;"></div>
<div class="response" id="mce-success-response" style="display: none;"></div>
</div>
<div class="clear" align="center">
<input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button" />
</div>
</div>
</form>
</div>
CSS
<style type="text/css">
#mc_embed_signup {
background: #fff;
clear: left;
font: 12px Helvetica, Arial, sans-serif;
}
.mc-field-group1 {
width: 100%;
display: inline-flex;
}
.mc-field-group2 {
display: inline-flex;
width: 100%;
}
label{
color:red;
width:40px !important;
}

Align labels under input boxes using Bootstrap

I'm not sure how to go about getting the effect I want here. I have two input boxes that are on the same line and I want to have labels underneath them and aligned to match the respective input box.
<div class="container">
<form class="form-inline" role="form">
<div class="form-group">
<label for="decimal_input">Label 1</label>
<input type="text" value="1" width="10" id="decimal_input" class="form-control" />
= <label for="input2">Label 2</label>
<input type="text" value="I" width="30" id="input2" class="form-control" />
</div>
</div>
</form>
Take a look at the jsfiddle here for more info:
http://jsfiddle.net/justinhj/bTVKZ/2/
http://jsfiddle.net/isherwood/bTVKZ/6
<div class="container">
<form class="form-inline" role="form">
<div class="form-group">
<div class="pull-left">
<input type="text" value="1" width="10" id="decimal_input" class="form-control" />
<br />
<label for="decimal_input">Label 1</label>
</div>
<div>
<input type="text" value="I" width="30" id="input2" class="form-control" />
<br />
<label for="input2">Label 2</label>
</div>
</div>
</form>
</div>
Your new HTML:
<div class="container">
<form class="form-inline" role="form">
<div class="form-group">
<span class="inner-container">
<label for="decimal_input">Label 1</label>
<input type="text" value="1" width="10" id="decimal_input" class="form-control" />
</span>
=
<span class="inner-container">
<label for="input2">Label 2</label>
<input type="text" value="I" width="30" id="input2" class="form-control" />
</span>
</div>
</div>
</form>
</diV>
Your new CSS (of course I would add a class to the labels):
.container {
margin-top: 10px;
}
.inner-container {
position: relative;
}
label {
top: 25px;
left: 5px;
position: absolute;
}
here's the fiddle
You may try this
Extra CSS:
label {
display:block;
}
.form-group {
display:inline-block;
}
Modified HTML:
<div class="container">
<form class="form-inline" role="form">
<div class="form-group">
<input type="text" value="1" width="10" id="decimal_input" class="form-control" />
<label for="decimal_input">Label 1</label>
</div>
<div class="form-group">
<input type="text" value="I" width="30" id="input2" class="form-control" />
<label for="input2">Label 2</label>
</div>
</form>
</div>
DEMO.