How can I create a horizontal form in Semantic UI? - semantic-ui

I see there are horizontal examples in Bootstrap (form-horizontal), but Semantic UI only seems to have form layouts where the label is above the input.

In the docs section, You can find Semantic UI form inline and Grouped fields which is similar to form-horizontal of Twitter Bootstrap.
To create a new row of fields inside the form, wrap the elements inside <div class="inline field"> </div>
/* Code added for presentation in SO snippet, ignore this CSS */
* > div,
h1 {
margin-left: 20px !important;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.1.3/semantic.min.css" rel="stylesheet" />
<h1>Single</h1>
<div class="ui form">
<div class="inline field">
<label>Last name</label>
<input placeholder="Full Name" type="text">
</div>
<div class="inline field">
<label>Last name</label>
<input placeholder="Full Name" type="text">
</div>
</div>
<h1>Grouped</h1>
<div class="ui form">
<div class="inline fields ui grid container centered">
<label class="four wide column">Lengthy Phone numbers</label>
<div class="field four wide column">
<input type="text" placeholder="(xxx)">
</div>
<div class="four wide column field">
<input type="text" placeholder="xxx">
</div>
</div>
<div class="inline fields ui grid container centered">
<label class="four wide column">Phone Number</label>
<div class="four wide column field">
<input type="text" placeholder="(xxx)">
</div>
<div class="field four wide column">
<input type="text" placeholder="xxx">
</div>
</div>
</div>

The first part of the solution, i.e. class="inline field" does not work if the labels have different width, also the labels are not right-aligned as in the bootstrap example. One could solve this like this
<div class="inline field">
<label style="width:30%; text-align:right;">Last name</label>
<input placeholder="Full Name" type="text">
</div>
But that's ugly.

Related

How to center input boxes (bootstrap form)

<div class="container-full">
<div class="jumbotron text-center" style="background-color:#fff" ng-show="registrationForm">
<p class="genericText">Fill out the following information to create your profile.</p>
<!-- FORM -->
<!-- pass in the variable if our form is valid or invalid -->
<form name="goalsForm" ng-submit="submitForm(goalsForm.$valid)">
<div style='width: 100%; display: inline-block;'>
<div class="form-group col-xs-4">
<label for="exampleInputEmail1">Create Password</label>
<input type="Text" class="form-control" id="inputGoal" placeholder="Enter a password" ng-model="goal">
</div>
<div class="form-group col-xs-4">
<label for="exampleInputEmail1">Confirm Password</label>
<input type="Text" class="form-control" id="inputGoal" placeholder="Confirm your password" ng-model="goal">
</div>
</div>
<button type="submit" class="btn btn-default">Complete</button>
</form>
</div>
</div> <!-- /container full -->
The above is my code for my form, I am using the full width bootstrap layout within Angular.js. Here is a screen of the output.
The two input boxes are within a parent div that is 100% wide, I am trying to center the two input boxes so that it does not lose it's responsiveness when resized.
I have tried
.text-center
margin: auto
without any success.
How can I do this?
Thanks.

Bootstrap 3 Vertical Align issue with grid sections containing input elements

I have a row that is split down into various columns and sub-columns. In the proper example there are several more inputs but I've removed them for clarity as they're not needed for this example.
<form id="inputForm" class="form-inline" role="form">
<div class="row">
<div class="col-xs-4">
<label class="control-label">Primary Packaging:</label>
</div>
<div class="col-xs-6">
<label for="pack1Height" class="control-label">Height:</label>
<div class="input-group">
<input type="text" id="pack1Height" class="form-control small text-right" />
<span class="input-group-addon">mm</span>
</div>
</div>
<div class="col-xs-2">
<label class="control-label">Vol:</label>
<label class="control-label">999</label>
<label class="control-label">cm<sup>3</sup></label>
</div>
</div>
</form>
If you look at http://jsfiddle.net/53vu25ad/ you can see the issue as "Primary Packaging" and "Vol: 999 cm3" are not vertically aligned within the row - they're top aligned. Is there something I'm missing here?
(ps: On my form, the "height" label and the input element are on the same line, I have no idea why they're not in this jsfiddle, but it's not relevant to the question - I would still expect to see the two labels either side aligned vertically).
Using bleeding-edge not-yet-released Bootstrap v3.2.1: JS Fiddle
The trick is to use a dummy .form-control-static:
<div class="col-xs-4">
<div class="form-group">
<label class="control-label">Primary Packaging:</label>
<p class="form-control-static"> </p>
</div>
</div>
Well without using experimental bootstrap, the way I got around this was adding a simple custom class that matched the form-control element height of 34px.
By setting the row line-height to the same, it automatically valigns content.
.fixedRow {
line-height: 34px;
}
<div class="row fixedRow">
<div class="col-xs-4">
<label class="control-label">Primary Packaging:</label>
</div>
...
Updated jsfiddle: http://jsfiddle.net/53vu25ad/2/
Please find the updated jsfiddle
You may need to use the .form-group class for .form-inline
<form id="inputForm" class="form-inline" role="form">
<div class="form-group">
<label class="control-label">Primary Packaging:</label>
</div>
<div class="form-group">
<label for="pack1Height" class="control-label">Height:</label>
<div class="input-group">
<input type="text" id="pack1Height" class="form-control small text-right" />
<span class="input-group-addon fw1">mm</span>
</div>
</div>
<div class="form-group">
<label class="control-label">Vol:</label>
<label class="control-label">999</label>
<label class="control-label">cm<sup>3</sup></label>
</div>
</div>
</div>
</form>

Narrow size of inputs in bootstrap 3

I want to narrow the size of input boxes in the horizontal form.
I used col-sm-4 to make text boxes narrower.
<form class="form-horizontal">
<div class=" form-group">
<label class="col-sm-2 control-label">date</label>
<div class="col-sm-4">
<input name="date" type="text" class="form-control" />
</div>
</div>
</form>
For big size it works, however when I resize the form and make it smaller, suddenly, the length of input box will stretch and become larger. So for big screens the input will have 230px and for smaller screen it will have 608px
The fiddel http://jsfiddle.net/3YWkd/
I want that the size of text box remain the same during page shrink.
You just need to add the mobile (xs) classes, like so:
<div class="col-sm-4 col-xs-4">
<input name="fromDate" type="text" class="form-control" />
</div>
Or just leave the col-xs-4, no need for the sm in this case.
Edit:
Re: your comment, you may use slightly different html, like soQ
<div class=" form-group">
<div class="col-xs-2">
<label class="control-label" for="fromDate">date</label>
</div>
<div class="col-xs-4">
<input name="fromDate" type="text" class="form-control" />
</div>
</div>
fiddle
This should do it:
<form class="form-horizontal">
<div class=" form-group">
<label class="col-sm-2 col-xs-12 control-label">date</label>
<div class="col-sm-4 col-xs-4">
<input name="date" type="text" class="form-control" />
</div>
</div>
</form>

Inputs of different sizes bootstrap

I have this problem - I need to make 3 INPUT, 1 wide (across the width of the screen) and below 2 small (exactly half the width of the first INPUT element), but it turns out that the size they are not the same. How to make an exact match width dimensions?
<form class="navbar-form">
<label>Where are you going?</label>
<input type="text" class="span8" data-provide="typeahead" data-items="5" placeholder="City, attraction, address, or airport">
<label>When?</label>
<input type="text" class="datepicker span4" id="dpd1" placeholder="Choose Arrive Date">
<input type="text" class="datepicker span4" id="dpd2" placeholder="Choose Depart Date">
</form>
you can see all code here
Maybe you can try something like this to avoid the extra space on inputs:
<div class="wrapper">
<div class="row-fluid">
<input class="span12"/>
</div>
<div class="row-fluid">
<div class='span6'>
<input class="span12"/>
</div>
<div class='span6'>
<input class="span12"/>
</div>
</div>
</div>
Demo

twitter bootstrap span not aligning properly

For some reason, when I apply spans the spans do not align themselves into a proper grid. It doesn't seem to matter what type of element I apply the span to, in this case it is inputs. I obviously want them to align themselves, what am I doing wrong?
Fiddle here: http://jsfiddle.net/fKQsj/
<div class="row-fluid">
<div class="span12">
<input type="text" class="span4" placeholder="First" />
<input type="text" class="span4" placeholder="Middle" />
<input type="text" class="span4" placeholder="Last" />
</div>
</div>
<div class="row-fluid">
<div class="span12">
<input type="text" class="span4" placeholder="City" />
<input type="text" class="span2" placeholder="State" />
<input type="text" class="span2" placeholder="Zip5" />
<input type="text" class="span4" placeholder="Store" />
</div>
</div>
<div class="row-fluid">
<div class="span12">
<div class="span4 offset8">
<button class="btn btn-success pull-right">Search</button>
</div>
</div>
</div>
Taken from the manual
For multiple grid inputs per line, use the .controls-row modifier class for proper spacing.
It floats the inputs to collapse white-space, sets the proper margins, and clears the float.

Resources