I am trying to align some inputs in my modal. I am trying to set this up the proper way. I have looked and found many examples but they are not working with mine. I understand the bootstrap site says to use form-inline but I dont need my entire form setup like that. I just want the City/State/Zipcode inline with each other. Also you will see a checkbox on the top right corner. I have moved it to the right with a margin-left, but it messes up the responsiveness of it. What is the best way to do this?
plunkr
<div class="form-group clearfix inline">
<label class="col-sm-3 control-label text-right">City</label>
<div class="col-sm-9">
<input style="width:200px" ng-model="customer.city" type="text" class="form-control input-md">
</div>
<label class="col-sm-3 control-label text-right" for="customerSt">State</label>
<div class="col-sm-9">
<select style="width:200px" ng-model="customer.st" class="form-control" ng-options="s.abbr as s.name for s in states">
<option value="">-- Select a State --</option>
</select>
</div>
<label class="col-sm-3 control-label text-right">Zipcode</label>
<div class="col-sm-9">
<input style="width:200px" ng-model="customer.zip" type="text" class="form-control input-md">
</div>
</div>
CheckBox
<div class="form-group clearfix" style="margin-left:520px">
<label class="col-sm-3 control-label text-right">Status</label>
<div class="col-sm-9">
<input style="width:50px" type="checkbox" ng-model="job.status" value="" class="form-control">
</div>
You would need to modify a little css and use nested columns.
This is an example of nesting columns in a form. You can use the same ideas to adjust your form.
DEMO: http://jsbin.com/kemumu/1/
Regarding the checkbox that you pushed into place with margin. If it looks good at 900px but strange at under that width, then put css in a min-width media query where it looks good and remove it outside the media query.
Notes: .form-group puts some nice vertical spacing when a form is stacked (in smaller viewports) but it also acts like a .row (with its negative -left and -right margins), so this css when it's used on a column (as I have done) gets adjusted. Plus the gutter which is 30px is too big for a form.
There's no need to put .clearfix on your .form-groups unless you've floated them for some reason.
CSS EXAMPLE:
.custom-form [class*="col-"].form-group {margin-left:0;margin-right:0;}
.custom-form .form-group [class*="col-"] .row [class*="col-"] {
padding-left: .5%;
padding-right: .5%;
}
.custom-form .form-group [class*="col-"] .row {
margin-left: -.5%;
margin-right: -.5%;
}
HTML EXAMPLE:
<form class="form-horizontal custom-form" role="form">
<div class="form-group">
<label class="col-sm-3 control-label">Card Holder's Name</label>
<div class="col-sm-9">
<div class="row">
<div class="col-sm-6 form-group">
<input type="text" class="form-control" autocomplete="off" maxlength="4" placeholder="First Name" required>
</div><!--nested col-sm-6-->
<div class="col-sm-6 form-group">
<input type="text" class="form-control" autocomplete="off" maxlength="4" placeholder="Last Name" required>
</div><!--nested col-sm-6-->
</div><!-- /.form-group > .row -->
</div><!-- /.col-sm-9 -->
</div><!-- /.form-group -->
<div class="form-group">
<label class="col-sm-3 control-label">Credit Card Number:</label>
<div class="col-sm-9">
<div class="row">
<div class="col-sm-3 form-group">
<input type="text" class="form-control" autocomplete="off" maxlength="4" pattern="\d4" placeholder="1st four digits" required>
</div>
<!--nested col-sm-3-->
<div class="col-sm-3 form-group">
<input type="text" class="form-control" autocomplete="off" maxlength="4" pattern="\d4" placeholder="2nd four digits" required>
</div>
<!--nested col-sm-3-->
<div class="col-sm-3 form-group">
<input type="text" class="form-control" autocomplete="off" maxlength="4" pattern="\d4" placeholder="3rd four digits" required>
</div>
<!--nested col-sm-3-->
<div class="col-sm-3">
<input type="text" class="form-control" autocomplete="off" maxlength="4" pattern="\d4" placeholder="4th four digits" required>
</div>
<!--nested col-sm-3-->
</div><!-- /.form-group > .row -->
</div><!-- /.col-sm-9 -->
</div><!-- /.form-group -->
<div class="form-group">
<label class="col-sm-3 control-label">Expiration Date:</label>
<div class="col-sm-9">
<div class="row">
<div class="col-sm-9 form-group">
<select class="form-control">
<option>January</option>
<option>...</option>
<option>December</option>
</select>
</div>
<!--nested col-sm-9-->
<div class="col-sm-3 form-group">
<select class="form-control">
<option>2013</option>
<option>...</option>
<option>2015</option>
</select>
</div>
<!--nested col-sm-3-->
</div><!-- /.form-group > .row -->
</div><!-- /.col-sm-9 -->
</div><!-- /.form-group -->
<div class="form-group">
<label class="col-sm-3 control-label">CVV Code:</label>
<div class="col-sm-9">
<div class="row">
<div class="col-sm-4">
<input type="text" class="form-control" autocomplete="off" maxlength="3" pattern="\d3" placeholder="3 digits on back of card" required>
</div><!--nested col-sm-4-->
</div><!-- /.form-group > .row -->
</div><!-- /.col-sm-9 -->
</div><!-- /.form-group -->
<div class="form-group">
<div class="col-sm-offset-3 col-sm-9">
<button type="submit" class="btn btn-primary btn-custom">Submit</button>
<button type="button" class="btn btn-default btn-custom">Cancel</button>
</div><!-- /.col-sm-offset-3 col-sm-9 -->
</div><!-- /.form-group -->
</form><!-- /.form-horizontal -->
</div><!-- /.container -->
**
If you want responsiveness in your site, then make/add different css and add them to different scree size.. for example..
<h2 class="visible-sm visible-md visible-lg">Some text here</h2>
The above h2 heading will show on only tablet,s smart TV's, laptop's desktops etc....
<h4 class="visible-xs">Some text here</h4>
When you see the same heading on small devices like smart phone's, or smaller, then it adjust it size according to the specified and only show on small devices....
Note: Please Read the twitter bootstrap documentation about responsiveness here
I had to add some custom css classes to do that. For example
#media (min-width: 768px) {
.input-inline .form-group {
display: inline-block;
margin-bottom: 0;
vertical-align: middle;
}
.input-inline .form-control {
display: inline-block;
}
.input-inline select.form-control {
width: auto;
}
.input-inline .radio,
.input-inline .checkbox {
display: inline-block;
margin-top: 0;
margin-bottom: 0;
padding-left: 0;
}
.input-inline .radio input[type="radio"],
.input-inline .checkbox input[type="checkbox"] {
float: none;
margin-left: 0;
}
}
}
So no i do not add the form-inline class at my form. When i need an inline input I write the following:
<div class="form-group input-inline">
<label class="sr-only" for="exampleInputEmail2">Email address</label>
<input type="text" class="form-control">
<div>
I might have missed copying something from my code but this is the general idea. You just need to copy from bootstrap the .form-inline values and replace it with .input-inline.
Related
<div class="modal" id="myModal" style="width:50%; top:15%;" role="dialog" >
<div class="">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-bodys" style="padding:20px 8px 20px 20px">
<a style="background: #EAEAEA;" class="wt-closebtn close closeButtonJoinNOw" aria-label="Close"><i class="fa fa-times" data-dismiss="modal"></i></a>
<form id="wt-single-joinnow-form" class="row">
<h2 class="col-sm-12"> Join Us Now </h2>
<div class="form-group col-sm-6" >
<label for="usrname"> First Name</label>
<input type="text" class="form-control" name="first_name" id="first_name" placeholder="Enter your first name">
</div>
<div class="form-group col-sm-6">
<label for="usrname"> Last Name</label>
<input type="text" class="form-control" name="last_name" id="last_name" placeholder="Enter your last name">
</div>
<div class="form-group col-sm-12" >
<label for="usrname"> Email Address</label>
<input type="text" class="form-control" name="email" id="email" placeholder="Enter your email">
</div>
<div class="form-group col-sm-12">
<label for="psw"> Password</label>
<input type="password" class="form-control" minlength="8" maxlength="16" id="password" name="password" placeholder="Enter your password">
<span id="password_strength"></span>
</div>
<div class="form-group col-sm-12">
<label for="psw"> Re-type Password</label>
<input type="password" class="form-control" minlength="8" maxlength="16" id="pass2" placeholder="Re-type your password" onkeyup="checkPass(); return false;">
<span id="confirmMessage" class="confirmMessage"></span>
</div>
<div class="formRadio123" id="customrediobtnmsgid">
<label>I want to start as:</label>
</div>
<div class="formRadio" id="customrediobtnid">
<input checked="checked" type="radio" class="" id="userTyp" name="user_type" value="freelancer">
<label for="Freelancer">Freelancer</label>
<input type="radio" id="userType" name="user_type" value="Client">
<label for="Client">Client</label>
<!-- <input style="visiblity:hidden !important; display: none;" type="radio" class="intersmodalclassclick" id="userType" name="user_type" value="Intern">
<label for="Intern">Intern</label> -->
</div>
<div class="problemSignUpError" id="problemSignUpError"></div>
<button class="btn btn-success btn-block" id="myBtn1" aria-hidden="true"> Join Now</button>
</form>
</div>
</div>
</div>
</div>
<link href="https://cdn.jsdelivr.net/npm/select2#4.1.0-beta.1/dist/css/select2.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/select2#4.1.0-beta.1/dist/js/select2.min.js"></script>
<script>
$(document).ready(function() {
$('.js-example-basic-multiple').select2();
});
</script>
I want to make this form responsive it is responsive for some sites but not responsive for the other so need to make it responsive . if anyone can guide me what to change in this code to make it responsive .I can share the css code for it as well as well as the form but I need to make it responsive on all mobiles devices . it works well on some but not on all .
Not responsive
Responsive
You can use #media rule and different css for different device
#media (min-width: 576px) {
//your css
}
You can change min and max-width according to ur device
you can use this css property to specify the width to your form. as soon the width of device will go down from 570(which is most of the cell phones) it will change
#media only screen and (max-width: 570px) {
/*
write the width and height of your form by using form property or class containing
the form
*/
}
I wanted to use the bootstrap and make a horizontal form. Unfortunately, my form generates a normal, normal one. As if form-horizontal does not work (blocks are generated from ReactJS).
<div id="app" class="container">
<block>
<block>
<div class="row">
<header class="col-sm-12 header">
<h1 class="text-center text-uppercase header__title">formularz wprowadzania danych osobowych!</h1>
</header>
</div>
<block>
<form class="form-horizontal">
<div class="form-group">
<label class="control-label col-sm-2" for="firstName">Imie: </label>
<div class="inputs col-sm-10">
<input class="form-control" type="text" id="firstName" name="firstName" value="">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="lastName">Nazwisko: </label>
<div class="col-sm-10">
<input class="form-control" type="text" id="lastName" name="lastName" value="">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input type="submit" value="dalej">
</div>
</div>
</form>
</block>
</block>
Dropped the .form-horizontal class requirement.
.form-group no longer applies styles from the .row via mixin, so .row
is now required for horizontal grid layouts (e.g., <div class="form-group row">).
Added new .col-form-label class to vertically center labels with
.form-controls.
Added new .form-row for compact form layouts with the grid classes
(swap your .row for a .form-row and go).
Bootstrap 4 Forms
I use bootstrap in my project.
The width of the area is 350px.
I have this html elements:
<form class="form-inline">
<div class="input-group input-group-sm col-xs-5" >
<input type="text" class="form-control" placeholder="search">
<div class="input-group-btn">
<button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button>
</div>
</div>
<div class="input-group input-group-sm">
<select class="form-control" ng-model="" ng-options="">
<option value="">- authority-</option>
</select>
</div>
</form>
Here is plunker.
How can I make search box and dropdown list in one line.
You don't need css to fix this, you can do it with bootstrap styles.
Wrap the form in a 12 wide container (col-lg-12) and wrap each input in a 6 wide container (col-lg-6). (For simplicities sake I only used desktop size in the example)
This would look like:
<div class="col-lg-12">
<!-- start form -->
<div class="col-lg-6">
<!-- input -->
</div>
<div class="col-lg-6">
<!-- input -->
</div>
<!-- end form -->
</div>
That way bootstrap will cut the screen in half (12 / 2 = 6) and put the input box in there.
To make it work with your code have a look at this fiddle
Note I added col-lg, col-md, col-sm and col-xs to make them appear on the same line regardless of screen size.
EDIT:
To put all of this in another panel use:
<div class="panel panel-default">
<div class="panel-body">
<!-- form row -->
</div>
</div>
Working fiddle: http://jsfiddle.net/92z54z04/596/
.input-group are table displayed, so:
.input-group {
display: inline-table;
}
will solve your problem.
JSFiddle
<form class="form-inline">
<div class="form-group" >
<input type="text" placeholder="search"/>
<button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button>
</div>
<select class="form-group" ng-model="builderStep1.inspectionArchiveData.DomainId" ng-options="item.Id as item.Description for item in builderStep1.lookups.domain">
<option value="">- authority-</option>
</select>
</form>
you can do it with bootstrap easily by using col-xs-6 property
here is the working code:
<form class="form-inline">
<div class="col-xs-6">
<div class="input-group input-group-sm" >
<input type="text" class="form-control" placeholder="search">
<div class="input-group-btn">
<button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button>
</div>
</div>
</div>
<div class="col-xs-6">
<div class="input-group input-group-sm">
<select class="form-control" ng-model="builderStep1.inspectionArchiveData.DomainId" ng-options="item.Id as item.Description for item in builderStep1.lookups.domain">
<option value="">- authority-</option>
</select>
</div>
</div>
</form>
You could extend bootstrap to allow a select element inside your input group.
This depends on your usecase if it is intuitive, but I think this may be a good looking option to evaluate.
You basically copy and paste some of bootstraps style to make the select element fit into a input group.
If you have control over the sass, less files, you may be able to do it cleaner than I did.
.input-group-select:not(:first-child):not(:last-child) {
border-radius: 0;
}
.input-group-select {
position: relative;
width: 1%;
white-space: nowrap;
vertical-align: middle;
display: table-cell;
}
.input-group-select>select {
border-color: #ccc;
margin-top: 0px;
margin-bottom: 0px;
padding-top: 7px;
padding-bottom: 7px;
border-radius: 0;
border-left-width: 0;
}
.input-group-btn:not(:first-child):not(:last-child)>.btn {
border-radius: 0;
border-left-width: 0;
}
.input-group-select:last-child>select {
border-radius: 0 3px 3px 0;
}
.input-group-sm>.input-group-select>select {
height: 30px;
padding: 5px 10px;
font-size: 12px;
line-height: 1.5;
}
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet" />
<form class="form-inline">
<div class="input-group input-group-sm col-xs-5">
<input type="text" class="form-control" placeholder="search">
<div class="input-group-select">
<select ng-model="builderStep1.inspectionArchiveData.DomainId" ng-options="item.Id as item.Description for item in builderStep1.lookups.domain">
<option value="">- authority-</option>
</select>
</div>
<div class="input-group-btn">
<button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button>
</div>
</div>
<div class="input-group input-group-sm col-xs-5">
<input type="text" class="form-control" placeholder="search">
<div class="input-group-select">
<select ng-model="builderStep1.inspectionArchiveData.DomainId" ng-options="item.Id as item.Description for item in builderStep1.lookups.domain">
<option value="">- authority-</option>
</select>
</div>
</div>
<div class="input-group input-group-sm col-xs-5">
<input type="text" class="form-control" placeholder="search">
<div class="input-group-btn">
<button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button>
</div>
<div class="input-group-select">
<select class="select" ng-model="builderStep1.inspectionArchiveData.DomainId" ng-options="item.Id as item.Description for item in builderStep1.lookups.domain">
<option value="">- authority-</option>
</select>
</div>
</div>
</form>
Just use style in div:
display:inline-table;
http://jsfiddle.net/ankitg1602/mqnrmLjb/1/
The button in the jsFiddle below is vertical aligned with the labels. That doesn't look good and I would like it to align with the select box instead.
How do I do that?
jsFiddle
<div class="container">
<form id="bookingForm" class="form-horizontal" method="post">
<div class="form-group">
<div class="col-sm-3">
<label class="control-label">Sender</label>
<select class="form-control">
<option>Choose a sender</option>
</select>
</div>
<div class="col-sm-3">
<label class="control-label">Receiver</label>
<select class="form-control">
<option>Choose a receiver</option>
</select>
</div>
<div class="col-sm-3">
<label class="control-label">Delivery</label>
<select class="form-control">
<option>Choose a delivery address</option>
</select>
</div>
<div class="col-sm-3">
<button type="button" class="btn btn-primary">Manage customers...</button>
</div>
</div>
</form>
</div>
I personally wouldn't add the margin-top, if you can avoid it. Purely down to the fact that when you look at it on a different device you will probably need to remove said margin.
I would add an "empty" form label above the button:
<div class="container">
<form id="bookingForm" class="form-horizontal" method="post">
<div class="form-group">
<div class="col-sm-3">
<label class="control-label">Sender</label>
<select class="form-control">
<option>Choose a sender</option>
</select>
</div>
<div class="col-sm-3">
<label class="control-label">Receiver</label>
<select class="form-control">
<option>Choose a receiver</option>
</select>
</div>
<div class="col-sm-3">
<label class="control-label">Delivery</label>
<select class="form-control">
<option>Choose a delivery address</option>
</select>
</div>
<div class="col-sm-3">
<label class="control-label" style="display: block;"> </label>
<button type="button" class="btn btn-primary">Manage customers...</button>
</div>
</div>
</form>
</div>
Flexbox, I find myself coming back to how good it is over and over again.
So what we want if for the button to move down so it's against the bottom of the block, not the top. We could move it a number of ways, but they all rely on you getting the number of pixels or percent right, and that seems like a lot of effort.
Here's the flexbox 'lazy' solution
#import url('http://getbootstrap.com/dist/css/bootstrap.css');
body {
padding-top: 50px;
}
.form-group {
display: flex;
}
.form-group .flex-down {
align-self: flex-end;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.1.0/bootstrap.min.js"></script>
<div class="container">
<form id="bookingForm" class="form-horizontal" method="post">
<div class="form-group">
<div class="col-sm-3">
<label class="control-label">Sender</label>
<select class="form-control">
<option>Choose a sender</option>
</select>
</div>
<div class="col-sm-3">
<label class="control-label">Receiver</label>
<select class="form-control">
<option>Choose a receiver</option>
</select>
</div>
<div class="col-sm-3">
<label class="control-label">Delivery</label>
<select class="form-control">
<option>Choose a delivery address</option>
</select>
</div>
<div class="col-sm-3 flex-down">
<button type="button" class="btn btn-primary">Manage customers...</button>
</div>
</div>
</form>
</div>
Hope you find this helpful.
I added this to the CSS
.form-group {
display: flex;
}
.form-group .flex-down {
align-self: flex-end;
}
and the class flex-down to the div containing the button.
try this.
add one label tag above the button with space (no content)
inside button use the class form-control.
#import url('http://getbootstrap.com/dist/css/bootstrap.css');
body {
padding-top: 50px;
}
<div class="container">
<form id="bookingForm" class="form-horizontal" method="post">
<div class="form-group">
<div class="col-sm-3">
<label class="control-label">Sender</label>
<select class="form-control">
<option>Choose a sender</option>
</select>
</div>
<div class="col-sm-3">
<label class="control-label">Receiver</label>
<select class="form-control">
<option>Choose a receiver</option>
</select>
</div>
<div class="col-sm-3">
<label class="control-label">Delivery</label>
<select class="form-control">
<option>Choose a delivery address</option>
</select>
</div>
<div class="col-sm-3">
<label class="control-label"> </label>
<button type="button" class="btn btn-primary form-control">Manage customers...</button>
</div>
</div>
</form>
</div>
do this as said by #Andrew,
button{
margin-top:25px;
}
Add 25px top margin to your button .
.btn-primary {
margin-top: 25px;
}
You can translate the Y position using transform: translateY(75%);. Updated Fiddle
Add below code to your CSS:
button {
transform: translateY(75%);
}
I wouldn't change the button margin as it will affect every button.
How about adding an invisible label and the button take all the space of the column? I think it looks nicer on devices too.
See example bellow:
http://jsfiddle.net/Dhanck/fpurv0L9/7/
<div class="col-sm-3">
<label style="visibility:hidden">das</label>
<button type="button" class="btn btn-primary btn-group-justified">Manage customers...</button>
</div>
I am trying to use affix of bootstrap 3.
Its working fine but i need to do the button affix right to container not to window.
The problem i am facing is when i Ctrl-- to reduce screen size button get stick on right of window.(facing problem on large screen)
How can i stick button to right of container.so when screen size get large it display right to container.
Here is link: Fiddle link
.save-btn .affix {
top: 100px;
right: 0px;
}
.container {
border: 1px solid #ccc;
}
<div class="container">
<div class="row">
<div class="col-md-12">
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail1" placeholder="Enter email">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password">
</div>
<div class="form-group">
<label for="exampleInputFile">File input</label>
<input type="file" id="exampleInputFile">
<p class="help-block">Example block-level help text here.</p>
</div>
<div class="checkbox">
<label>
<input type="checkbox"> Check me out
</label>
</div>
<div class="save-btn">
<button name="submit" type="submit" value="Save" class="btn btn-orange btn-lg affix" data-spy="affix" data-offset-top="0">Save </button>
</div>
</form>
</div>
</div>
</div>
The jsfiddle is using BS 2.x, but your markup is for Bootstrap 3.
I created a Bootply (which includes BS 3 automatically): http://www.bootply.com/95296
I think you want to use pull-right and not affix to pull the button to the right.