Adjusting Buttons and Text Field in a Div - html

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.

Related

input-prepend create two rows

I'm trying to add two buttons on both sides of the search field, so I did this:
<div id="fixtures-filter">
<div class="input-group-btn">
<div class="input-group-prepend"><button type="button" class="btn btn-light" aria-expanded="false" id="countries-btn">Filters</button></div>
<div class="app-search">
<div class="input-group"><input type="text" class="form-control" placeholder="Search..."><span class="mdi mdi-magnify"></span>
<div class="input-group-append"><button type="button" class="btn btn-light" data-toggle="modal" data-target="#fixtures-filter-modal">Search</button> </div>
</div>
</div>
</div>
</div>
the result is really weird:
This is a JSFIDDLE.
Use an append and prepend. Adjust the borders as needed to make the search icon appear inside the input.
<div class="input-group">
<span class="input-group-prepend">
<button class="btn btn-primary" type="button">
Filters
</button>
</span>
<span class="input-group-prepend">
<div class="input-group-text bg-transparent border-right-0"><i class="fa fa-search"></i></div>
</span>
<input class="form-control py-2 border-left-0 border" type="search" value="..." id="example-search-input">
<span class="input-group-append">
<button class="btn btn-outline-secondary border-left-0 border" type="button">
Search
</button>
</span>
</div>
https://www.codeply.com/go/KJcZWvSsR9
If you are trying to get the filter to be on the same line, you have to move it inside the same parent div as the other inputs:
<div id="fixtures-filter">
<div class="input-group-btn">
<div class="app-search">
<div class="input-group">
<div class="input-group-prepend"><button type="button" class="btn btn-primary" aria-expanded="false" id="countries-btn"><span class="mdi mdi-magnify"></span></button></div>
<input type="text" class="form-control padleft" placeholder="Search...">
<span class="mdi mdi-magnify search-mg"></span>
<div class="input-group-append">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#fixtures-filter-modal">Search</button>
</div>
</div>
</div>
</div>
</div>
CSS added to get the magnifying glass icon to appear in the search input:
#fixtures-filter {
position: relative;
}
span.search-mg {
position: absolute;
z-index: 10;
font-size: 20px;
line-height: 38px;
left: 45px;
}
.padleft {
padding-left: 30px;
}
fiddle: http://jsfiddle.net/5xkbn3o0/

How to prevent button click inside the label control?

I have this HTML code:
<label style="padding: 0px 0px!important; text-align:center">
<span style="color: gray">Some Text</span>
<button onclick='alert("Hello!")' style="cursor: pointer;">
<i class="glyphicon glyphicon-pushpin btn-lg" aria-hidden="true"></i> </button>
</label>
Here is JSFiddle.
In label control I declared button.Button is clicked when I click in any area in the label.How to make button clicked only when I click on the button it self?
unwrap label to button like
<label style="padding: 0px 0px!important; text-align:center">
<span style="color: gray">Some Text</span>
</label>
<button onclick='alert("Hello!")' style="cursor: pointer;">
<i class="glyphicon glyphicon-pushpin btn-lg" aria-hidden="true"></i>
</button>
https://jsfiddle.net/xzgqLhpd/2/
Your solution is like so:
<label style="padding: 0px 0px!important; text-align:center">
<span style="color: gray">Some Text</span>
</label>
<button onclick='alert("Hello!")' style="cursor: pointer;">
<i class="glyphicon glyphicon-pushpin btn-lg" aria-hidden="true"></i>
</button>
Just place the button outside the label.
add onclick function on wrapper element with return false;
<label onclick="return false;">
<span style="color: gray">Some Text</span>
<button onclick='alert("Hello!");' style="cursor: pointer;">
MY BUTTON
</button>
</label>

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%;
}
}

Glyphicon and Button Text should be side by side

I am trying to place a glyphicon inside a button control but the button text and glyphicon don't come in the same line. The button text comes slightly below and is not parallel with the glyphicon
<button type="button" class="btn btn-default" aria-label="my button" style="border: 0px">
<span class="glyphicon glyphicon-plus-sign" style="color:#a0a0a0; font-size: 30px" aria-hidden="true"></span>
My Button Text
</button>
there should be vertical-align: middle; to glyphicon span where you have placed inline CSS
<button type="button" class="btn btn-default" aria-label="my button" style="border: 0px">
<span class="glyphicon glyphicon-plus-sign" style="color:#a0a0a0; font-size: 30px; vertical-align: middle;" aria-hidden="true"></span>
My Button Text
</button>
That's it :)
You can use bootstrap grid system and css like following:
<button type="button" class="btn btn-default" aria-label="my button" style="border: 0px">
<div class="col-md-2">
<span class="glyphicon glyphicon-plus-sign" style="color:#a0a0a0; font-size: 30px" aria-hidden="true"></span>
</div>
<div class="col-md-10" style="padding-top:5px; margin-left: -4px">
My Button Text
</div>
</button>