button group and textbox in middle in bootstrap - css

I am creating pager using bootstrap as given below using input-group.
+──+─+───+──+─+──+
│<<│<│ 1 │GO│>│>>│
+──+─+───+──+─+──+
but it moves the part after textbox on right side.
Sample code is I have added at
https://jsfiddle.net/386my76a/
Would there be any bootstrap's inbuilt solution or I need to fix it adding custom CSS (ex: float left for 2nd part)?

What you can do is to set the minimal width of entire input-group (like width: 1%;) and wrap input field into .input-group-btn class:
#import url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css');
#import url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css');
body {margin: 10px;}
.pagination {width: 1%;}
<div class="container">
<div class="input-group pagination">
<div class="input-group-btn">
<button class="btn btn-default" type="button"><<</button>
<button class="btn btn-default" type="button"><</button>
</div>
<div class="input-group-btn">
<input class="form-control" type="text" style="width: 50px;" value="2">
</div>
<div class="input-group-btn">
<button class="btn btn-primary" type="button">Go</button>
<button class="btn btn-default" type="button">></button>
<button class="btn btn-default" type="button">>></button>
</div>
</div>
</div>

Bootstrap do have their own pagination class and you can directly use it to make your pagination.
<ul class="pagination">
<li class="disabled">«</li>
<li class="active">1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>»</li>
</ul>
You can check out this link here and it shows how it works:
http://www.tutorialrepublic.com/codelab.php?topic=bootstrap&file=pagination-with-disabled-and-active-state-01
Hope it helps.

Related

Align two buttons (one of them in a form) in a table cell in Bootstrap 4

I'm using Bootstrap 4 and I want to align two buttons inside a table column. The buttons are of the same size, but the second one is inside of a form.
I tried using the button group approach which almost solves the situation, but unfortunately there's a small gap between the buttons:
<td class="text-right">
<div class="btn-group" role="group">
<button type="button" class="btn btn-sm btn-secondary">Edit</button>
<form action="" method="POST">
<button type="button" class="btn btn-sm btn-danger">Delete</button>
</form>
</div>
</td>
What utility class can I use or any additional css in order to have the buttons aligned on the same level?
P.S. It doesn't have to be the button group, it can be any other technique as long as the buttons are on the same line.
Following the same strategy used to align columns in the bootstrap, its td can be of the row class, surrounded by items in the class col-md , col-lg, col-sm.
Try this:
HTML
<td class="text-right row">
<div class="btn-group" role="group">
<div class="col-md-6 custom">
<button type="button" class="btn btn-sm btn-secondary">Edit</button>
</div>
<div class="col-md-6 custom">
<form action="" method="POST">
<button type="button" class="btn btn-sm btn-danger">Delete</button>
</form>
</div>
</div>
</td>
Customize your column with a custom CSS
CSS
.custom {
padding-right: 5px;
padding-left: 5px;
}
https://jsfiddle.net/braulioti/aq9Laaew/160600/

Spacing between Bootstrap buttons

How do I make sure that there is spacing between the buttons when i use the following piece of code
<div class="container">
<div class="jumbotron">
<button ng-repeat="char in alphabet" ng-click="filterByAlphabet(char)">{{char}}</button>
<br><br>
<span ng-repeat="genre in genres">
<button class="btn btn-xs" ng-click="filterByGenre(genre)">{{genre}}</button>
</span>
</div>
'btn-toolbar' does the trick in one fell swoop. No manual css'ing required
<div class="btn-toolbar">
<button id="button1" class="btn btn-primary">Button 1</button>
<button id="button2" class="btn btn-primary">Button 2</button>
<button id="button3" class="btn btn-primary">Button 3</button>
</div>
You can use Bootstrap spacing, docs here --> https://getbootstrap.com/docs/4.0/utilities/spacing/
This example uses the class 'mr-2' to add right margins to buttons
<button id="button1" class="btn btn-primary mr-2">Button 1</button>
<button id="button2" class="btn btn-primary mr-2">Button 2</button>
<button id="button3" class="btn btn-primary">Button 3</button>
Use css property margin
button { margin: 5px 5px 5px 5px } //change the value to see the effect and choose for yourself which value to keep
margin: margin-top margin-right margin-bottom margin-left ;
Set right margin on buttons:
<div class="container">
<div class="jumbotron">
<button ng-repeat="char in alphabet" ng-click="filterByAlphabet(char)" style="margin-right: 10px;">{{char}}</button>
<br><br>
<span ng-repeat="genre in genres">
<button class="btn btn-xs" ng-click="filterByGenre(genre)" style="margin-right: 10px;">{{genre}}</button>
</span>
</div>
Hope, this is what you're looking for.
.capsule{
padding: 0 30px;
}
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<div class="container">
<div class="jumbotron">
<span class="col-xs-4"> </span>
<span class="capsule col-xs-2">
<button ng-repeat="char in alphabet" ng-click="filterByAlphabet(char)">{{char}}</button>
</span>
<span class="capsule col-xs-2" ng-repeat="genre in genres">
<button class="btn btn-xs" ng-click="filterByGenre(genre)">{{genre}}</button>
</span>
</div>
i added one empty span to center the jumbo in the screen, also added "capsule" span to get space between the buttons.
Hope it helps!

hidden-xs class in btn-group make a line break

all btn's - in a line (http://bootply.com/100575)
when I add hidden-xs into btn-group, it make new line break. (http://bootply.com/100574)
I changed codes but I can not find how to make btn's in a line with hidden-xs.
<div class="btn-group">
<a class="btn btn-default" href="./board.php?bo_table=qna&page=1"><i class="fa fa-list"></i>List</a>
</div>
<div class="btn-group">
<a class="btn btn-default" href="./write.php?bo_table=qna"><i class="fa fa-edit"></i>Write</a>
</div>
<div class="btn-group hidden-xs"> <!-- here... -->
<a class="btn btn-default" href="javascript:select_delete();">Delete</a>
<a class="btn btn-default" href="javascript:select_copy('copy');">Copy</a>
<a class="btn btn-default" href="javascript:select_copy('move');">Move</a>
</div>
The default styling of .hidden-xs is:
.hidden-xs {
display: block!important;
}
Changing it to display:inline-block will solve this.
.hidden-xs {
display: inline-block!important;
}
In this instance, usage of !important would be necessary since you are having to overwrite the initial declaration which uses !important. Alternately just change the bootstrap CSS to inline-block and avoid having to overwrite it.

Select "arrow" hidden in bootstrap 3 input group in IE9

I have the following html styled by bootstrap 3 that defines a group of inputs:
<div class="input-group">
<select class="form-control" >Some options here</select>
<a class="btn btn-default input-group-addon disabled" title="Legg til" disabled="" href="#" ><i class="glyphicon glyphicon-plus-sign"></i></a>
</div>
This gives the following result in most browsers (including IE10):
However in IE9, the "arrow" for the dropdown is missing:
Anyone know a fix for this in IE9?
I found the issue here. It seems that the arrow button is simply hidden below the button with the plus icon. So the select box is the entire width, and the other buttons end up overlying it.
So the fix was to add float:left to the select box, and voila!
You should use .input-group-btn to avoid this issue :
<div class="container">
<form role="form">
<div class="form-group">
<div class="input-group">
<select class="form-control">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
<span class="input-group-btn">
<a class="btn btn-default" href="#"><i class="glyphicon glyphicon-plus-sign"></i></a>
</span>
</div>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
You just need to remove padding on the select tag. You'll first need conditional classes for IE9.
<!--[if IE 9 ]><html class="ie9"><![endif]-->
Then just simply remove the padding on the select tags.
.ie9{
select.form-control{
padding: 0 !important;
}
}

Set a button group's width to 100% and make buttons equal width?

I'm using Bootstrap, and I'd like to set an entire btn-group to have a width of 100% of its parent element. I'd also like the inner buttons to take equal widths. As it is, I can't achieve either.
I've made a JSFiddle here: http://jsfiddle.net/BcQZR/12/
Here is the HTML:
<div class="span8 background">
<div class="btn-group btn-block" id="colours">
<span class="btn"><input type='checkbox' name='size' value='red'/>red</span>
<span class="btn"><input type='checkbox' name='size' value='orange'/>orange</span>
<span class="btn"><input type='checkbox' name='size' value='yellow'/>yellow</span>
</div> <!-- /btn-group -->
</div>
And here is my current CSS, which doesn't work:
#colours {
width: 100%;
}
Bootstrap has the .btn-group-justified css class.
How it's structured is based on the type of tags you use.
With <a> tags
<div class="btn-group btn-group-justified" role="group" aria-label="...">
...
</div>
With <button> tags
<div class="btn-group btn-group-justified" role="group" aria-label="...">
<div class="btn-group" role="group">
<button type="button" class="btn btn-default">Left</button>
</div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-default">Middle</button>
</div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-default">Right</button>
</div>
</div>
There's no need for extra css the .btn-group-justified class does this.
You have to add this to the parent element and then wrap each btn element in a div with .btn-group like this
<div class="form-group">
<div class="btn-group btn-group-justified">
<div class="btn-group">
<button type="submit" id="like" class="btn btn-lg btn-success ">Like</button>
</div>
<div class="btn-group">
<button type="submit" id="nope" class="btn btn-lg btn-danger ">Nope</button>
</div>
</div>
</div>
BOOTSTRAP 2 (source)
The problem is that there is no width set on the buttons. Try this:
.btn {width:20%;}
EDIT:
By default the buttons take an auto width of its text length plus some padding, so I guess for your example it is probably more like 14.5% for 5 buttons (to compensate for the padding).
Note:
If you don't want to try and compensate for padding you can use box-sizing:border-box;
http://www.w3schools.com/cssref/css3_pr_box-sizing.asp
I don't like the solution of settings widths on .btn because it assumes there'll always be the same number of items in the .btn-group. This is a faulty assumption and leads to bloated, presentation-specific CSS.
A better solution is to change how .btn-group with .btn-block and child .btn(s) are display. I believe this is what you're looking for:
.btn-group.btn-block {
display: table;
}
.btn-group.btn-block > .btn {
display: table-cell;
}
Here's a fiddle: http://jsfiddle.net/DEwX8/123/
If you'd prefer to have equal-width buttons (within reason) and can support only browsers that support flexbox, try this instead:
.btn-group.btn-block {
display: flex;
}
.btn-group.btn-block > .btn {
flex: 1;
}
Here's a fiddle: http://jsfiddle.net/DEwX8/124/
For bootstrap 4 just add this class:
w-100
Bootstrap 4 removed .btn-group-justified. As a replacement you can use <div class="btn-group d-flex" role="group"></div> as a wrapper around elements with .w-100.
Try this:
<div class="btn-group d-flex" role="group>
<button type="button" class="btn btn-primary w-100">Submit</button>
<button type="button" class="btn btn-primary w-100">Cancel</button>
</div>
Angular - equal width button group
Assuming you have an array of 'things' in your scope...
Make sure the parent div has a width of 100%.
Use ng-repeat to create the buttons within the button group.
Use ng-style to calculate the width for each button.
<div class="btn-group"
style="width: 100%;">
<button ng-repeat="thing in things"
class="btn btn-default"
ng-style="{width: (100/things.length)+'%'}">
{{thing}}
</button>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="btn-group btn-block">
<button type="button" data-toggle="dropdown" class="btn btn-default btn-xs btn-block dropdown-toggle">Actions <span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span></button><ul role="menu" class="dropdown-menu"><li>Action one</li><li class="divider"></li><li><a href="#" >Action Two</a></li></ul></div>
Bootstrap 4
<ul class="nav nav-pills nav-fill">
<li class="nav-item">
<a class="nav-link active" href="#">Active</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Longer nav link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
Bootstrap 4 Solution
<div class="btn-group w-100">
<button type="button" class="btn">One</button>
<button type="button" class="btn">Two</button>
<button type="button" class="btn">Three</button>
</div>
You basically tell the btn-group container to have width 100% by adding w-100 class to it. The buttons inside will fill in the whole space automatically.

Resources