Bootstrap 3 buttons and input to be grouped in one row - html

I have a bunch of buttons and an input text box. But they are not aligned properly as shown.
<div class="col-md-12 pull-right">
<div class="pull-right">
<button type="button" class="btn btn-default btn-xs"> << </button>
<button type="button" class="btn btn-default btn-xs"> < </button>
<button type="button" class="btn btn-default btn-xs"> > </button>
<button type="button" class="btn btn-default btn-xs"> >> </button>
<input type="number" style="width: 30px; " class="form-control input-number" placeholder="84" maxlength="4" value="34" min="0" max="9999" autocomplete="off" pattern="\d4" />
</div>
</div>
Is there a way they are alligned in one row? Also notice that the size of the input box is looking different from the others. Is there a way to fix this too?

using btn-group arranges all buttons in a row. like this
<link href="http://getbootstrap.com/2.3.2/assets/css/bootstrap.css" rel="stylesheet" />
<div class="btn-group">
<button type="button" class="btn btn-default btn-xs"><<</button>
<button type="button" class="btn btn-default btn-xs"><</button>
<button type="button" class="btn btn-default btn-xs">></button>
<button type="button" class="btn btn-default btn-xs">>></button>
<input type="number" style="width: 30px; margin-top:10px" class="form-control input-number input-xs" placeholder="84" maxlength="4" value="34" min="0" max="9999" autocomplete="off" pattern="\d4" />
</div>
Note: When using HTML symbols(for example <,>) as text, then encode them as I did(Just a good practice).
Docs btn-groups
And I used inline style for input type number margin-top:10px; because input[type=number] in bootstrap has margin-bottom:10px; so, to balance used margin-top. Instead you can use margin-bottom:0px
As #Mike Robinson said, even .input-append does the same . the difference is rounded borders and input-append is converted to input-group from version 3
<link href="http://getbootstrap.com/2.3.2/assets/css/bootstrap.css" rel="stylesheet" />
<div class="input-append">
<button type="button" class="btn btn-default btn-xs"><<</button>
<button type="button" class="btn btn-default btn-xs"><</button>
<button type="button" class="btn btn-default btn-xs">></button>
<button type="button" class="btn btn-default btn-xs">>></button>
<input type="number" style="width: 30px; " class="form-control input-number input-xs" placeholder="84" maxlength="4" value="34" min="0" max="9999" autocomplete="off" pattern="\d4" />
</div>

You need an input-group. You can add on groups of buttons to either side of the input. Here they'll be on the left:
<div class="input-group">
<div class="input-group-btn">
<button type="button" class="btn btn-default"> << </button>
<button type="button" class="btn btn-default"> < </button>
<button type="button" class="btn btn-default"> > </button>
<button type="button" class="btn btn-default"> >> </button>
</div>
<input type="number" style="width: 30px; " class="form-control input-number" placeholder="84" maxlength="4" value="34" min="0" max="9999" autocomplete="off" pattern="\d4" />
</div>
Read more about it here:
http://getbootstrap.com/components/#input-groups-buttons-multiple

The form-control style on your input is the thing that's moving it to the next line. It's doing so because the form-control style in bootstrap is set to display: block. By adding a new style or doing an inline style you can get them on the same page.
For instance:
<input type="number" style="width: 30px; " class="form-control input-number" placeholder="84" maxlength="4" value="34" min="0" max="9999" autocomplete="off" pattern="\d4" style="display: initial;" />
Or you can make a class such as:
.newInputControl{
display: inline;
}
<input type="number" style="width: 30px; " class="form-control input-number" placeholder="84" maxlength="4" value="34" min="0" max="9999" autocomplete="off" pattern="\d4" class="newInputControl" />
You can also take care of it using bootstrap, which has built the framework to handle this by placing your form-control inside an input group.

use:
form-control-static instead of form-control in your input text

Related

Align input buttons next to textarea in css

I have the above sample html but the button are being placed one line below the textarea. How do ensure that the buttons are placed next to the textarea (on the right side of textarea) but not below?
<div id="txtArea" style="width:1000px;">
<textarea style="margin-left:20px;" class="span1 form-control" rows="6" ></textarea>
</div>
<div id="buttons">
<input id="btnApprove" type="button"name="action" value="Create Profile" onclick="return validateCreateStaffProfile()" class="btn btn-default btn-sm_Custom active" />
<input id="btnReject" type="button" style="margin-left: 30px;" class="btn btn-default btn-sm_Custom active" value="Clear" onclick="return ClearStaffProfileActionDiv();" />
<input id="btnDelete" type="button" name="action" value="Create Profile" onclick="return validateCreateStaffProfile()" class="btn btn-default btn-sm_Custom active" />
</div>
You can use inline-block property
#txtArea,#buttons{
display:inline-block;
vertical-align: top;
}
<div id="txtArea" >
<textarea style="margin-left:20px;" class="span1 form-control" rows="6" ></textarea>
</div>
<div id="buttons">
<input id="btnApprove" type="button"name="action" value="Create Profile" onclick="return validateCreateStaffProfile()" class="btn btn-default btn-sm_Custom active" />
<input id="btnReject" type="button" style="margin-left: 30px;" class="btn btn-default btn-sm_Custom active" value="Clear" onclick="return ClearStaffProfileActionDiv();" />
<input id="btnDelete" type="button" name="action" value="Create Profile" onclick="return validateCreateStaffProfile()" class="btn btn-default btn-sm_Custom active" />
</div>
You need to remove the style width: 1000px and wrap the content into a div with display: inline-flex.
.content {
display: inline-flex;
}
<div class="content">
<div id="txtArea" >
<textarea style="margin-left:20px;" class="span1 form-control" rows="6" >
</textarea>
</div>
<div id="buttons">
<input id="btnApprove" type="button"name="action" value="Create Profile" onclick="return validateCreateStaffProfile()" class="btn btn-default btn-sm_Custom active" />
<input id="btnReject" type="button" style="margin-left: 30px;" class="btn btn-default btn-sm_Custom active" value="Clear" onclick="return ClearStaffProfileActionDiv();" />
<input id="btnDelete" type="button" name="action" value="Create Profile" onclick="return validateCreateStaffProfile()" class="btn btn-default btn-sm_Custom active" />
</div>
</div>
If you're using bootstrap why not just column them?
<div class="container">
<form action="">
<div class="col-lg-9">
<div class="row">
<textarea name="" class="form-control" id=""rows="10"></textarea>
</div>
</div>
<div class="col-lg-3">
<input type="submit" class="btn btn-primary" onclick="return validateCreateStaffProfile()" value="Create Profile">
<input type="submit" class="btn btn-primary" value="Clear">
<input type="submit" class="btn btn-primary" onclick="return validateCreateStaffProfile()" value="Create Profile">
</div>
</form>
</div>
This will align the buttons to the right of the texarea and side by side.

Bootstrap add-on on buttons

I am an bit new to Bootstrap but I can't ind it anywhere on the manual how to give the add on in the last line (where the txt is 'cm') the dimensions as the previous 3 lines.
<!-- width right -->
<div id="div_widthRight" class="form-group has-warning">
<label for="widthRight" class="col-sm-3 control-label">Breedte rechts</label>
<div class="col-sm-9">
<div class="input-group">
<input type="number" class="form-control" id="widthRight" name="width_right" min="20" max="252" value="" data-preview="preview_hl_right" onkeyup="validate()" onclick="validate()">
<span class="input-group-addon">cm</span>
</div>
</div>
</div>
<!-- height -->
<div id="div_height" class="form-group has-warning">
<label for="height" class="col-sm-3 control-label">Hoogte</label>
<div class="col-sm-9">
<div class="btn-group">
<button type="button" class="btn btn-default" id="height_1" name="height" value="1" data-preview="preview_hl_height" onclick="validate_but(this);validate()">14,5</button>
<button type="button" class="btn btn-default" id="height_2" name="height" value="2" data-preview="preview_hl_height" onclick="validate_but(this);validate()">29,0</button>
<button type="button" class="btn btn-default" id="height_3" name="height" value="3" data-preview="preview_hl_height" onclick="validate_but(this);validate()">43,5</button>
<button type="button" class="btn btn-default" id="height_4" name="height" value="4" data-preview="preview_hl_height" onclick="validate_but(this);validate()">58,0</button>
<span class="input-group-addon">cm</span>
</div>
</div>
</div>
Or is it because I am using different classes? But to get this aligned correct?
This is what I am trying to get.
When adding the input-group class to btn-group.
Width 0 on the input-group-addon. I have this result:
When only adding Width 0 on the input-group-addon.
I have edited my answer since my first answer did not work properly in all resolutions. I think this is one way to achieve what you want. I have changed some of your bootstrap classes.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div id="div_height" class="form-group has-warning">
<label for="height" class="col-sm-3 control-label">Hoogte</label>
<div class="col-sm-9">
<div class="input-group-btn">
<span class="input-group-btn">
<button type="button" class="btn btn-default" id="height_1" name="height" value="1" data-preview="preview_hl_height" onclick="validate_but(this);validate()">14,5</button>
<button type="button" class="btn btn-default" id="height_2" name="height" value="2" data-preview="preview_hl_height" onclick="validate_but(this);validate()">29,0</button>
<button type="button" class="btn btn-default" id="height_3" name="height" value="3" data-preview="preview_hl_height" onclick="validate_but(this);validate()">43,5</button>
<button type="button" class="btn btn-default" id="height_4" name="height" value="4" data-preview="preview_hl_height" onclick="validate_but(this);validate()">58,0</button>
</span>
<span class="input-group-addon">cm</span>
</div>
</div>
</div>

Bootstrap radio buttons

I have 3 different sets of radio buttons on the same page. The problem I am experiencing with them is that when a button in another btn-group is pressed it will toggle the state of the buttons in the previous or next btn-group. They don't seem to be independent. Here's the code:
<div id="file1" class="btn-group" data-toggle="buttons-radio" >
<button class="btn btn-primary" type="radio" name="radioGroup2" value="yes">Yes</button>
<button class="btn btn-danger" type="radio" name="radioGroup2"onClick="$('#mandatory1').val('no');">No</button>
</div>
<div id="file2" class="btn-group" data-toggle="buttons-radio" >
<button class="btn btn-primary" type="radio" name="radioGroup" value="yes">Yes</button>
<button class="btn btn-danger" type="radio" name="radioGroup" onClick="$('#mandatory2').val('no');">No</button>
</div>
When a button within div file1 is clicked it toggles the state of a button in div id file2
I've tried using button.js with this, but no luck.
I've tried various different variations of data-toggle="button"
Any ideas?
Demo
Your HTML structure for bootstrap radio buttons is wrong.
<div id="file1" class="btn-group" data-toggle="buttons" >
<label class="btn btn-primary">
<input type="radio" name="option1" /> Yes
</label>
<label class="btn btn-danger">
<input type="radio" name="option1" /> No
</label>
</div>
<div id="file2" class="btn-group" data-toggle="buttons" >
<label class="btn btn-primary">
<input type="radio" name="option2" /> Yes
</label>
<label class="btn btn-danger">
<input type="radio" name="option2" /> No
</label>
</div>
Aside:
You're using jQuery; Please don't use onClick in your HTML. You would set up those events like this (though there is a way that involves less code).
$(function(){
$('.btn').button(); // this is for the radio buttons.
// this replaces your inline JS
$('#file1 .btn-danger').on('click', function(){
$('#mandatory1').val('no');
});
$('#file2 .btn-danger').on('click', function(){
$('#mandatory2').val('no');
});
});
Demo
this should fix your problem:
<div id="file1" class="btn-group" data-toggle="buttons">
<label class="btn btn-primary active"><input type="radio" name="radioGroup2" value="yes">Yes</label>
<label class="btn btn-danger"><input type="radio" name="radioGroup2" onclick="$('#mandatory1').val('no');">No</label>
</div>
<div id="file2" class="btn-group" data-toggle="buttons">
<label class="btn btn-primary"><input type="radio" name="radioGroup" value="yes">Yes</label>
<label class="btn btn-danger active"><input type="radio" name="radioGroup" onclick="$('#mandatory2').val('no');">No</label>
</div>

Display elements inline

I was wondering if you could help.
I am looking for an easy way to display the circled elements in this picture https://db.tt/w5doYPNZ horizontally.
I have tried:
.calculator {
display: inline-block;
}
However that doesn't seem to make any difference. I have added the HTML for reference.
Thanks in advance :D
<div class="calculator">
<div class="input-group input-small">
<h4>Adult (12+)</h4>
<button class="btn theme-btn" id="decrease" value="Decrease Value">-</button>
<input type="text" id="adult" value="1" class="form-control input-usmall" min="0">
<button class="btn theme-btn" id="increase" value="Increase Value">+</button>
<h4>Child (2-11)</h4>
<button class="btn theme-btn" id="decreasec" value="Decrease Value">-</button>
<input type="text" id="child" value="0" class="form-control input-usmall" min="0" >
<button class="btn theme-btn" id="increasec" value="Increase Value">+</button>
<p>£</p><p id="total"></p><p>.00</p><button class="btn green" onclick="myFunction()">Calculate</button>
</div>
</div>
Put this stuff in it's own div:
<h4>Adult (12+)</h4>
<button class="btn theme-btn" id="decrease" value="Decrease Value">-</button>
<input type="text" id="adult" value="1" class="form-control input-usmall" min="0">
<button class="btn theme-btn" id="increase" value="Increase Value">+</button>
Then put this stuff it it's own div:
<h4>Child (2-11)</h4>
<button class="btn theme-btn" id="decreasec" value="Decrease Value">-</button>
<input type="text" id="child" value="0" class="form-control input-usmall" min="0" >
<button class="btn theme-btn" id="increasec" value="Increase Value">+</button>
Then this stuff in it's own div:
<p>£</p><p id="total"></p>
<p>.00</p>
<button class="btn green" onclick="myFunction()">Calculate</button>
Then float each of those divs. I would make the three newly created divs all live in the same parent div. Also, I would avoid display: inline-block, as it has issues in older browsers. Just float, and you get the same effect.
Here's a codepen with a working model.
The elements you're trying to affect with display: inline-block won't inherit that behavior from the .calculator parent element. You need to target them directly.
There's a lot I would change about your class naming and choice of elements, but at minimum, you need to create a separate class for calculator components, break the calculator structure into said components, and you need to convert your paragraphs to spans:
HTML:
<div class="calculator">
<div class="calculator-submodule input-group input-small">
<h4>Adult (12+)</h4>
<button class="btn theme-btn" id="decrease" value="Decrease Value">-</button>
<input type="text" id="adult" value="1" class="form-control input-usmall" min="0">
<button class="btn theme-btn" id="increase" value="Increase Value">+</button>
</div>
<div class="calculator-submodule input-group input-small">
<h4>Child (2-11)</h4>
<button class="btn theme-btn" id="decreasec" value="Decrease Value">-</button>
<input type="text" id="child" value="0" class="form-control input-usmall" min="0" >
<button class="btn theme-btn" id="increasec" value="Increase Value">+</button>
</div>
<div class="calculator-submodule">
<span>£</span>
<span id="total"></span><span>.00</span><button class="btn green" onclick="myFunction()">Calculate</button>
</div>
</div>
CSS:
.calculator-submodule {
display: inline-block;
padding-left: 1em;
text-align: center;
}
Try this :
.input-group.input-small {
display: inline-block;
}
With this :
<div class="calculator">
<div class="input-group input-small">
<h4>Adult (12+)</h4>
<button class="btn theme-btn" id="decrease" value="Decrease Value">-</button>
<input type="text" id="adult" value="1" class="form-control input-usmall" min="0">
<button class="btn theme-btn" id="increase" value="Increase Value">+</button>
</div>
<div class="input-group input-small">
<h4>Child (2-11)</h4>
<button class="btn theme-btn" id="decreasec" value="Decrease Value">-</button>
<input type="text" id="child" value="0" class="form-control input-usmall" min="0" >
<button class="btn theme-btn" id="increasec" value="Increase Value">+</button>
<p>£</p><p id="total"></p><p>.00</p><button class="btn green" onclick="myFunction()">Calculate</button>
</div>
</div>

Bootstrap 3 Button Groups

**Bootstrap 3
I'm trying to make each set of button group unique but the different groups are interfering with each other
<label>Payment Mode</label>
<div class="btn-group">
<button type="button" class="btn btn-default">Cash / Cheque / Bank Transfer </button>
<button type="button" class="btn btn-default">JobsBuddy Disbursement</button>
</div>
<label>Payment Period</label>
<div class="btn-group">
<button type="button" class="btn btn-default">Immediate</button>
<button type="button" class="btn btn-default"> More Than 1 day</button>
</div>
How do i keep it unique in it's own group
You may want to use the Bootstrap provided radio button groups (http://getbootstrap.com/javascript/#buttons), and then use the reset method to clear the other group..
HTML:
<label>Payment Mode</label>
<div id="mode-group" class="btn-group" data-toggle="buttons">
<label class="btn btn-primary">
<input type="radio" name="mode" id="option1"> Cash / Cheque / Bank Transfer
</label>
<label class="btn btn-primary">
<input type="radio" name="mode" id="option2"> JobsBuddy Disbursement
</label>
</div>
<label>Payment Period</label>
<div id="period-group" class="btn-group" data-toggle="buttons">
<label class="btn btn-primary">
<input type="radio" name="period" id="period1"> Immediate
</label>
<label class="btn btn-primary">
<input type="radio" name="period" id="period2"> More Than 1 day
</label>
</div>
jQuery:
// unselect period when mode is selected
$("#mode-group .btn").on('click',function(){
$("#period-group").button('reset');
});
Demo: http://bootply.com/86422
Click the button in the btn-group doesn't set a (active) class. The button gets a different background-color cause it is focussed (:focus). Clicking a button in a different btn-group sets the focus to this button.
Use something like this to set an active class per btn-group:
$('.btn-group button').click(function()
{
$(this).parent().children().removeClass('active');
$(this).addClass('active');
});
If you are using AngularJS the Angular UI bootstrap has a great solution.
Basically do the following using the btnRadio directive.
<div class="btn-group">
<label class="btn btn-primary" ng-model="radioModel" btn-radio="'Left'">Left</label>
<label class="btn btn-primary" ng-model="radioModel" btn-radio="'Middle'">Middle</label>
<label class="btn btn-primary" ng-model="radioModel" btn-radio="'Right'">Right</label>
</div>
To keep unique button just don't use class="btn-group":
<label>Payment Mode</label>
<div>
<button type="button" class="btn btn-default">Cash / Cheque / Bank Transfer </button>
<button type="button" class="btn btn-default">JobsBuddy Disbursement</button>
</div>
<label>Payment Period</label>
<div>
<button type="button" class="btn btn-default">Immediate</button>
<button type="button" class="btn btn-default"> More Than 1 day</button>
</div>
This class is used for series of buttons. Check documentation of Buttons Group
Just to simplify it for the next person to come looking, here's the solution code from the Bootstrap website:
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-primary active">
<input type="radio" name="options" id="option1" autocomplete="off" checked> Radio 1 (preselected)
</label>
<label class="btn btn-primary">
<input type="radio" name="options" id="option2" autocomplete="off"> Radio 2
</label>
<label class="btn btn-primary">
<input type="radio" name="options" id="option3" autocomplete="off"> Radio 3
</label>
</div>
Basically, you style the labels as buttons and code the options as regular radio buttons to separate one set of options from the other.