I'm using bootstrap toggle to create switches like so:
<form>
<div class="checkbox">
<label>
<input type="checkbox" data-toggle="toggle" checked="checked" />
Toggle Text Right
</label>
</div>
<div class="checkbox">
<label>
Toggle Text Left
<input type="checkbox" data-toggle="toggle" />
</label>
</div>
</form>
Is there a way to move the label to the left of the switch? I tried by putting the text before the input, but it doesn't fit well.
http://jsfiddle.net/sjxd1vpt/2/
Or if you do not specifically need the label tag you could use a span.
<form>
<div class="checkbox">
<input type="checkbox" data-toggle="toggle" checked="checked" />
<span>
Toggle Text Right
</span>
</div>
<div class="checkbox">
<span>
Toggle Text Left
</span>
<input type="checkbox" data-toggle="toggle" />
</div>
It appears the bootstrap-toggle css has a margin-left: -20px;
Simply add a custom class to the desired left label like so.
.left .toggle {
margin-left: 5px;
}
This will maintain the structure Bootstrap-Toggle expects in case they have styling tied in such as:
label input {
// some input targeted styling
}
http://jsfiddle.net/sjxd1vpt/5/
You should use bootstrap container-fluid wrappers to achieve the effect.
<form>
<div class="checkbox container-fluid" >
<label>
<input type="checkbox" data-toggle="toggle" checked="checked" />
Toggle Text Right
</label>
</div>
<div class="checkbox container">
<label>
Toggle Text Left
</label>
<input type="checkbox" data-toggle="toggle" />
</div>
Your label tag should be closed before the input tag.
<form>
<div class="checkbox">
<label> Toggle Text Right </label>
<input type="checkbox" data-toggle="toggle" checked="checked" />
</div>
<div class="checkbox">
<label> Toggle Text Left </label>
<input type="checkbox" data-toggle="toggle" />
</div>
</form>
This should prevent the button toggle from overlapping on the text.
Here : http://jsfiddle.net/sjxd1vpt/4/
Related
Probably has been asked before but didn't manage to find an answer.
I would simply like to right align the bootstrap4 toggle buttons.
<ul >
<li>
<label for="test1">Small Length Label</label>
<input id="test1" class="float-right" style="float: right" checked data-toggle="toggle" type="checkbox" />
</li>
<li>
<label for="test2">Longer__ Length Label </label>
<input id="test2" style="float: right" checked data-toggle="toggle" type="checkbox" />
</li>
<li>
<label for="test3">Longer_Longer_Longer Label </label>
<input id="test3" style="float: right" checked data-toggle="toggle" type="checkbox" />
</li>
</ul>
Here is a JSFiddle showing the current alignment.
I would like the toggle buttons to be on the same column no matter the text length.
I think what you're looking for is <div class="d-flex justify-content-between">
Just wrap the elements inside the li like this:
<li>
<div class="d-flex justify-content-between">
<label for="test1">Small Length Label</label>
<input id="test1" class="float-right" style="float: right" checked data-toggle="toggle" type="checkbox" />
</div>
</li>
To have space between the text and input
I would use flexbox for this. Just add the following classes to the ul element: d-flex flex-column align-items-end. And, optionally, a width of your choice.
I am trying to get a radio button, dropdown, and checkbox on the same line for where the second radio button appears. I am using Bootstrap 4, but I do not need this to look or conform to bootstrap ideals. Plain looking html is fine.
I thought that display:inline, or display:inline-block using a div around the second radio group should have done it, but the stubborn checkbox remains in the line below, rather than inline.
What I want:
Line 1: Radio button (Popular)
Line 2: Radio button (Order), Dropdown, Checkbox
What I have:
Line 1: Radio button (Popular)
Line 2: Radio button (Order), Dropdown
Line 3: Checkbox
Code below:
<div class="form-check">
<label class="form-check-label">
<input style="height:1em; width:1em;" type="radio" class="form-check-input" value="popular" name="abc" checked>Popular
</label>
</div>
<div class="form-check">
<div style="display:inline-block;">
<label class="form-check-label">
<input style="height:1em; width:1em;" type="radio" class="form-check-input" value="order" name="abc" checked>Order
</label>
<select id="user_tag_dropdown">
<option>One</option>
<option>Two</option>
</select>
<div class="checkbox">
<label>
<input type="checkbox"> All
</label>
</div>
</div>
</div>
try using it like this..
<div class="form-check">
<label class="form-check-label">
<input style="height:1em; width:1em;" type="radio" class="form-check-input" value="popular" name="abc" checked>Popular
</label>
</div>
<div class="form-check">
<div style="display:inline-block;">
<label class="form-check-label">
<input style="height:1em; width:1em;" type="radio" class="form-check-input" value="order" name="abc" checked>Order
</label>
<select id="user_tag_dropdown">
<option>One</option>
<option>Two</option>
</select>
<div class="checkbox" style="display: inline">
<label>
<input type="checkbox"> All
</label>
</div>
</div>
</div>
I am using Bootstrap3 in my project. I have enclosed my form in a jumbotron.
Here is how my form looks (not good looking as of now):
I tried to make it better. but it is getting worse. I want all the fields to be in one-line and
the submit button centered below them. I have no idea how to do it. I am very new using Bootstrap3.
Here is my html code:
<form action="" id="id-exampleForm" class="form-inline" method="post" >
<input type='hidden' name='csrfmiddlewaretoken' value='1bfhNFINdeJVpSNBBQd0X7zLWLVwm1bB' />
<div id="div_id_price_order" class="form-group">
<label for="id_price_order_0" class="control-label col-lg-2 requiredField">
price order
<span class="asteriskField">*</span>
</label>
<div class="controls col-lg-12">
<label class="radio">
<input type="radio" checked="checked" name="price_order" id="id_price_order_1" value="lowest_price" >lowest</label>
<label class="radio">
<input type="radio" name="price_order" id="id_price_order_2" value="highest_price" >highest</label>
</div>
</div>
<div class="form-group">
<div id="div_id_newest_entry" class="checkbox">
<div class="controls col-lg-offset-2 col-lg-12">
<label for="id_newest_entry" class=" requiredField">
<input class="checkboxinput checkbox" id="id_newest_entry" name="newest_entry" type="checkbox" />
latest date
</label>
</div>
</div>
</div>
<div class="form-group">
<div id="div_id_latest_year" class="checkbox">
<div class="controls col-lg-offset-2 col-lg-12">
<label for="id_latest_year" class=" requiredField">
<input class="checkboxinput checkbox" id="id_latest_year" name="latest_year" type="checkbox" />
latest year
</label>
</div>
</div>
</div>
<input type="submit" name="submit" value="Submit" class="btn btn-primary button white" id="submit-id-submit" />
</form>
EDIT:
I want something like this: I have edited this on powerpoint. so it does not look very good.
EDIT AFTER COMMENT
Please see the fiddle for an inline form in a Jumbotron with the button in-line (not below centered), and fieldset.
Note : that I changed the vertical alignment of the checkbox and radio + add some right margin, and an extra small button. The form will go as block if the screen is extra-small as a bootstrap behavior.
JsFiddle
<div class="jumbotron">
<form class="form-inline">
<fieldset class="radiogroup">
<legend>Sorting Criteria</legend>
<label for="id_price_order_0">
price order
<span class="asteriskField">*</span>
</label>
<label class="radio" for="id_price_order_1">
lowest
<input type="radio" checked="checked" id="id_price_order_1" />
</label>
<label class="radio" for="id_price_order_2">
highest
<input type="radio" id="id_price_order_2" />
</label>
<label for="id_newest_entry" class="requiredField checkbox">
latest date
<input id="id_newest_entry" type="checkbox" />
</label>
<label for="id_latest_year" class="requiredField checkbox">
latest year
<input id="id_latest_year" type="checkbox" />
</label>
<input type="submit" name="submit" value="Submit" class="btn btn-primary btn-xs" />
</fieldset>
</form>
Add the class form-control to ALL of your input elements for a start:
<input type="radio" class='form-control' checked="checked" name="price_order" id="id_price_order_1" value="lowest_price" >
Also, what I do to make my life easier is to pre-wrap the elements in the correct sized divs instead of doing it in the labels and inputs like so:
<div class='row'>
<form ... >
<div class='col-lg-2>
<label ... ></label>
<input ... >
</div>
<div class='col-lg-2'>
...
</div>
...
</form>
</div>
Its a tiny bit slower to load but it makes the code so much more readable I think it is worth it. Also I feel that there is a lot of extra in your code that shouldn't be there and is confusing check out the code here: http://getbootstrap.com/css/#forms. They show you exactly how to format an in-line form.
Could being inside a .jumbotron be causing the issues? Why don't you try a panel or a well This should work for you:
<div class='panel panel-default'>
<div class="panel-heading">In-line Form</div>
<div class="panel-body">
<form action='anotherScript.php' method='post' class='form-inline'>
<div class='row'>
<div class='col-md-4'>
<strong>Price:</strong>
<div class="radio-inline">
<label>
<input type="radio" name="rad1" value="low" checked>
Lowest
</label>
</div>
<div class="radio-inline">
<label>
<input type="radio" name="rad1" value="high">
Highest
</label>
</div>
</div>
<div class='col-md-4'>
<div class="checkbox-inline">
<label>
<input type="checkbox" name='date' value='date'>
Latest Date
</label>
</div>
</div>
<div class='col-md-4'>
<div class="checkbox-inline">
<label>
<input type="checkbox" name='year' value='year'>
Latest Year
</label>
</div>
</div>
</div>
<div class='row'>
<div class='col-md-12'>
<center><button type='submit' class='btn btn-primary'>Submit</button></center></form>
</div>
</div>
</div>
Fiddle: http://jsfiddle.net/52VtD/5046/
Make sure you stretch the results panel to full width to see the form in-line.
Is there anyway to get the text of a checkbox to be on the left side of the checkbox? I have tried and tried but cant get it working.
I'm using
<div class="col-xs-4 col-sm-3 col-md-2 col-md-offset-2 everything-checkbox">
<div class="checkbox">
<label>
<input type="checkbox" class="checkbox style-2 " checked="checked">
<span>Text goes here</span>
</label>
</div>
I have tried putting the span on top and that also doesn't work, Then if I make it a blank checkbox and just put text in front then they don't line up.
any help would be really appreciated.
Bootstrap styling will float the checkbox elements to the left because of this styling:
.radio input[type="radio"],
.radio-inline input[type="radio"],
.checkbox input[type="checkbox"],
.checkbox-inline input[type="checkbox"] {
float: left;
margin-left: -20px;
}
To solve this, you could simply add pull-right to the input element's class:
<input type="checkbox" id="checkbox1" class="checkbox style-2 pull-right" checked="checked"/>
It's also worth noting that a label element should have a for attribute matching the input element's id attribute, like this:
<div class="checkbox">
<label for="checkbox1">
<span>Text goes here</span>
</label>
<input type="checkbox" id="checkbox1" class="checkbox style-2 pull-right" checked="checked"/>
</div>
UPDATED EXAMPLE HERE
Using form-check-prepend in parent div
<form>
<div>
<div class="form-check-prepend">
<label class="form-input-label" for="checkbox1">
This is the label for the checkbox
</label>
<input
type="checkbox1"
class="form-check-input pull-right"
id="checkbox1"
/>
</div>
</div>
</form>
I'm currently using this on my website. I have not tested it across different devices and/or browsers. Comments welcome...
This should do it! JSFiddle
<div class="col-xs-4 col-sm-3 col-md-2 col-md-offset-2 everything-checkbox">
<div class="checkbox">
<label>
<span>Text goes here</span>
<input type="checkbox" class="checkbox style-2 " checked="checked">
</label>
</div>
How about this (note left-checkbox class):
<div class="form-group">
<div class="col-xs-4">
<div class="checkbox left-checkbox">
<label>
Text goes here
</label>
</div>
</div>
<div class="col-xs-8">
<div class="checkbox left-checkbox">
<input type="checkbox">
</div>
</div>
</div>
with css
.left-checkbox label {
text-align: right;
float: right;
font-weight: bold;
}
.left-checkbox input[type=checkbox] {
margin-left: 0;
}
Looks fine to me.
I am always looking for simple solutions first.
A KISS solution is:
<span style="white-space: nowrap;">Do Not Reverse Import
<label>
<input
type="checkbox"
name="DoNotReverseImport"
value="DoNotReverseImport"
OnChange = "OffYouGo('DoNotReverseImport');"
title = 'Check if old entries appear first in your import'
>
</label>
</span>
There are 2 things to correct to have Bootstrap 3 checkbox to the right of label text:
margin-left: -20px for checkbox
padding-left: 20px for label
Checkbox's size is 12.8px.
So our new values should be:
for checkbox: margin-left: 7.2px
for label: padding-right: 20px
Here is an example:
.checkbox.checkbox-left-label label,
.checkbox-inline.checkbox-left-label {
padding-left: unset;
padding-right: 20px;
}
.checkbox.checkbox-left-label input[type=checkbox],
.checkbox-inline.checkbox-left-label input[type=checkbox] {
margin-left: 7.2px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<h5>Checkboxes with labels on the left side:</h5>
<p>
<div class="checkbox checkbox-left-label">
<label>Option 1<input type="checkbox" value=""></label>
</div>
<div class="checkbox checkbox-left-label">
<label>Option 2<input type="checkbox" value=""></label>
</div>
<div class="checkbox checkbox-left-label disabled">
<label>Option 3<input type="checkbox" value="" disabled></label>
</div>
</p>
</div>
<div class="container">
<h5>Inline checkboxes with labels on the left side:</h5>
<p>
<label class="checkbox-inline checkbox-left-label">Option 1<input type="checkbox" value=""></label>
<label class="checkbox-inline checkbox-left-label">Option 2<input type="checkbox" value=""></label>
<label class="checkbox-inline checkbox-left-label disabled">Option 3<input type="checkbox" value="" disabled></label>
</p>
</div>
Wide space between label for vertical radio button and first choice. In an ideal world, I would love it to be the same amount of space as between the field labels and the top line on the fields. Any thoughts or ideas? Thanks in advance.
http://jsfiddle.net/steveadams617/MgcDU/8543/
<div class="container">
<form>
<div class="row">
<div class="col-sm-6">
<div class='form-group'>
<label for="provider_id">Provider</label>
<div>
<input class="form-control" type="text" maxlength="255" value="" name="provider_id_auto" id="provider_id_auto"/>
</div>
</div>
</div>
<div class="col-sm-3">
<div class='form-group'>
<label for='phone_us'>Phone</label>
<input class='form-control phone_us' type='text' maxlength='14' value='' name='phone_us' id='phone_us'/>
</div>
</div>
</div><!-- .row -->
<div class='row'>
<div class="col-sm-6">
<label for="med_coverage_id">Insurance Coverage</label>
<div class="radio">
<label>
<input type="radio" name="med_coverage_id" value="1" checked />
Pending
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="med_coverage_id" value="2" />
Covered
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="med_coverage_id" value="3" />
Needs Prior Approval
</label>
</div>
</div>
</div><!-- .row -->
</form>
</div><!-- .container -->
Your div .radio has a margin-top of 10px. You can manually adjust this like so
<div class="radio" style="margin-top: 0px;">
<label>
<input type="radio" name="med_coverage_id" value="1" checked="">Pending </label>
</div>
or of course edit the stylesheet or add your own style to the .radio-class (eg if you are using a CDN).