Bootstrap button inside input-group - html

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

Related

Search Icon inside text box

How to place search icon inside text box
<input class="col-lg-3 col-md-3 col-sm-5 col-xs-5 form-control" type="text" name="searchroleName" id="searchroleName" placeholder="Search By RoleName"/><span class="fa fa-search form-control-feedback"></span>
working fiddle
Hope this code snippet will help you.
<div class="col-lg-3 col-md-3 col-sm-5 col-xs-5">
<div class="input-group">
<input type="text" class="form-control" id="exampleInputAmount" placeholder="Amount">
<div class="input-group-btn">
<button type="button" class="btn btn-default">
<span class="glyphicon glyphicon glyphicon-search"></span>
</button>
</div>
</div>
</div>
CSS:
input {
border: 0;
background: transparent;
-webkit-appearance: none;
-moz-appearance: none;
-ms-appearance: none;
-o-appearance: none;
appearance: none;
}
input:focus{
outline: 0;
}
.input-placeholder{
background-color: #eee;
display: inline-block;
padding: 10px;
}
HTML:
<div class="input-placeholder">
<input class="col-lg-3 col-md-3 col-sm-5 col-xs-5 form-control" type="text" name="searchroleName" id="searchroleName" placeholder="Search By RoleName"/><span class="fa fa-search form-control-feedback"></span>
</div>
Here's the fiddle https://jsfiddle.net/6d463wo1/1/
As per your code it looks like you are using Bootstrap, in bootstrap it provide another method like input-group. You can use following html code for this
<div class="col-lg-3 col-md-3 col-sm-5 col-xs-5">
<div class="input-group">
<input class="form-control" type="text" name="searchroleName" id="searchroleName" placeholder="Search By RoleName"/><div class="input-group-addon"><span class="fa fa-search form-control-feedback"></span></div>
</div>
</div>
There's a bootstrap way for this. Use the .input-group-addon class.
<div class="input-group">
<input type="text" class="form-control" placeholder="Search By RoleName" aria-describedby="basic-addon2">
<span class="input-group-addon fa fa-search" id="basic-addon2"></span>
</div>
In order to place the button inline with the input field, add this css:
.input-group .fa-search{
display: table-cell;
}
Please try it in the fiddle here
You can use this if you want
<input class="col-lg-3 col-md-3 col-sm-5 col-xs-5 form-control" type="text" name="searchroleName" id="searchroleName" placeholder="Search By RoleName 🔍"/>
<!DOCTYPE ht`enter code here`ml>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/fontawesome/4.7.0/css/font-awesome.min.css">
<style>
* {
box-sizing: border-box;
}
.club input[type=text] {
padding: 10px;
font-size: 17px;
border: 1px solid black;
border-right: 0px solid black;
float: left;
width: 90%;
}
.club button {
float: left;
width: 10%;
padding: 10px;
background:white;
color: black;
font-size: 17px;
border: 1px solid grey;
border-left: none;
cursor: pointer;
}
</style>
</head>
<body>
<div class="club">
<input type="text" placeholder="Search.." name="search2">
<button type="submit"><i class="fa fa-search"></i></button>
<div>
</body>
</html>
code on fiddle

CSS: Span color when adjacent input is selected

I am attempting to create a css rule that will allow the fa-search icon to change color only when the input field is selected:
<div class="field-icon-prepend">
<span class="field-icon"><i class="fa fa-search"></i></span>
<input type="search" id="top-nav-search" name="s" placeholder="Search">
</div>
How would I create this rule?
What you're asking for is not quite possible, but this is close enough:
.fa-search{
float:left;
margin: 0 5px 0 0;
}
#top-nav-search:focus + .field-icon .fa-search{
color: red;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="field-icon-prepend">
<input type="search" id="top-nav-search" name="s" placeholder="Search">
<span class="field-icon"><i class="fa fa-search"></i></span>
</div>

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.

Input groups button bigger than input in Bootstrap 3 using Jumbotron container

Here is my code for the form:
<div class="container-full">
<div class="jumbotron text-center" style="background-color:transparent; margin:auto">
<form name="verifyForm" ng-submit="submitForm()" novalidate>
<div class="input-group input-group-lg col-xs-1" style="margin: auto;" ng-class="{'has-error': verifyForm.verifyCode.$invalid}">
<input type="text" class="form-control" placeholder="Username" style="min-width:15em">
<span class="input-group-addon">
<button id="filter" class="btn btn-primary btn-block" onclick="submitForm();" style="background-color:#6e5cbf; color: #ffffff">
>
</button></span>
</div>
</form>
</div>
The problem I have is when I add a button to the button group, it is bigger than the input box:
How can I stop this from happening? Thanks
You could do it by changing the button to a span with role=button on the parent and switching a few styles around, like so
<div class="container-full">
<div class="jumbotron text-center" style="background-color:transparent; margin:auto">
<form name="verifyForm" ng-submit="submitForm()" novalidate>
<div class="input-group input-group-lg col-xs-1" style="margin: auto;" ng-class="{'has-error': verifyForm.verifyCode.$invalid}">
<input type="text" class="form-control" placeholder="Username" style="min-width:15em">
<span class="input-group-addon" style="background-color:#6e5cbf;" role="button">
<span id="filter" onclick="submitForm();" style="color: #ffffff">
>
</span>
</span>
</div>
</form>
</div>
</div>
While the bootstrap documentation doesn't say anything about buttons, it does say
We do not support multiple form-controls in a single input group.
Looking at the styling of buttons vs. form-controls I'd assume that the restriction extends to buttons as well.
It's going to look like this (image)
Try to add form-group for these input and button element.
something like
<form name="verifyForm" ng-submit="submitForm()" novalidate>
<div class="input-group input-group-lg col-xs-1" style="margin: auto;" ng-class="{'has-error': verifyForm.verifyCode.$invalid}">
<div class="form-group">
<input type="text" class="form-control" placeholder="Username" style="min-width:15em">
</div>
<div class="form-group">
<span class="input-group-addon">
<button id="filter" class="btn btn-primary btn-block" onclick="submitForm();" style="background-color:#6e5cbf; color: #ffffff"></button>
</span>
</div>
</div>
</form>
It will differentiate those two blocks and you can write cutom classes on top of that
Your button has class .btn which has following style:
.btn{
display: inline-block;
padding: 6px 12px; //this is what making it to extend space
margin-bottom: 0;
font-size: 14px;
font-weight: 400;
line-height: 1.42857143; //and this too
text-align: center;
white-space: nowrap;
vertical-align: middle;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
background-image: none;
border: 1px solid transparent;
border-radius: 4px;
}
So the work-around will be override those properties. Add a class say 'special' to the button and override following attributes:
.special{
padding:0px !important;
line-height:1
}
DEMO
Why is everyone making it complicated? Just put this and y'all will be fine.
This:
<input class="btn btn-outline-primary form-control-sm" type="button" Value="Send" />
instead of:
<button class="btn btn-outline-primary form-control-sm">Send</button>
Boom. We done.

bootstrap form while mobile

I'm using a form for the site search with a button inside the text-box. On the desktop version it works ok, howerver when resizing to mobile it is not. I am using a position: absolute; to set the button positioning, giving it a fixed position. Is there any way I can make this work on the mobile version as well?
HTML:
<!-- Right search form -->
<div class="col-md-3 col-xs-12">
<form class="form-inline" role="search">
<div class="form-group">
<input type="text" class="form-control search-input" size="40" placeholder="Cauta in site...">
<input type="submit" value="" class="search-button" id="searchsubmit">
</div>
</form>
</div>
CSS:
.search-button {
background: url('../images/search-btn.png') right no-repeat;
border: 0px solid black;
border-left: none;
cursor: pointer;
height: 35px;
width: 35px;
position:absolute;
left:241px;
top: 3px;
}
you can use the bootstrap class
reference here
<div class="input-group">
<span class="input-group-btn">
<button class="btn btn-default" type="button">Go!</button>
</span>
<input type="text" placeholder="Cauta in site..." class="form-control">
</div><!-- /input-group -->