Use font-awesome icon inside input element - html

I have div element which inside has a span element and inside this one I have an i element, but the i tag goes out of the span and div elements.
Actually I want to put eye icon in the input field.
This is my current code, what should I do?
.fa-eye {
float: right;
display: flex;
}
.fa-eye {
position: absolute;
z-index: 5;
display: block;
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="eye">
<span>
<i class="fa fa-eye"></i>
</span>
<input placeholder="term">
</div>

Based on this commentary:
Actually I want to put eye in input field
You can check the next alternatives:
(1) If you want to use a font-awesome icon like a placeholder for the input, then you can use the Unicode Cheatsheet. In the next example I show you how to do this:
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<input type="text" class="fa" placeholder=" term">
(2) In the other hand, if you want to have a fixed static icon inside the input, then you can go with something like this:
.input-icon {
position: absolute;
left: 3px;
color: rgb(0, 128, 255);
/* Vertically center the icon in the input */
top: calc(50% - 0.5em);
}
#myInput {
padding-left: 25px;
}
.custom-wrapper {
position: relative;
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="custom-wrapper">
<input type="text" placeholder="term" id="myInput">
<i class="fa fa-eye input-icon"></i>
</div>

If you are using the position: absolute you need to decide which element is position: relative. Also, you need to decide where is the position of the "child" will be (for example where I want to put the left side).
And one last thing, you don't need to use the float: left/right when you are using positions.
Take a look at the next code:
.eye{
position: absolute;
}
.fa-eye {
position: relative;
left: 143px;
display: flex;
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<span >
<input class="eye" placeholder="term">
<i class="fa fa-eye"></i>
</span>

Related

How to put icon inside an input box

Can anyone help me to put the tick icon inside the input box at right corner?
Also is it possible to display a 'Field Saved' message along with the tick icon?
Update:
What if form contains multiple input in single row, then how to show icon inside the input boxes?
Fiddle: https://jsfiddle.net/sanadqazi/5Len09ad/1/
.test {
position: relative;
}
.test .fas.fa-check {
position: absolute;
top: 0;
right: 0;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.1/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous" />
<div class="row">
<div class="col-8">
<div class="test">
<input type="text">
<i class="fas fa-check inp"></i>
</div>
</div>
<div class="col-4">
<div class="test">
<input type="text">
<i class="fas fa-check inp"></i>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/jquery#3.5.1/dist/jquery.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.1/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#4.6.1/dist/js/bootstrap.bundle.min.js"></script>
A little bit of CSS should do the trick here.
Either add the following code snippet to a stylesheet or to a style block. Alternatively, you could apply the styles inline, directly on the HTML elements themselves.
CSS:
.test {
position: relative;
}
.test .fas.fa-check {
position: absolute;
top: 0;
right: 0;
}
UPDATE
If the form contains multiple select boxes in the same row, then they must be wrapped in a div which has relative positioning and inline display.
.col-8,
.col-4 {
position: relative;
}
.input-container {
border: solid 1px #000;
border-radius: 2px;
position: absolute;
display: flex;
align-items: center;
padding: 4px;
gap: 4px;
}
.input-container i {
display: flex;
justify-content: center;
align-items: center;
}
.inp {
height: 36px;
line-height: 36px;
}
input[type="text"] {
/* padding-right: 100px; */
border: none;
outline: none;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.1/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous" />
<div class="row">
<div class="col-8">
<label class="input-container">
<input type="text">
<i class="fas fa-check inp"></i>
<!-- <span>Field Saved</span> -->
</label>
</div>
<div class="col-4">
<label class="input-container">
<input type="text">
<i class="fas fa-check inp"></i>
<!-- <span>Field Saved</span> -->
</label>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/jquery#3.5.1/dist/jquery.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.1/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#4.6.1/dist/js/bootstrap.bundle.min.js"></script>
You can add a container element to your textbox and tick icon. Then, you can remove all the styles of the textbox and put similar styles to the container to make it look like the container itself is a textbox. This way, you can make it look like the icon (and the Field Saved text) inside the textbox.

Add html icon in button value

<input type="submit" id="appCreate" name="Reds" value="Reds" formaction=#Url.Action("") formmethod="post" class="btn btn-success btn-block" onclick="javascript: return SubmitForm(this);" />
CSS -
.reddot {
content: "\25cf";
font-size: 1.5em;
color: red;
}
I want to add <span class="reddot"></span> to the value of my button (it just creates a red dot icon). So the value of my button shown is Reds<red dot icon>
How can I do this?
Instead of content: "\25cf"; Try background: url('xyz.png');
<input> elements are considered void elements, therefore they cannot contain children. You could use a <button> element, but personally I'd discourage this method because the HTML spec deems it invalid.
One possible solution is to wrap the button in a container. That container could have a pseudo-element (::after) that places the red dot for you.
.reddot {
display: inline-block;
position: relative;
}
.reddot > input[type=submit] {
text-align: left;
padding-right: 20px; /* Add padding to make space for the dot */
}
.reddot::after { /* Place an element inside of .reddot */
display: block;
position: absolute;
top: 50%;
transform: translateY(-50%); /* Center it vertically */
right: 5px; /* 5px off the right edge */
content: "\25cf";
font-size: 1.5em;
color: red;
pointer-events: none; /* Make sure the dot doesn't block the button */
}
<div class="reddot">
<input type="submit" />
</div>
<div class="reddot">
<input type="submit" value="Here's another button with a red dot!" />
</div>

Bootstrap tooltip on Font Awsome icon in Modal

I have an input field with a Fontawesome icon that I added through content in my CSS file. This icon will only show on validation. I want to add bootstrap's tooltip to the icon, but I can't figure out a way to do this since my icon is on the CSS file and not on the HTML file. This is what I'm trying to achieve.
It might be important to note that I'm trying to achieve this in a modal.
$(function() {
$('[data-toggle="tooltip"]').tooltip()
})
.input-validation-error input {
border: 2px solid #f46262;
}
.input-validation-error input[type="text"] {
position: relative;
}
.input-validation-error::before {
font-family: "Font Awesome 5 Free";
color: #f46262;
position: relative;
content: "\f06a";
font-weight: 900;
z-index: 2;
top: 36px;
right: -210px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
<form class="registration-form">
<div class="form-group input-validation-error">
<input type="text" class="form-control" id="formGroupExampleInput" placeholder="Nombre de usuario" data-toggle="tooltip" data-placement="top" title="I'm a tooltip">
</div>
</form>
Add an empty "placeholder" div before the input and position it the same as the icon. Use the placeholder as the tooltip trigger...
.tooltip-trigger {
position: absolute;
z-index: 3;
top: 36px;
left: 210px;
width: 30px;
height: 30px;
}
https://www.codeply.com/go/VxFPfXj9oa
Finally figured it out. My z-index was causing trouble, so I changed it from:
z-index: 3;
to
z-index: 5 !important;

Using font awesome icon as uploadlabel

I am developing a website in Angular 2. I want to be able to upload images by clicking on a icon from font awesome, but i am having problems doing this. I can upload images when i use a label for this, but now when using font awesome icons i can't
What i have right now:
#pic {
border-radius: 200px;
width: 200px;
height: 200px;
background-size: 240px;
border-style: none;
border: 2px solid black;
outline: none;
cursor: pointer;
}
#pencilicon {
position: absolute;
margin-left: 85px;
margin-top: 85px;
font-size: 50px;
color: #fff;
visibility: hidden;
opacity: 0;
cursor: pointer;
transition: opacity .2s, visibility .2s;
}
#uploadinput{
position: absolute;
opacity: 0;
z-index: -1;
text-align: left;
}
<div id="picture">
<input type='file' (change)="readUrl($event)"id="uploadinput">
<i class="fa fa-pencil-square-o" for="uploadinput" id="pencilicon" aria-
hidden="true"> </i>
<img [src]="imageurl" id="pic" >
</div>
You have to include the font awesome library into your page and give the appropriate icon like so:
<i class="fa fa-upload"></i>.
See the code snippet below for an example and demo of your requirement.
input[type="file"].novisible {
display: none;
}
input[type="file"].novisible + label {
width:200px;
height:200px;
border-radius:50%;
border:2px solid #999;
display:inline-flex;
justify-content:center;
align-items:center;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<input type="file" class="novisible" id="file_upload">
<label for="file_upload" class="btn btn-md btn-teak"><i class="fa fa-upload"></i> <span>Upload</span></label>
Have you tried putting your icon in a label ?
Personnaly I do like that (with Ember.js)
<input type='file' (change)="readUrl($event)"id="uploadinput">
<label for="uploadinput">
<i class="fa fa-pencil-square-o" for="uploadinput" id="pencilicon" aria-hidden="true"></i>
<span>{{uploadLabel}}</span>
<!-- This is then switched to file name -->
</label>
CSS :
input[type="file"] {
position: absolute;
left: -9999%;
& + label {
// your label style
}
}
Fits your method is attached to input wich have z-index -1, it's impossible to click it now.
Change z-index to 999 and click on the top border of the circle.
Your method should be run when you click on the circle, not input.

Place icon inside submit button using Bootstrap 3

I am trying to achieve the effect as shown in below screenshot using Bootstrap 3.
As you can see, the search button is both:
1) inside the input
2) styled with a glyphicon so as to not appear like a "button".
How can I achieve a similar effect with Bootstrap 3? I would like to place a button with a magnifying glass glyphicon at the end of a text input, however the button keeps appearing below the input as opposed to inside of it.
A wrapper div with position: relative; then positioning the submit button on top using position: absolute;. Like this:
http://jsfiddle.net/VtP5k/
HTML
<form>
<div id="search">
<input type="text" />
<button type="sutmit">Search</button>
</div>
</form>
CSS
#search {
position: relative;
width: 200px;
}
#search input {
width: 194px;
}
#search button {
position: absolute;
top: 0;
right: 0;
margin: 3px 0;
}
Try this.
In bootstrap you have to use button type submit instead of input type;
Both works fine! use button in bootstrap!
div {
padding: 15px;
background: #000;
}
.btn {
text-align: left !important;
font-size: 12px !important;
padding: 20px 12px !important;
width: 200px !important;
color: #888 !important;
}
<link href="http://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css" rel="stylesheet" />
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" />
<div>
<button type="submit" class="btn btn-default">
awesomeness <span class="glyphicon glyphicon-search pull-right"></span>
</button>
<div>
Or see this fiddle
<button type="submit" class="btn btn-default">
Awesomeness <span class="glyphicon glyphicon-search"></span>
</button>
The problem is because the button is adhering to the normal flow of html and thus appears below the first element. What you need to do is wrap both the input and search button in an div and then make the search button absolute positioning. Then you can ad some jQuery functionality on a click function to achieve an event is needs be.
<html>
<body>
<div>
<input type="text" value="test"/>
<span id="search" class="absolute">x</span>
</div>
<style>
.absolute {
position:absolute;
top:9px;
left:115px;
}
</style>
<script>
$(document).on('click','#search',function(){
//some functionality
}
</script>
</body>
</html>