How to put icon inside an input box - html

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.

Related

How to add icon inside the input field with the placeholder text

How do I add an icon as the placeholder text inside an input field?
The icon is placed outside of the input field. I tried moving it using padding and margin, but I can't seem to position it exactly where I want it.
Your best option is either using CSS Grid or Flexbox to center the icon within a wrapper element.
You can read more about Grid here:
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout
And you can read more about Flexbox here:
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout
Here is an example using Grid:
body {
background: #F5F5F6;
}
label {
display: grid;
grid-template: 1fr / auto 1fr;
gap: 12px;
border: 1px solid #CFD5DB;
border-radius: 5px;
background: #fafafa;
padding: 12px;
color: #6C757D;
cursor: text;
}
label:focus-within {
border: 1px solid #000;
}
label>input {
outline: none;
border: none;
background: transparent;
}
<label>
<svg viewBox="0 0 24 24" width="24" height="24" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round" class="css-i6dzq1">
<circle cx="11" cy="11" r="8"></circle>
<line x1="21" y1="21" x2="16.65" y2="16.65"></line>
</svg>
<input placeholder="Enter Hotel name" type="search" />
</label>
A couple of important things to note about this example:
I've used a label element to wrap the input. This gives us the behavior of clicking the icon to focus the input field without needing to use javascript.
I've used input[type=search] because that is more semantically correct for your usage, and will aid users of screen readers in understanding the purpose of the text field.
I've used the :focus-within pseudo-selector to target and style the label when its child input is focused.
I've opted to use an svg icon but an img based icon will work just as well.
I could've used Flexbox just as easily but I wanted to use the gap property on the wrapping label instead of setting a margin on the icon or input. gap also works with Flexbox the same way it does with Grid except that Safari only supports gap on Grid layouts. If you opt for the Flexbox method, use a margin on one of the child elements instead of gap.
If you are using bootstrap4/bootstrap5 you can do easily
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.0/css/all.css" integrity="sha384-lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ" crossorigin="anonymous">
<div class="container">
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text">
<i class="fas fa-search"></i>
</div>
</div>
<input type="text" placeholder="search here" class="form-control" name="search" />
</div>
</div>
Check this
Place the two inline controls (the image and the input) into a container (e.g. a Div).
The container must be styled position:relative
Style the inline elements as position:absolute; top:0; left:0, which will place them one-on-top-of-the-other. Then use z-index to decide which element is on top and which is below.
Then a bit of padding, so that the input text is pushed over to the right to make room for the image... and you have it.
The border-radius is not necessary - it only rounds the corners of the image.
.iwi{
position:relative;
}
img,input{position:absolute;top:0;left:0;}
input{
z-index:1;
font-size:1.3rem;
padding: 3px 5px;
padding-left:25px;
}
img{
z-index:2;
margin-top:7px;
margin-left:3px;
border-radius: 20px;
}
::placeholder{
color: #ddd;
}
<div class="iwi">
<img src="https://placekitten.com/20/20" />
<input type="text" placeholder="Name the kitten" />
</div>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Add icon library -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
body {font-family: Arial, Helvetica, sans-serif;}
* {box-sizing: border-box;}
.input-container {
display: -ms-flexbox; /* IE10 */
display: flex;
width: 100%;
margin-bottom: 15px;
}
.icon {
padding: 10px;
background: dodgerblue;
color: white;
min-width: 50px;
text-align: center;
}
.input-field {
width: 100%;
padding: 10px;
outline: none;
}
.input-field:focus {
border: 2px solid dodgerblue;
}
/* Set a style for the submit button */
.btn {
background-color: dodgerblue;
color: white;
padding: 15px 20px;
border: none;
cursor: pointer;
width: 100%;
opacity: 0.9;
}
.btn:hover {
opacity: 1;
}
</style>
</head>
<body>
<form action="/action_page.php" style="max-width:500px;margin:auto">
<h2>Register Form</h2>
<div class="input-container">
<i class="fa fa-user icon"></i>
<input class="input-field" type="text" placeholder="Username" name="usrnm">
</div>
<div class="input-container">
<i class="fa fa-envelope icon"></i>
<input class="input-field" type="text" placeholder="Email" name="email">
</div>
<div class="input-container">
<i class="fa fa-key icon"></i>
<input class="input-field" type="password" placeholder="Password" name="psw">
</div>
<button type="submit" class="btn">Register</button>
</form>
</body>
</html>

Use font-awesome icon inside input element

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>

Div not appearing in line with paragraph

I'm trying to get a div to appear in-line with a <p> but for some reason it keeps skipping whenever it's generated. I need "Normal" to appear on the same line as "condition is:" but it's showing up on the next line.
/* CSS used here will be applied after bootstrap.css */
emergency {
color: #1D1060;
}
.alert-color {
color: #0F75BC;
}
.normal {
color: #6DC2E9;
}
.sys-cond-list ul li span {
color: #4B5D6B;
}
.sys-cond-list {
font-size: 12px;
}
#currState {
color: #3379A3;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="row">
<div class="col-sm-10" style="float: left">
<div class="system-cond" style="position: absolute">
<p style="text-align: left;">
Our current<br>condition is:
<strong><div id="currState">Normal</div></strong>
</p>
<p></p>
</div>
</div>
</div>
</div>
You could do something like below. Your elements need a float:left;.
Though there are far better ways to handle this. You should really change your HTML to use span instead of div to achieve the final solution.
/* CSS used here will be applied after bootstrap.css */emergency{
color: #1D1060;
}
.alert-color{
color: #0F75BC;
}
.normal{
color:#6DC2E9;
}
.sys-cond-list ul li span{
color: #4B5D6B;
}
.sys-cond-list{
font-size: 12px;
}
#currState{
color: #3379A3;
float:left;
margin:24px 0 0 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="col-sm-10" style="float: left">
<div class="system-cond" style="position: absolute">
<p style="text-align: left;float:left;">Our current<br>condition is: <strong>
</strong></p><div id="currState"><strong>Normal</strong></div><p></p>
</div>
</div>
</div>
</div>
Your <p> and #currState are block level elements, meaning they will take up the full-width of screen and so naturally "Normal" will be on next line.
A hack fix would be to set both elements to display: inline-block; but I think your code could use a restructuring. You are using inline styles and <br> when not necessary and <strong> tags when you can just modify the font-weight in css, you have empty <p> tags, etc.
p {
display: inline-block;
}
#currState{
display: inline-block;
}

Does <br> tag take some horizontal space?

I can't understand why it renders different two lines vertically separated with a br tag from two lines separated vertically making the first line a block level tag.
Here's an example:
https://jsfiddle.net/qzgeassf/
span.block {
display: block;
}
div {
text-align: center;
}
.border {
border: 1px solid black;
display: inline-block;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div>
<nav class="bottom-nav">
<span class="border">
<span>PORTFOLIO</span>
<br>
<span><i class="glyphicon glyphicon-circle-arrow-down"></i></span>
</span>
</nav>
</div>
<div>
<span class="border">
<span class="block">PORTFOLIO</span>
<span><i class="glyphicon glyphicon-circle-arrow-down"></i></span>
</span>
</div>
With Chrome dev tools I can't see what's taking that space at the end of the first line.
What you're seeing is white space in the non-block span. Remove the white space between the inline elements, and the widths are the same.
span.block {
display: block;
}
div {
text-align: center;
}
.border {
border: 1px solid black;
display: inline-block;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div>
<nav class="bottom-nav"><span class="border"><span>PORTFOLIO</span><br><span><i class="glyphicon glyphicon-circle-arrow-down"></i></span></span></nav>
</div>
<div>
<span class="border">
<span class="block">PORTFOLIO</span>
<span><i class="glyphicon glyphicon-circle-arrow-down"></i></span>
</span>
</div>

Owl Carousel 2 pagination dots were not diplayed

I am experiencing issue. The navigation components owl-nav and owl-dots are no longer wrapped with owl-controls.
<div class="owl-nav disabled">
<div class="owl-prev">prev</div>
<div class="owl-next">next</div>
</div>
<div class="owl-dots disabled">
<div class="owl-dot active"><span></span></div>
<div class="owl-dot"><span></span></div>
</div>
Demos show:
<div class="owl-controls">
<div class="owl-nav disabled">
<div class="owl-prev">prev</div>
<div class="owl-next">next</div>
</div>
<div class="owl-dots disabled">
<div class="owl-dot active"><span></span></div>
<div class="owl-dot"><span></span></div>
</div>
</div>
This is breaking the default css selections within owl-theme.
Can any one help me to solve this issue?
Thanks in advance.
Had the same problem, used some CSS-Styling my own:
.owl-dots {
text-align: center;
position: fixed;
bottom: 5px;
width: 100%;
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
-ms-backface-visibility: hidden;
backface-visibility: hidden;
}
.owl-dot {
border-radius: 50px;
height: 10px;
width: 10px;
display: inline-block;
background: rgba(127,127,127, 0.5);
margin-left: 5px;
margin-right: 5px;
}
.owl-dot.active {
background: rgba(127,127,127, 1);
}
If you don't want to overlaps the dots just use:
.owl-dots {
text-align: center;
}
You've to add owl-theme file also to get pagination dots.
$(document).ready(function(){
$('#demoCarousel').owlCarousel({
loop:true,
margin:10,
nav:true,
dots: true // if you don't want dots, change to false
});
});
#demoCarousel .item {
height: 10rem;
background: #4DC7A0;
padding: 1rem;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/assets/owl.carousel.min.css" type="text/css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/assets/owl.theme.default.css" type="text/css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/owl.carousel.min.js"></script>
<div class="owl-carousel owl-theme" id="demoCarousel">
<div class="item"><h4>1</h4></div>
<div class="item"><h4>2</h4></div>
<div class="item"><h4>3</h4></div>
<div class="item"><h4>4</h4></div>
<div class="item"><h4>5</h4></div>
<div class="item"><h4>6</h4></div>
<div class="item"><h4>7</h4></div>
<div class="item"><h4>8</h4></div>
<div class="item"><h4>9</h4></div>
<div class="item"><h4>10</h4></div>
<div class="item"><h4>11</h4></div>
<div class="item"><h4>12</h4></div>
</div>
I had same issue, Add more slides and dots will appear.