bootstrap btn group not working - html

When I try class="btn-group" the buttons aren't joined anymore. They are separate.
<div class="btn-group btn-group-xs">
<form action="{{ route('requisitions.update' , ['id' => $requisition->id]) }}" method="post">
{{ method_field('PATCH') }}
{{ csrf_field() }}
<button type="submit" class="btn btn-success btn-xs">Confirmation</button>
</form>
<form action="{{ route('requisitions.destroy' , ['id' => $requisition->id]) }}" method="post">
{{ method_field('PATCH') }}
{{ csrf_field() }}
<button type="submit" class="btn btn-danger btn-xs">Disapproval</button>
</form>
</div>

You should follow the standard way as bootstrap
https://getbootstrap.com/docs/4.1/components/button-group/
try to wrap this code some thing like this in a div having class "btn-toolbar"
<div class="btn-toolbar" role="toolbar" aria-label="Toolbar with button groups">
<div class="btn-group btn-group-xs" role="group">
<form method="post">
<button type="submit" class="btn btn-success btn-xs">Confirmation</button>
</form>
<form method="post">
<button type="submit" class="btn btn-danger btn-xs">Disapproval</button>
</form>
</div>
</div>
Example#2
<div class="btn-toolbar" role="toolbar" aria-label="Toolbar with button groups">
<div class="btn-group mr-2" role="group" aria-label="First group">
<button type="button" class="btn btn-secondary">1</button>
<button type="button" class="btn btn-secondary">2</button>
<button type="button" class="btn btn-secondary">3</button>
<button type="button" class="btn btn-secondary">4</button>
</div>
</div>

Related

Align button groups some to the left and some to the right

How can I align button groups, 3 buttons to the left and another 3 buttons to the right with an input field in the middle in a div.
<div class="container">
<div>
<div class="button-group">
<button type="button" class="btn btn-secondary"></button>
<button type="button" class="btn btn-secondary"></button>
<button type="button" class="btn btn-secondary"></button>
</div>
</div>
<div>
<input type="text" name="textfield" value="">
</div>
<div>
<div class="button-group">
<button type="button" class="btn btn-secondary"></button>
<button type="button" class="btn btn-secondary"></button>
<button type="button" class="btn btn-secondary"></button>
</div>
</div>
</div>
Before:
before applying your answer
after applying
This is how I want to arrange them
Flexbox solves your requirement. Learn more here
.container{
display: flex;
align-items: center;
justify-content: space-around;
}
.button-group{
display:flex;
}
<div class="container">
<div>
<div class="button-group">
<button type="button" class="btn btn-secondary"></button>
<button type="button" class="btn btn-secondary"></button>
<button type="button" class="btn btn-secondary"></button>
</div>
</div>
<div>
<input type="text" name="textfield" value="">
</div>
<div>
<div class="button-group">
<button type="button" class="btn btn-secondary"></button>
<button type="button" class="btn btn-secondary"></button>
<button type="button" class="btn btn-secondary"></button>
</div>
</div>
</div>
Like this?
.center{
text-align: center;
}
.right{
text-align: right;
}
<div class="container">
<div>
<div class="button-group">
<button type="button" class="btn btn-secondary"></button>
<button type="button" class="btn btn-secondary"></button>
<button type="button" class="btn btn-secondary"></button>
</div>
</div>
<div class="center">
<input type="text" name="textfield" value="">
</div>
<div>
<div class="button-group right">
<button type="button" class="btn btn-secondary"></button>
<button type="button" class="btn btn-secondary"></button>
<button type="button" class="btn btn-secondary"></button>
</div>
</div>
</div>
Or do you mean like this?
Source: (Making a flex item float right)
.button-container{
display: flex;
}
.right{
margin-left: auto;
}
.center{
text-align: center;
}
<div class="container">
<div class="button-container">
<div class="button-group left">
<button type="button" class="btn btn-secondary"></button>
<button type="button" class="btn btn-secondary"></button>
<button type="button" class="btn btn-secondary"></button>
</div>
<div class="button-group right">
<button type="button" class="btn btn-secondary"></button>
<button type="button" class="btn btn-secondary"></button>
<button type="button" class="btn btn-secondary"></button>
</div>
</div>
<div class="center">
<input type="text" name="textfield" value="">
</div>
</div>

Bootstrap5 input-group with btn-group-vertical

As title, I want to create a input-group for number increase/decrease.
This is my code:
<div class="input-group input-group-sm">
<input type="text" class="form-control" placeholder="0.9">
<div class="btn-group-vertical">
<button class="btn btn-primary btn-sm" type="button">+</button>
<button class="btn btn-primary btn-sm" type="button">-</button>
</div>
</div>
Result
Expected result
You need to add py-0 for remove top & bottom padding and lh-1 for decrease line height of button. Your code should be as below:
<div class="input-group input-group-sm">
<input type="text" class="form-control" placeholder="0.9">
<div class="btn-group-vertical">
<button class="btn btn-primary btn-sm py-0 lh-1" type="button">+</button>
<button class="btn btn-primary btn-sm py-0 lh-1" type="button">-</button>
</div>
</div>
add p-0 in button so the code will like this :
<div class="input-group input-group-sm">
<input type="text" class="form-control" placeholder="0.9">
<div class="btn-group-vertical">
<button class="btn btn-primary btn-sm p-0" type="button">+</button>
<button class="btn btn-primary btn-sm p-0" type="button">-</button>
</div>
</div>

Active button always active in each division

Here is my sample form HTML code. In further, I need when click the button in each section the button stays active and it shows red color background. on the other hand, inactive buttons change the grey background color. For example when we click the "print foil thickness" label button 3 then it will active
button 3 and remains 4,5,6,7,8, Best Fit buttons are disabled.
<form id="msform">
<fieldset>
<div class="form-card">
<label class="label-order">Order Set Required:</label>
<div class="btn-group" role="group" aria-label="Kit">
<button type="button" class="btn btn-secondary">Replacement Set</button>
<button type="button" class="btn btn-secondary">Complete Set</button>
</div>
<label class="label-order">Print Foil Thickness:</label>
<div class="btn-toolbar" role="toolbar" aria-label="Toolbar with button groups">
<div class="btn-group mr-2" role="group" aria-label="First group">
<button type="button" class="btn btn-secondary">3</button>
<button type="button" class="btn btn-secondary">4</button>
<button type="button" class="btn btn-secondary">5</button>
<button type="button" class="btn btn-secondary">6</button>
<button type="button" class="btn btn-secondary">7</button>
<button type="button" class="btn btn-secondary">8</button>
<button type="button" class="btn btn-secondary">Best Fit</button>
</div>
</div>
<label class="label-order">Print Foil Opening (in mils):</label>
<div class="btn-toolbar" role="toolbar" aria-label="Toolbar with button groups">
<div class="btn-group mr-2" role="group" aria-label="First group">
<button type="button" class="btn btn-secondary">3</button>
<button type="button" class="btn btn-secondary">4</button>
<button type="button" class="btn btn-secondary">5</button>
<button type="button" class="btn btn-secondary">6</button>
<button type="button" class="btn btn-secondary">7</button>
<button type="button" class="btn btn-secondary">8</button>
<button type="button" class="btn btn-secondary">Best Fit</button>
</div>
</div>
<label class="label-order">Sphere Diameter To Be Used (in mils):</label>
<div class="btn-toolbar" role="toolbar" aria-label="Toolbar with button groups">
<div class="btn-group mr-2" role="group" aria-label="First group">
<button type="button" class="btn btn-secondary">3</button>
<button type="button" class="btn btn-secondary">4</button>
<button type="button" class="btn btn-secondary">5</button>
<button type="button" class="btn btn-secondary">6</button>
<button type="button" class="btn btn-secondary">7</button>
<button type="button" class="btn btn-secondary">8</button>
<button type="button" class="btn btn-secondary">Best Fit</button>
</div>
</div>
</div>
</fieldset>
</form>

Label smaller than button in Bootstrap button group

I found some come to make a button that is also an input file with a label :
<label>
Import
<input type="file" hidden>
</label>
So I put in on the toolbar on my project where I'm using a button group :
<div class="btn-toolbar" role="toolbar">
<div class="btn-group mr-2" role="group">
<button class="btn btn-primary" (click)="newNetwork()">New network</button>
<label class="btn btn-primary">
Import
<input type="file" (change)="import($event.target.files)" hidden>
</label>
<button class="btn btn-primary" (click)="export()">Export</button>
</div>
<div class="btn-group mr-2" role="group">
<button class="btn btn-primary" (click)="addElement('station')">Add station</button>
<button class="btn btn-primary" (click)="addElement('shed')">Add shed</button>
<button class="btn btn-primary" (click)="addElement('bridge')">Add bridge</button>
</div>
<div class="btn-group" role="group">
<button class="btn"
[ngClass]="{'btn-primary': !linking, 'btn-warning': linking}"
(click)="link()">
Add link
</button>
<button class="btn"
[ngClass]="{'btn-primary': !editing, 'btn-warning': editing}"
(click)="edit()">
Edit
</button>
<button class="btn"
[ngClass]="{'btn-primary': !removing, 'btn-warning': removing}"
(click)="remove()">
Remove
</button>
</div>
</div>
The thing the label is actually a bit shorter than other buttons.
I tried to fix it's height :
<label style="height: 101%" class="btn btn-primary">
It works but now the text isn't vertically centered !
Is there a way to make it look like a normal button ?
You can remove the margin of that label like this:
(I would not recommend inline css).
.export {
margin: 0px;
}
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
</head>
<div class="btn-toolbar" role="toolbar">
<div class="btn-group mr-2" role="group">
<button class="btn btn-primary" (click)="newNetwork()">New network</button>
<label class="btn btn-primary export">
Import
<input type="file" (change)="import($event.target.files)" hidden>
</label>
<button class="btn btn-primary " (click)="export()">Export</button>
</div>
<div class="btn-group mr-2" role="group">
<button class="btn btn-primary" (click)="addElement('station')">Add station</button>
<button class="btn btn-primary" (click)="addElement('shed')">Add shed</button>
<button class="btn btn-primary" (click)="addElement('bridge')">Add bridge</button>
</div>
<div class="btn-group" role="group">
<button class="btn"
[ngClass]="{'btn-primary': !linking, 'btn-warning': linking}"
(click)="link()">
Add link
</button>
<button class="btn"
[ngClass]="{'btn-primary': !editing, 'btn-warning': editing}"
(click)="edit()">
Edit
</button>
<button class="btn"
[ngClass]="{'btn-primary': !removing, 'btn-warning': removing}"
(click)="remove()">
Remove
</button>
</div>
</div>

Twitter Bootstrap button-group as text input add-on isn't so nice

This is what I've tried:
<div class="input-prepend input-append">
<input type="text" />
<div class="add-on btn-group" data-toggle="buttons-radio">
<button type="button" class="btn btn-primary" dir="ltr">http://</button>
<button type="button" class="btn btn-primary" dir="ltr">https://</button>
</div>
</div>
but the group-button's padding and margin made it ugly! you can see it in jsFiddle
How can I fix it?
Remove add-on from class="add-on btn-group"
Try changing your code to this:
<div class="input-prepend input-append">
<div class="btn-group" data-toggle="buttons-radio">
<button type="button" class="btn btn-primary" dir="ltr">http://</button>
<button type="button" class="btn btn-primary" dir="ltr">https://</button>
<input type="text" />
</div>
:)