I can't seem to get my checkboxes to align with the labels and select options inside a well using bootstrap 3.3.5. My code is:
<div class="well">
<div class="row">
<div class="col-md-6">
<label class="control-label">Checkboxes</label>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="checkbox">
<input type="checkbox" id="1">1
</div>
<div class="checkbox">
<input type="checkbox" id="2">2
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<label class="control-label">Select</label>
</div>
</div>
<div class="row">
<div class="col-md-6">
<select id="2" class="form_control">
<option value="A">A</option>
<option value="B">B</option>
</select>
</div>
</div>
</div>
Fiddle illustrating misalignment:
https://jsfiddle.net/dwzvsoax/
I'm pretty new to bootstrap, so I'm probably doing something dumb! Thank you in advance.
Wrap your form elements and labels together with a .form-group element.
jsFiddle
Also, you should read the Boostrap Documentation on Forms
<div class="well">
<div class="form-group">
<label>Check Boxes</label>
<div class="checkbox">
<label>
<input type="checkbox" /> 1
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" /> 2
</label>
</div>
</div>
<div class="form-group">
<label>select</label>
<select id="2" class="form-control">
<option value="A">A</option>
<option value="B">B</option>
</select>
</div>
</div>
you could add in to the .checkbox class an attribute margin-left:22px; in the css file and that should give you the desired effect. If it's just on one page though, just add it in style tags at the top of the page, as it may not be desirable everywhere.
I updated your fiddle
Related
I am trying to put 3 drop down select item in the same row, but they end up in the one column in a .cshtml file.
The shorten part of the code is right below (the complete section of code is at the end of the question with the current outcome).
<div class="form-row">
<div class="form-group col-2">
</div>
<div class="form-group col-5">
</div>
<div class="form-group col-5">
</div>
</div>
<div clas="form-row">
<div class="form-group col-4">
</div>
<div class="form-group col-4">
</div>
<div class="form-group col-4">
</div>
</div>
The first section, three pieces show up in the same line as expected. (col-2, col-5, col-5).
But the second section, the three select drop down showing up in a column instead of the same row.
<div class="form-row">
<div class="form-group col-2">
<label>Item ID</label>
<input readonly class="form-control" type="text" value="#pi.ProjectItemId" />
</div>
<div class="form-group col-5">
<label for="ItemName_#(pi.ProjectItemId)">Item Name</label>
<input id="ItemName_#(pi.ProjectItemId)" class="form-control" type="text" value="#pi.ItemName" />
</div>
<div class="form-group col-5">
<label for="ItemDescription_#(pi.ProjectItemId)">Item Description</label>
<textarea id="ItemDescription_#(pi.ProjectItemId)" class="form-control" type="text" row=3>#(pi.ItemDescription)</textarea>
</div>
</div>
<div clas="form-row">
<div class="form-group col-4">
<label for="ItemTechnology_#(pi.TechId)">Technology:</label>
<select class="form-control" id="ItemTechnology_#(pi.ProjectItemId)">
#foreach(var tech in #ViewBag.ListOfTechnologies)
{
#if(#pi.TechId == #tech.TechId)
{
<option value=#(tech.TechId) selected>#(tech.TechId)</option>
}
else
{
<option value=#(tech.TechId)>#(tech.TechId)</option>
}
}
</select>
</div>
<div class="form-group col-4">
<label for="MainApplication_#(pi.ProjectItemId)">Main Application:</label>
<select class="form-control" id="MainApplication_#(pi.ProjectItemId)">
#foreach(var app in #ViewBag.ListOfApplications)
{
#if(#pi.MainApplicationId == #app.ApplicationId)
{
<option value=#(app.ApplicationId) selected>#(app.ApplicationId)</option>
}
else
{
<option value=#(app.ApplicationId)>#(app.ApplicationId)</option>
}
}
</select>
</div>
<div class="form-group col-4">
<label for="SecondaryApplication_#(pi.ProjectItemId)">Secondary Application:</label>
<select class="form-control" id="SecondaryApplication_#(pi.ProjectItemId)">
#foreach(var app in #ViewBag.ListOfApplications)
{
#if(#pi.SecondaryApplicationId == #app.ApplicationId)
{
<option value=#(app.ApplicationId) selected>#(app.ApplicationId)</option>
}
else
{
<option value=#(app.ApplicationId)>#(app.ApplicationId)</option>
}
if (#pi.SecondaryApplicationId == null)
{
<option value=0>No secondary application was chosen.</option>
}
}
</select>
</div>
</div>
Everything was perfect. You have made a spelling mistake for the class in second row. Instead of class, you have mentioned it as clas
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="form-row">
<div class="form-group col-2"> 1
</div>
<div class="form-group col-5"> 2
</div>
<div class="form-group col-5">
3
</div>
</div>
<div class="form-row">
<div class="form-group col-4">
4
</div>
<div class="form-group col-4">
5
</div>
<div class="form-group col-4">
6
</div>
</div>
You are using the wrong classes, you should use col-md-2 or son on.
Look at the documentation https://getbootstrap.com/docs/4.1/layout/grid/
You need to correct your code like this :
<div class="row">
<div class="col-2">
<div class="form-group">
</div>
</div>
<div class="col-2">
<div class="form-group">
</div>
</div>
<div class="col-2">
<div class="form-group">
</div>
</div>
</div>
<div clas="row">
<div class="col-4">
<div class="form-group">
</div>
</div>
<div class="col-4">
<div class="form-group">
</div>
</div>
<div class="col-4">
<div class="form-group">
</div>
</div>
</div>
SO i m trying to add input forms with different column width ..
Below is my code:
`<
div class="row">
<div class="col-md-10">
<div class="form-group form-inline col-md-6 col-lg-4">
<input type="text" name="cw" id="inputammino" value="A">
</div>
<div class="form-group form-inline col-md-4 col-lg-4">
<input type="text" name="cw2" id="inputcusti" value="42.010565">
</div>
<div class="form-group form-inline col-md-2 col-lg-4">
<input type="text" name="cw3" id="amiaci" value="K">
</div>
</div>
</div>
`
But instead of adding more column width to first column its adding it to last..What am I doing wrong?
I am using Bootstrap 3.3.7 and I have formatted your HTML as below by using BootStrap 3.3 Documentation and its working fine for me.
<div class="form-inline">
<div class="form-group">
<div class="col-md-6">
<input type="text" name="cw" id="inputammino" value="A">
</div>
<div class="col-md-4">
<input type="text" name="cw2" id="inputcusti" value="42.010565">
</div>
<div class="col-md-2">
<input type="text" name="cw3" id="amiaci" value="K">
</div>
</div>
</div>
I'm new to bootstrap and have a problem placing two input fields next to each other. I've searched on the internet (and bootstrap.com), but couldn't find the anser.
Code:
Result. But I need the input fields and button next to each other in one row:
I tried using columns... didn't work
You can follow : Display two fields side by side in a Bootstrap Form
<div class="input-group">
<input type="text" class="form-control" placeholder="Start"/>
<span class="input-group-addon">-</span>
<input type="text" class="form-control" placeholder="End"/>
You can try below code
<div class="container content">
<div class='row'>
<form role="form" class="form-horizontal" method="post">
<div class='col-xs-12 col-sm-4'>
<div class="form-group">
<input class="form-control" name="" placeholder="Search from this date">
</div>
</div>
<div class='col-xs-12 col-sm-4'>
<div class="form-group">
<input class="form-control" name="" placeholder="Search till this date">
</div>
</div>
<div class='col-xs-12'>
<div class="form-group">
<button class="btn btn-primary">Search</button>
</div>
</div>
<div class='col-xs-12'>
<div class="form-group">
Back
</div>
</div>
</form>
</div>
</div>
I have code like below. How to make buttons in-line with input ? Now buttons are inline with adjacent column and looks ugly. Live demo here
<div class="row">
<div class="col-md-3">
<div class="form-group">
<label for="x" class="control-label">Function</label>
<input type="text" id="x" class="form-control" placeholder="x"/>
</div>
</div>
<div class="col-md-1">
Get
</div>
<div class="col-md-1">
Stat
</div>
</div>
You can use an input group (though bootstrap say you shouldn't use input groups with selects because it doesn't always behave)
http://getbootstrap.com/components/#input-groups-buttons
edit: for the label above the input group:
<div class="container" style="width: 600px;">
<form id="form" role="form">
<div class="row">
<label for="x" class="control-label">Function</label>
<div class="input-group">
<select id="x" class="form-control" placeholder="x">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>
<span class="input-group-btn">
Get
Stat
</span>
</div>
</div>
</form>
</div>
or for the label as part of the input group:
<div class="container" style="width: 600px;">
<form id="form" role="form">
<div class="row">
<div class="input-group">
<span class="input-group-addon"><label for="x" class="control-label">Function</label></span>
<select id="x" class="form-control" placeholder="x">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>
<span class="input-group-btn">
Get
Stat
</span>
</div>
</div>
</form>
</div>
I added an update to your fiddle:
input above group: http://jsfiddle.net/ced7k0hq/11/
input as part of group: http://jsfiddle.net/ced7k0hq/12/
From the bootstrap docs: http://getbootstrap.com/components/#input-groups
Textual <input>s only
Avoid using <select> elements here as they cannot be fully styled in WebKit browsers.
Avoid using <textarea> elements here as their rows attribute will not be respected in some cases.
thanks #ovitinho for comment about joining the two anchors inside a single input-group-btn :D
I wish to have labels right-aligned next to its input box (with a space in between). However, labels are still left-aligned. According to Boostrap3 documentation and this question, the form-horizontal class should be used, but still result is not right.
The django template code below does generate fields in a two-column fashion, but with left-aligned labels:
<form class="form-horizontal" role="form">
<div class="form-group">
<div class="col-md-3 col-md-offset-1 input-md">
{{ form.code|bootstrap_horizontal }}
</div>
<div class="col-md-3 col-md-offset-2 input-md">
{{ form.name|bootstrap_horizontal }}
</div>
<div class="col-md-3 col-md-offset-1 input-md">
{{ form.company|bootstrap_horizontal }}
</div>
</div>
<div class="btn-group btn-group-lg">
<button class="btn" type="submit">Crear Marca</button>
</div>
</form>
I guess I'm missing something. Thanks in advance for your help.
EDITED:
Output HTML in jsfiddle.
Image of actual output included as well in this link. As you can see, Code & Company are left-aligned.
I think your text is right-aligned but the effect is not visible due to the nesting of your grid classes.
Try something like:
<form class="form-horizontal container" role="form">
<div class="form-group">
<label for="inputEmail1" class="col-sm-2 control-label">Code</label>
<div class="col-sm-4">
<input type="email" class="form-control" id="inputEmail1" placeholder="Email">
</div>
<label for="inputPassword1" class="col-sm-2 control-label">Name</label>
<div class="col-sm-4">
<input type="password" class="form-control" id="inputPassword1" placeholder="Password">
</div>
</div>
<div class="form-group">
<label for="inputEmail1" class="col-sm-2 control-label">Company</label>
<div class="col-sm-4">
<input type="email" class="form-control" id="inputEmail1" placeholder="Email">
</div>
</div>
<div class="btn-group btn-group-lg">
<button class="btn" type="submit">Crear Marca</button>
</div>
</form>
When you nest your grid classes (col--) a child get a percentage of the width of its parent. When you nest a col-lg-6 in a col-lg-6 its with will be 25% of the viewport 50% of 50%.
In the case you want to input next to each other with a float left (your col-- classes add this float) they can't be in different input-groups. The .from-group has a clearfix which undo the float left. So try something like:
<div class="col-sm-6">
<div class="form-group">
<label for="inputEmail1" class="col-sm-4 control-label">Company</label>
<div class="col-sm-8">
<input type="email" class="form-control" id="inputEmail1" placeholder="Email">
</div>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="inputEmail1" class="col-sm-4 control-label">Company 2</label>
<div class="col-sm-8">
<input type="email" class="form-control" id="inputEmail1" placeholder="Email">
</div>
</div>
</div>