Aligning buttons next to many inputs inside a row - html

This is part of a bigger table. I have three fields and each one should have a remove button aligned next to it.
The CSS I have alignes only the first button, and the other buttons are in the same position. How can I place the other two buttons next to their fields.
Thanks!
td .btn.aligned {
position: absolute;
margin-top: 7px;
float: right;
margin-left: 5px;
}
td input {
float: left;
margin-bottom: 10px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://use.fontawesome.com/a06b1c7829.js"></script>
<table id="tablaProveedores" class="table table-hover">
<thead class="thead-inverse">
<th>Phone numbers</th>
</thead>
<tbody>
<tr>
<td>
<input type="text" name="phone1_1" id="telefono1_1" class="form-control" disabled/>
<a title="Remove" class="btn btn-danger btn-xs aligned"><span class="fa fa-times"></span></a>
<input type="text" name="phone2_1" id="telefono2_1" class="form-control" disabled/>
<a title="Remove" class="btn btn-danger btn-xs aligned"><span class="fa fa-times"></span></a>
<input type="text" name="phone3_1" id="telefono3_1" class="form-control" disabled/>
<a title="Remove" class="btn btn-danger btn-xs aligned"><span class="fa fa-times"></span></a>
</tr>
</tbody>
</table>

Wrap them in <div>s. Giving them the class .row with the bootstrap framework will do everything you need.
td .btn.aligned {
position: absolute;
margin-top: 7px;
float: right;
margin-left: 5px;
}
td .lowered {
margin-top: 44px;
}
td input {
float: left;
margin-bottom: 10px;
}
.spacer {
padding-left: 30px !important;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://use.fontawesome.com/a06b1c7829.js"></script>
<table id="tablaProveedores" class="table table-hover">
<thead class="thead-inverse">
<th>Phone numbers</th>
</thead>
<tbody>
<tr>
<td>
<div class="row">
<input type="text" name="phone1_1" id="telefono1_1" class="form-control" disabled/>
<a title="Remove" class="btn btn-danger btn-xs aligned"><span class="fa fa-times">
</span>
</a>
</div>
<div class="row">
<input type="text" name="phone2_1" id="telefono2_1" class="form-control" disabled/>
<a title="Remove" class="btn btn-danger btn-xs aligned"><span class="fa fa-times">
</span>
</a>
</div>
<div class="row">
<input type="text" name="phone3_1" id="telefono3_1" class="form-control" disabled/>
<a title="Remove" class="btn btn-danger btn-xs aligned"><span class="fa fa-times">
</span>
</a>
</div>
</tr>
</tbody>
</table>

I was able to get this accomplished with a bit less code. I removed the absolute positioning and applied a max-width to the input and a float left instead of right to the buttons since they're in the same table-cell.
Check out the jsfiddle
td .btn.aligned {
margin-top: 7px;
float: left;
margin-left: 5px;
}
td input {
float: left;
margin-bottom: 10px;
max-width:80%;
}

Related

Divide spacing in bootstrap group of buttons

How to get equal spacing in this group of buttons?
When I add pull-right to the class the search and plus buttons is set to below the search box.
<tr>
<th class="col-md-3">
<small>Firma</small>
<span class="glyphicon glyphicon-sort-by-alphabet glyph_sorting" aria-hidden="true"></span>
<span class="glyphicon glyphicon-sort-by-alphabet-alt glyph_sorting" aria-hidden="true"></span>
</th>
<th class="col-md-3"><small>Plaats</small></th>
<th class="col-md-3"><small>Telefoon</small></th>
<th class="col-md-3">
<form action="" method="post">
<div class="form-group col-xs-8">
<input type="text" class="form-control input-sm" placeholder="Search">
</div>
<button type="submit" class="btn btn-default btn-sm"><span class="glyphicon glyphicon-search" aria-hidden="true"></span></button>
<button type="button" class="btn btn-sm"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></button>
</form>
</th>
</tr>
Edit based on comment:
Set parent container (form) to flexbox row, and center it's children elements horizontally with even space in-between with justify-content:space-between & vertically with align-items:center.
Override bootstrap's .form-control's padding & margin, which is whats causing the space async between buttons & the search input.
form {
display: flex;
flex-flow: row wrap;
justify-content: space-between;
align-items: center;
}
div.form-group {
padding: 0;
margin: 0;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<table>
<tr>
<th class="col-md-3">
<small>Firma</small>
<span class="glyphicon glyphicon-sort-by-alphabet glyph_sorting" aria-hidden="true"></span>
<span class="glyphicon glyphicon-sort-by-alphabet-alt glyph_sorting" aria-hidden="true"></span>
</th>
<th class="col-md-3"><small>Plaats</small></th>
<th class="col-md-3"><small>Telefoon</small></th>
<th class="col-md-3">
<form action="" method="post">
<div class="form-group col-xs-8">
<input type="text" class="form-control input-sm" placeholder="Search">
</div>
<button type="submit" class="btn btn-default btn-sm"><span class="glyphicon glyphicon-search" aria-hidden="true"></span></button>
<button type="button" class="btn btn-sm"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></button>
</form>
</th>
</tr>
</table>

How to center-align buttons inside <td>?

enter image description hereI have two button inside my and I need to align it in the center
<td align="center">
<form action="ReplyFound" method="post" class="pull-left">
<a class="btn btn-default "><em class="fa fa-pencil"></em></a>
</form>
<form action="DeleteMessage" method="post" class="pull-left">
<a class="btn btn-danger "><em class="fa fa-trash"></em></a>
</form>
</td>
Try:
display: block;
margin: auto;
Try This :
.divCenter {
width: 100%;
max-width: 960px;
margin: 0 auto;
text-align: center;
}
.pull-left {
display: inline-block;
margin: 5px;
background-color: #000;
color: #fff;
}
<div class="divCenter">
<td align="center">
<form action="ReplyFound" method="post" class="pull-left">
<a class="btn btn-default "><em class="fa fa-pencil">Button1</em></a>
</form>
<form action="DeleteMessage" method="post" class="pull-left">
<a class="btn btn-danger "><em class="fa fa-trash">Button2</em></a>
</form>
</td>
</div>
You can use following html for this
<td class="text-center">
<form action="ReplyFound" method="post" class="btn-block">
<a class="btn btn-default "><em class="fa fa-pencil"></em></a>
</form>
<form action="DeleteMessage" method="post" class="btn-block">
<a class="btn btn-danger "><em class="fa fa-trash"></em></a>
</form>
</td>
Missing closing tag </form>.
If you are not defining width when its width will be wrap content.
<table style="width:100%">
<tr>
<td align="center">
<form action="ReplyFound" method="post" class="pull-left">
<a class="btn btn-default ">Edit</a>
</form>
<form action="DeleteMessage" method="post" class="pull-left">
<a class="btn btn-danger ">Delete</a>
</form>
</td>
</tr>
</table>
You can use this
.centerBtn{
display:inline-block;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<table style="width:100%">
<tr>
<td align="center" >
<div class="centerBtn">
<form action="ReplyFound" method="post" class="pull-left">
<a class="btn btn-default "><em class="fa fa-pencil"></em></a>
</form>
<form action="DeleteMessage" method="post" class="pull-left">
<a class="btn btn-danger "><em class="fa fa-trash"></em></a>
</form>
</div>
</td>
</tr>
</table>

Adjusting Buttons and Text Field in a Div

I'm trying to develop a Integer Number Field. I've got it working but the styling is somewhat creating a problem. I'm using Glyphicons Plus and Minus to act as increment and decrement functionalities and input text field to display the Integer number.
I'm not able to adjust the Minus Glyphicon to the height of the div.
The working code: http://jsfiddle.net/nvarun123/fv4jxo4t/26/
HTML code:
<div>
<a>
<button (click)="decrement()" class="btn btn-primary">
<span><i class="glyphicon glyphicon-minus" ></i></span>
</button>
</a>
<input type="text" style="width:45%;" [(ngModel)]="count">
<a>
<button (click)="increment()" class="btn btn-primary" style="float: right;">
<span><i class="glyphicon glyphicon-plus" ></i></span>
</button>
</a>
</div>
CSS code:
div {
position:relative;
border: 1px solid #CACEDB;
width: 162px;
height:38px;
overflow: hidden;
white-space: nowrap;
border-radius:3px;
}
input{
text-align: center;
height:100%;
width:100%;
border:none;
}
input:focus{
outline: none;
}
button
{
-webkit-appearance: none;
outline: none;
height:100%;
border:none;
vertical-align:middle;
}
button:active {
background-color: #015191;
}
Your minus button needs a float:left :
<div>
<a>
<button (click)="decrement()" class="btn btn-primary" style="float: left;">
<span><i class="glyphicon glyphicon-minus" ></i></span>
</button>
</a>
<input type="text" style="width:45%;" [(ngModel)]="count">
<a>
<button (click)="increment()" class="btn btn-primary" style="float: right;">
<span><i class="glyphicon glyphicon-plus" ></i></span>
</button>
</a>
</div>
As you are already using Bootstrap you can make use of the input-group class alongside input-group-btn. Reference the CodePen link below:
http://codepen.io/rkieru/pen/JKOyom
<div class="input-group">
<span class="input-group-btn"><button class="btn btn-primary" type="button"><i class="fa fa-minus"></i></button></span>
<input type="text" class="form-control" placeholder="Integer">
<span class="input-group-btn"><button class="btn btn-primary" type="button"><i class="fa fa-plus"></i></button></span>
</div>
I would also recommend not wrapping your <button> in an <a> tag. The <button> can function on a JS event on its own and the code is cleaner.

Space between two buttons on a Bootstrap form

I want to add some space between 2 buttons. This form is created using bootstrap. Tried a number of tricks but couldn't get what I want. The same page is accessed via mobile too.
Here is my code along with screenshot:
<div class="input-group">
<span class="input-group-btn">
<input type="button" style="border-radius: 10px;" id="button1" class="btn btn-primary btn-lg btn-block" value="My Provider"/>
</span>
<span class="input-group-btn" >
<input type="button" style="border-radius: 10px;" id="button2" class="btn btn-primary btn-lg btn-block" value="Any Provider"/>
</span>
</div>
The problem is Bootstrap's btn-block class.
A block level button spans the entire width of the parent element.
http://www.w3schools.com/bootstrap/bootstrap_buttons.asp
Try removing that class from each of your buttons, setting the width of the input-group class to 100% and adding margin after the first button.
input[type=button] {
border-radius: 10px;
width: 47%;
}
.input-group {
display: inline-block;
width: 100%;
}
input[type=button]:first-child {
margin-right: 20px;
}
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="input-group">
<input type="button" id="button1" class="btn btn-primary btn-lg" value="My Provider"/>
<input type="button" id="button2" class="btn btn-primary btn-lg" value="Any Provider"/>
</div>
You can add paddings to input-group-btn blocks.
.container {
margin-top: 50px;
}
.input-group-btn-left {
padding-right: 30px;
}
.input-group-btn-right {
padding-left: 30px;
}
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<div class="container">
<div class="input-group">
<span class="input-group-btn input-group-btn-left">
<input type="button" id="button1" class="btn btn-primary btn-lg btn-block" value="My Provider" style="border-radius: 10px;">
</span>
<span class="input-group-btn input-group-btn-right">
<input type="button" id="button2" class="btn btn-primary btn-lg btn-block" value="Any Provider" style="border-radius: 10px;">
</span>
</div>
</div>

Bootstrap button inside input-group

How to make it so that it appears nicely after input page with same height?
<div class="input-group">
<input type="text" class="form-control"/>
<button class="input-group-addon" type="submit">
<i class="fa fa-search"></i>
</button>
</div>
Here is code http://jsfiddle.net/6mcxdjdr/ The first one is original input-group, the second one is something what I am trying to have
If you follow bootstrap's documentation:
<div class="input-group">
<input type="text" class="form-control" placeholder="Search for...">
<span class="input-group-btn">
<button class="btn btn-default" type="submit">
<i class="fa fa-search"></i>
</button>
</span>
</div>
Bootstrap 4 provides the classes input-group-prepend and input-group-append that allows the effect of button inside input.
Below the snippet for a left aligned button inside input-group (class input-group-prepend):
#import "https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css";
<div class="input-group">
<div class="input-group-prepend">
<button class="btn btn-outline-secondary" type="button">Prepended button</button>
</div>
<input type="text" class="form-control">
</div>
And the snippet for a right aligned button inside input-group (class input-group-append):
#import "https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css";
<div class="input-group">
<input type="text" class="form-control">
<div class="input-group-append">
<button class="btn btn-outline-secondary" type="button">Button</button>
</div>
</div>
here is my solution, using a little CSS to position the button to the right of the input field by adding position: absolute and a z-index:
button.input-group-addon {
position: absolute;
right: -38px;
top: 0;
padding: 2px;
z-index: 999;
height: 34px;
width: 38px;
}
http://jsfiddle.net/6mcxdjdr/1/
Another idea is to manipulate the form submit with javascript, so you dont have to create your own button but submit the form by clicking on the bootstrap span. This could be done by
$('.input-group-addon').click(function(){ $('#myform').submit(); });
You can also try this way
<div class="input-group">
<input type="text" class="form-control search-input" />
<span class="input-group-addon">
<i class="fa fa-search"></i>
</span><span class="input-group-addon">
<i class="fa fa-refresh"></i>
</span>
</div>
.search-input {
border-right: 0;
}
.input-group-addon {
background: white;
border-left: 0;
border-right: 0;
}
.input-group-addon:last-child {
border-left: 0;
border-right: 1px solid #ccc;
}
Try this,
.input-group-addon{
width:50px;
position:absolute;
margin-left:196px;
height:34px;
}
.input-group-addon > i{
text-align:center;
font-size:18px;
}
Here's how I did it, I had to override some css...
(Bootstrap 4 Beta 2)
Html
<div class="input-group">
<input type="search" class="form-control" placeholder="search..." />
<span class="input-group-addon input-group-addon-btn bg-white">
<button class="btn px-2" type="submit"><i class="fa fa-search" aria-hidden="true"></i></button>
</span>
</div>
And here's the css
#app-search .input-group-addon-btn {
padding: 0;
button {
border: none;
background: transparent;
cursor: pointer;
height: 100%;
}
}