How to add Search Icon next to my label? - css

Hi I am working in Angular 4 designing using bootstrap 4.
I tried to add search Icon at the end of my label.
Codings below:
<div class="row ">
<div class="form-group col-lg-2"></div>
<div class="form-group col-lg-4">
<label class="Bold">Location Id </label>
<input type="text" class="form-control" name="LocationId" >
<span class="input-group-btn">
<button class="btn btn-info btn-md" type="button"><i class="fa fa-search"></i></button>
</span>
</div>
<div class="form-group col-lg-4">
<label class="Bold">Description </label>
<input type="text" class="form-control" name="description">
</div>
<div class="form-group col-lg-2"></div>
</div>
but it comes like the attached image. How to add icon at the end of label. Is any problem with my coding?

Try to make use of input-group component of bootstrap4
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="col-6">
<div class="form-group">
<label>Username</label>
<div class="input-group">
<input type="text" class="form-control" placeholder="Username" aria-label="Username" aria-describedby="basic-addon2">
<div class="input-group-append">
<button class="btn btn-outline-secondary" type="button">Go</button>
</div>
</div>
</div>
</div>
</div>
</div>

Try this. Wrap input and span to the input-group.
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" >
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" ></script>
<div class="row ">
<div class="form-group col-lg-2"></div>
<div class="form-group col-lg-4">
<label class="Bold">Location Id </label>
<div class="input-group">
<input type="text" class="form-control" name="LocationId" >
<span class="input-group-append">
<button class="btn btn-info btn-md" type="button">
<i class="fa fa-search"></i>
</button>
</span>
</div>
</div>
<div class="form-group col-lg-4">
<label class="Bold">Description </label>
<input type="text" class="form-control" name="description">
</div>
<div class="form-group col-lg-2">
</div>
</div>

Form-control class for Input makes the text box occupy the entire width. We need to use input-group class to group input and any icon attached to it. Refer code snippet below for example:
<div class="input-group">
<input type="text" class="form-control"/>
<span class="input-group-addon">
<i class="fa fa-search"></i>
</span>
</div>

Following is the code snippet:
<div class="form-group col-lg-4">
<label class="Bold">Location Id </label>
<input type="text" class="location-txt form-control" name="LocationId" >
<span class="input-group-btn location-search">
<button class="btn btn-info btn-md" type="button">
<i class="fa fa-search"></i>
</button>
</span>
</div>
CSS
.location-txt
width: calc(100% - 44px);
float: left;
}
.location-search{
display: inline-block;
float: right;
}

Related

Bootstrap 4, Form-Inline does not align on XS view

Using Boostrap 4, I have a .form-inline at the footer of my page. It looks fine when the viewport is larger than the XS breakpoint...
...but then breaks when entering XS view...
...from my understanding, the subscribe button should drop below the input field on XS view.
Here is the code that I used...
<div class="col-md-6 col-lg-4 order-first order-md-6 align-self-center">
<form class="form-inline justify-content-center">
<div class="form-group">
<input type="email" class="form-control mr-2 mb-2" id="EmailInpue" placeholder="Join our Mailing List" />
</div>
<button type="submit" class="btn btn-primary mb-2"><i class="far fa-envelope-open"></i> Subscribe</button>
</form>
</div>
...I managed to get what I wanted by putting the button in the same form-group div as the input...
<div class="col-md-6 col-lg-4 order-first order-md-6 align-self-center">
<form class="form-inline justify-content-center">
<div class="form-group">
<input type="email" class="form-control mr-2 mb-2" id="EmailInpue" placeholder="Join our Mailing List" />
<button type="submit" class="btn btn-primary mb-2"><i class="far fa-envelope-open"></i> Subscribe</button>
</div>
</form>
</div>
...but from my understanding of the Bootstrap format is that the button should usually be outside of that form-group.
Anyways, this seems to have solved the problem.
You should not put the buttons in the same form-group as the input because form-group, by default, has only margin-bottom.
There are a few ways to fix this issue.
Put the button in a form-group.
<div class="form-group">
<button type="submit" class="btn btn-primary mb-2"><i class="far fa-envelope-open"></i> Subscribe</button>
</div>
Keep your code as it is but remove the margin-bottom of the form-group.
<div class="form-group mb-0">
I'd go for the last approach.
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.css" rel="stylesheet" />
<div class="col-md-6 col-lg-4 order-first order-md-6 align-self-center">
<form class="form-inline justify-content-center">
<div class="form-group mb-0">
<input type="email" class="form-control mr-2 mb-2" id="EmailInpue" placeholder="Join our Mailing List" />
</div>
<button type="submit" class="btn btn-primary mb-2"><i class="far fa-envelope-open"></i> Subscribe</button>
</form>
Putting the button code in the same form-group div as the input field seems to have worked...
<div class="col-md-6 col-lg-4 order-first order-md-6 align-self-center">
<form class="form-inline justify-content-center">
<div class="form-group">
<input type="email" class="form-control mr-2 mb-2" id="EmailInpue" placeholder="Join our Mailing List" />
<button type="submit" class="btn btn-primary mb-2"><i class="far fa-envelope-open"></i> Subscribe</button>
</div>
</form>
</div>

How to make labels and inputs on the same row?

I use Bootstrap 3 in my project.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="row well well-sm">
<div class="col-xs-2">
<label for="txtMonth"> month:</label>
<input type="number" class="form-control input-sm" id="txtMonth" ng-model="month" />
</div>
<div class="col-xs-3">
<label for="txtMonth"> year:</label>
<input type="number" class="form-control input-sm" id="txtYear" ng-model="year" />
</div>
<div class="col-xs-2">
<input type="button" class="btn btn-default btn-sm" id="btnGetRecords" ng-click="getRecords()" value="Enter" />
</div>
</div>
As you can see each input number has label, but the label and input not on the same row how to make label and input show on a single row?
use col-xs-4[label] in your label and create new div for and col-xs-8 [input div]
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row well well-sm">
<div class="col-xs-5">
<label class="col-xs-4" for="txtMonth"> month:</label>
<div class="col-xs-8">
<input type="number" class="form-control input-sm" id="txtMonth" ng-model="month" />
</div>
</div>
<div class="col-xs-5">
<label class="col-xs-4" for="txtMonth"> year:</label>
<div class="col-xs-8">
<input type="number" class="form-control input-sm" id="txtYear" ng-model="year" />
</div>
</div>
<div class="col-xs-2">
<input type="button" class="btn btn-default btn-sm" id="btnGetRecords" ng-click="getRecords()" value="Enter" />
</div>
</div>
Just use the form-inline to align your label and input inline as below.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<form class="form-inline">
<div class="well well-sm">
<div class="form-group">
<label for="txtMonth"> month:</label>
<input type="number" class="form-control input-sm" id="txtMonth" ng-model="month" />
</div>
<div class="form-group">
<label for="txtMonth"> year:</label>
<input type="number" class="form-control input-sm" id="txtYear" ng-model="year" />
</div>
<div class="form-group">
<input type="button" class="btn btn-default btn-sm" id="btnGetRecords" ng-click="getRecords()" value="Enter" />
</div>
</div>
</form>
You need to wrap you Code into a div with CSS class of form-group like this:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="row well well-sm">
<div class="form-group">
<label class="col-xs-2" for="txtMonth"> month:</label>
<div class="col-xs-2">
<input type="number" class="form-control input-sm" id="txtMonth" ng-model="month"/>
</div>
<label class="col-xs-2" for="txtMonth"> year:</label>
<div class="col-xs-2">
<input type="number" class="form-control input-sm" id="txtYear" ng-model="year"/>
</div>
<input type="button" class="btn btn-default btn-sm" id="btnGetRecords" ng-click="getRecords()" value="Enter"/>
</div>
</div>
It is because of the form-control class having width:100% and display:block properties. If you overwrite this one that will work automatically.
Also Increase the xs values for fixing the label and text boxes in a same row.
Apply some new class and override the above properties like below.
.newclass {
display:inline-block;
width:auto;
}
<div class="row well well-sm">
<div class="col-xs-5">
<label for="txtMonth"> month:</label>
<input type="number" class="form-control newclass input-sm" id="txtMonth" ng-model="month" />
</div>
<div class="col-xs-5">
<label for="txtMonth"> year:</label>
<input type="number" class="form-control newclass input-sm" id="txtYear" ng-model="year" />
</div>
<div class="col-xs-2">
<input type="button" class="btn btn-default btn-sm" id="btnGetRecords" ng-click="getRecords()" value="Enter" />
</div>
</div>
DEMO
Hope it will work
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="col-xs-12">
<label for="txtMonth" class="col-xs-2"> month:</label>
<label for="txtMonth" class="col-xs-3"> year:</label>
<div class="col-xs-7">
</div>
</div>
<div class="col-xs-12">
<div class="col-xs-2">
<input type="number" class="form-control input-sm" id="txtMonth" ng-model="month" />
</div>
<div class="col-xs-3">
<input type="number" class="form-control input-sm" id="txtYear" ng-model="year" />
</div>
<div class="col-xs-2">
<input type="button" class="btn btn-default btn-sm" id="btnGetRecords" ng-click="getRecords()" value="Enter" />
</div>
<div class="col-xs-5">
</div>
</div>

Twitter Bootstrap 3 - feedback glyphicons are shifted

When I put 2 fields in a row, their glyphicons are being shown with a nasty offset:
<div class="form-inline">
<div class="form-group col-xs-6 has-feedback has-error">
<input data-placeholder="Your Latitude" id="latitude" name="latitude" type="text" class="form-control">
<span class="glyphicon glyphicon-remove form-control-feedback"></span>
</div>
<div class="form-group col-xs-6 has-feedback has-error">
<input data-placeholder="Your Longitude" id="longitude" name="longitude" type="text" class="form-control">
<span class="glyphicon glyphicon-remove form-control-feedback"></span>
</div>
</div>
The full JSFiddle is here: https://jsfiddle.net/v_melnik/f8u9hvLa/6/
Is there a way to make them being shown properly?
Lots of thanks to everyone!
UPDATE: Someone marked this question as a duplicate of this one. But this question isn't about adding a glyhicon, it's rather about using glyphicons with a "narrowed" input box.
change your html
<div class="form-inline">
<div class="col-xs-6">
<div class="form-group has-feedback has-error">
<input data-placeholder="Your Latitude" id="latitude" name="latitude" type="text" class="form-control">
<span class="glyphicon glyphicon-remove form-control-feedback"></span>
</div>
</div>
<div class="col-xs-6">
<div class="form-group has-feedback has-error">
<input data-placeholder="Your Longitude" id="longitude" name="longitude" type="text" class="form-control">
<span class="glyphicon glyphicon-remove form-control-feedback"></span>
</div>
</div>
</div>
jsfiddle
Use position:absolute for glyphicon.
.glyphicon-remove::before {
left: 0;
position: absolute;
}
DEMO
only for Mobile Device Because you can use xs class. Add Style.
.form-control-feedback
{
right: 7px;
}
Fiddle Demo
#import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css');
.form-control-feedback
{
right: 7px;
}
.
<!-- We'll use col-xs-* here, as JSFiddle's result window is really narrow -->
<div class="ibox col-xs-12">
<div class="ibox-content">
<form action="#">
<div>
<label>Location</label>
<div class="form-inline">
<div class="form-group col-xs-6 has-feedback has-error">
<input data-placeholder="Your Latitude" id="latitude" name="latitude" type="text" class="form-control">
<span class="glyphicon glyphicon-remove form-control-feedback"></span>
</div>
<div class="form-group col-xs-6 has-feedback has-error">
<input data-placeholder="Your Longitude" id="longitude" name="longitude" type="text" class="form-control">
<span class="glyphicon glyphicon-remove form-control-feedback"></span>
</div>
</div>
</div>
</form>
</div>
</div>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

Centering Labels Above Inputs using Bootstrap 3

I am trying to center my labels on top of me datetimepicker inputs but text-align:center does not seem to be cutting it.
http://jsfiddle.net/aesh3ufk/4/
Does anyone know how to center the labels on top of my inputs? Even !important does not work...
<div class="row">
<div class="col-xs-12">
<h4><strong>ITEMS CHECKED IN</strong></h4>
<div class='col-md-6'>
<label for="From">From</label>
<div class="form-group">
<div class='input-group date' id='datetimepicker1'>
<input type='text' id="From" class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
<div class='col-md-6'>
<label for="To">To</label>
<div class="form-group">
<div class='input-group date' id='datetimepicker2'>
<input type='text' id="To" class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
</div>
</div>
That's an easy fix actually. Just add text-center to your col-md-6 <div>s:
<div class="row">
<div class="col-xs-12">
<h4 class="CAlign"><strong>ITEMS CHECKED IN</strong></h4>
<!-- Right Here -->
<div class='col-md-6 text-center'>
<label for="From">From</label>
<div class="form-group">
<div class='input-group date' id='datetimepicker1'>
<input type='text' id="From" class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
<!-- And Here -->
<div class='col-md-6 text-center'>
<label for="To">To</label>
<div class="form-group">
<div class='input-group date' id='datetimepicker2'>
<input type='text' id="To" class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
</div>
</div>
JSFiddle Example
The label's display style is inline-block and you must change it to block in order to be able to align the text to the center
One option is just to add the .text-center Bootstrap class to the parent div like so:
<div class='col-md-6 text-center'>
<label for="From">From</label>
<div class="form-group">
<div class='input-group date' id='datetimepicker1'>
<input type='text' id="From" class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
http://jsfiddle.net/aesh3ufk/6/

Bootstrap Input Group pushes control little to left

I am trying to layout a form using bootstrap 3 but for some reason the input is pushed to left.
My markup looks like this
<div class="jumbotron">
<form name="invoiceForm" class="form-horizontal" role="form" data-toggle="validator">
<div class="form-group">
<label class="control-label col-sm-3" for="txt_job_date" >Date work performed</label>
<p class="input-group col-sm-3">
<input type="text"
class="form-control"
datepicker-popup="{{format}}" ng-model="dt"
is-open="opened" min-date="minDate"
max-date="'2015-06-22'"
datepicker-options="dateOptions"
date-disabled="disabled(date, mode)"
ng-required="true"
close-text="Close"
id="txt_job_date"
ng-model="job_date"
/>
<span class="input-group-btn">
<button type="button" class="btn btn-default" ng-click="open($event)"><i class="glyphicon glyphicon-calendar"></i></button>
</span>
</p>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="txt_job_ref_no" required-asterix="" >Ref No</label>
<div class="col-sm-2">
<input type="text" class="form-control" ng-model="ref_no" id="txt_job_ref_no" placeholder="123RTE" required="">
</div>
<div role="alert">
<span class="error has-error alert-danger" ng-show="invoiceForm.txt_job_ref_no.$error.required">
Ref no is required!</span>
</div>
</div>
</form>
</div>
Here is the link to fiddle
Many thanks in advance!
This should help. Wrap the labels and elements in cols, and the form in a .container inside the .jumbotron. You were over-complicating the layout.
<div class="jumbotron">
<div class="container">
<form name="invoiceForm" class="form-horizontal" role="form" data-toggle="validator">
<div class="col-sm-12">
<div class="form-group">
<label class="control-label" for="txt_job_date">Date work performed</label>
<div class="input-group">
<input type="text"
class="form-control"
datepicker-popup="{{format}}" ng-model="dt"
is-open="opened" min-date="minDate"
max-date="'2015-06-22'"
datepicker-options="dateOptions"
date-disabled="disabled(date, mode)"
ng-required="true"
close-text="Close"
id="txt_job_date"
ng-model="job_date"
/>
<span class="input-group-btn">
<button type="button" class="btn btn-default" ng-click="open($event)"><i class="glyphicon glyphicon-calendar"></i></button>
</span>
</div>
</div>
</div>
<div class="col-sm-12">
<div class="form-group">
<label class="control-label" for="txt_job_ref_no" required-asterix="" >Ref No</label>
<input type="text" class="form-control" ng-model="ref_no" id="txt_job_ref_no" placeholder="123RTE" required="">
</div>
</div>
</form>
</div>
</div>
http://jsfiddle.net/j8x15dbs/1/
Edit: Missed part about form being horizontal. Added new code below to reflect that.
This has the layout you're looking for
<div class="jumbotron">
<div class="container">
<form class="form-horizontal">
<div class="form-group">
<label class="control-label col-sm-3" for="txt_job_date">Date work performed</label>
<div class="col-sm-7">
<div class="input-group">
<input type="text"
class="form-control"
datepicker-popup="{{format}}" ng-model="dt"
is-open="opened" min-date="minDate"
max-date="'2015-06-22'"
datepicker-options="dateOptions"
date-disabled="disabled(date, mode)"
ng-required="true"
close-text="Close"
id="txt_job_date"
ng-model="job_date"
/>
<span class="input-group-btn">
<button type="button" class="btn btn-default" ng-click="open($event)"><i class="glyphicon glyphicon-calendar"></i></button>
</span>
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="txt_job_ref_no" required-asterix="">Ref No</label>
<div class="col-sm-7">
<input type="text" class="form-control" ng-model="ref_no" id="txt_job_ref_no" placeholder="123RTE" required="required">
</div>
</div>
</form>
</div>
</div>
http://jsfiddle.net/j8x15dbs/2/
A real easy thing to do - and a great way to learn - is to just copy the examples off of Bootstrap's site and replace their values with yours. :)
remove <col-sm-2> from before the input tag. As good practice, always use <div class="row"> before using <col-sm-12> and don't use rows or columns inside <div class="form-group">
Please read about bootstrap scaffolding to understand how to write good markup.

Resources