glyphicons inside inputs and inside alerts - html

Hello I'm having a hard time trying to put a glyphicon inside input tags, I've tried several codes from here and other sites but still can't get it..
this is what I have:
<div class="form-group">
<label for="cedula">Cedula:</label>
<div class="inner-addon left-addon">
<i class="glyphicon glyphicon-user"></i>
<input type="text" class="form-control" id="cedula" name="cedula" placeholder="Numero De Cedula" required="true" autofocus="true" maxlength="9">
</div>
</div>
and this is my css file:
/* enable absolute positioning */
.inner-addon {
position: relative;
}
/* style glyph */
.inner-addon .glyphicon {
position: absolute;
padding: 10px;
pointer-events: none;
}
/* align glyph */
.left-addon .glyphicon { left: 0px;}
.right-addon .glyphicon { right: 0px;}
/* add padding */
.left-addon input { padding-left: 30px; }
.right-addon input { padding-right: 30px; }
BUT I keep getting this weird symbol outside the input:
and following the Bootstrap documentation I'm trying to implement the glyphicon inside the alert box:
if( $errores !== ""){
echo '<div class="alert alert-danger">';
echo '<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>';
echo $errores;
echo '</div>';
}
but again weird symbol appears:

Just use only this (no additional css needed):
<div class="form-group has-feedback">
<label class="control-label" >Cedula:</label>
<input type="text" class="form-control" id="cedula" name="cedula" placeholder="Numero De Cedula" required="true" autofocus="true" maxlength="9">
<i class="glyphicon glyphicon-user form-control-feedback"></i>
</div>

use this one:
<div class="input-group">
<span class="input-group-addon" id="basic-addon1"><i class="glyphicon glyphicon-user" ></i></span>
<input type="text" class="form-control" id="cedula" name="cedula" placeholder="Numero De Cedula" required="true" autofocus="true" maxlength="9">
</div>

Related

Can't render input inline

I'm trying to create an input with an icon indicating its purpose, but it's not rendering how I like:
I want the input at the same level as the icon, however, dispite my best efforts:
.field
{
margin: auto;
border-radius: 10px;
width: 67%;
white-space: nowrap;
overflow-x: auto;
}
.field input, .field label
{
display: inline-block !important;
margin: 0;
padding: 0;
}
<div class = 'field w3-bar w3-center w3-border w3-border-green'>
<label class='w3-bar-item w3-left w3-border-right w3-border-green fas fa-user' for='username'></label>
<input class="w3-bar-item w3-right w3-input w3-border-green w3-hover-border-green no-box" id="username" name="username" required type="text" value="">
</div>
— it still renders on a new line! Note that I'm using w3.css and font-awesome. Is there something I'm missing? Thank you.
How about like this?
.custom-input{
display:inline-block;
margin-left:12px;
}
.input-component{
border:3px solid teal;
padding:8px;
padding-left:30px;
}
.input-icon{
color:teal;
position:absolute;
margin-right:-30px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<div class="custom-input">
<span class="glyphicon glyphicon-user input-icon"></span>
<input class="input-component" placeholder="username...">
</div>
<div class="custom-input">
<span class="glyphicon glyphicon-calendar input-icon"></span>
<input class="input-component" type="date">
</div>
<br>
<br>
<div class="custom-input">
<span class="glyphicon glyphicon-lock input-icon"></span>
<input class="input-component" type="password" placeholder="password"/>
</div>
You can minimize the code to something like this:
<div style="width: 67%;display:flex; align-items:center;" class ="w3-padding w3-margin w3-border w3-border-green w3-round-large">
<label style="width:10%" class="w3-center w3-border-right w3-border-green fa fa-user" for="username"></label>
<input style="width:80% " class="w3-input" id="username" name="username" required type="text" value="">
</div>
And you don't need define the class "field" and the others.

Custom input style with a icon inside and button in the right

I am trying to get a custom input style have a glyph icon inside and have a button on the right that says go.
Here is my js fiddle with it. jsfiddle
<div class="form-group">
<div class="icon-addon addon-sm">
<input type="text" placeholder="Search All Orders" class="form-control" id="Order Search">
<label for="email" class="glyphicon glyphicon-search" rel="tooltip" title="email"></label>
</div>
</div>
The problem i am having is when i try to add the button on the right it makes the icon disappear when the input is clicked.
Using your fiddle I simply added an absolutely positioned button into your search box. Perhaps this is what you were looking for?
Added button in HTML:
<input type="text" placeholder="Search All Orders" class="form-control" id="Order Search">
<label for="email" class="glyphicon glyphicon-search" rel="tooltip" title="email"></label>
<button class="button-go">go</button>
Button's CSS:
.button-go {
position: absolute;
right: 0;
top: 0;
height: 30px;
}
https://jsfiddle.net/t6295xrd/
Here is a Demo for what i understood from you i just add the button to your fiddle and add this css to position it on right.
#Order_Search {
padding-right:20px;
}
.go-btn {
position: absolute;
right: 3px;
margin-left: -2.5px;
top: 2px
}
and this is the html
<div class="form-group">
<div class="icon-addon addon-sm">
<input type="text" placeholder="Search All Orders" class="form-control" id="Order_Search">
<label for="email" class="glyphicon glyphicon-search" rel="tooltip" title="email"></label>
<button class="go-btn"> Go </button>
</div>

Boostrap glyphicon inside input not showing on hover

on my website, while hovering over the "Search" input or on focus, the glyphicon dissapears!
<div class="icon-addon addon-sm">
<input type="text" placeholder="Search (621 videos)" class="form-control" name="searchString" id="searchString">
<label for="searchString" class="glyphicon glyphicon-search" rel="tooltip" title="search"></label>
</div>
you have a problem here
.icon-addon .form-control:focus+.glyphicon, .icon-addon:hover .glyphicon, .icon-addon .form-control:focus+.fa, .icon-addon:hover .fa {
color: #fff;
}
remove .icon-addon:hover .glyphicon from above css or remove color or set difference color: #232323; Your choice.

Left div with fixed width and right div with fluid width

I have a situation where I cannot change the HTML and everything has to be done with CSS.**** In the image below you can see there are text on either side of the input box. I need to have all text to be on left side. The span containing the text has a fixed width of 30 pixels. And I need the input box to have a fluid width so that it will fill the rest of the container. I just added a background color to the first container for illustration purposes.
<div class="input-group input-prepend">
<input name="monthlyBudget" class="form-control" placeholder="0" required="" data-bind="number, live: monthlyBudget" data-parsley-min="50" data-parsley-max="5000" data-parsley-validation-threshold="1" data-parsley-trigger="keyup" data-parsley-errors-container="#affordabilityCalErrorBudget" type="text">
<span class="input-group-addon add-on">$</span>
</div>
Entire HTML for the form:
<form class="calculators-form-inputs no-submit" id="form-calculator-affordability" name="calculator-affordability" data-parsley-validate="">
<div class="calculators-info-text">
<h2>How Much Car Can I Afford?</h2>
<p>Great question. Fill in the boxes below to help with the answer and determine what price you can afford to pay for a car.</p>
</div>
<div class="calculators-form-field credit-amount">
<div class="calculators-labels">
<label>Your monthly budget <i class="label-tooltip icon-info-sign glyphicon glyphicon-info-sign" data-toggle="tooltip" data-placement="top" title="" data-original-title="Tooltip"></i>
<a class="calculators-helper-link" href="#" data-toggle="modal" data-target="#budgetCalModal">(Help me)</a>
</label>
</div>
<div class="calculators-sliders">
<input type="range" value="0" min="50" max="5000" step="50" tabindex="-1" data-bind="value: monthlyBudget">
</div>
<div class="calculators-inputs">
<div class="input-group input-prepend">
<span class="input-group-addon add-on">$</span>
<input name="monthlyBudget" class="form-control" type="text" placeholder="0" required="" data-bind="number, live: monthlyBudget" data-parsley-min="50" data-parsley-max="5000" data-parsley-validation-threshold="1" data-parsley-trigger="keyup" data-parsley-errors-container="#affordabilityCalErrorBudget">
</div>
</div>
<div class="calculators-inputs-error" id="affordabilityCalErrorBudget"></div>
</div>
<div class="calculators-form-field credit-term">
<div class="calculators-labels">
<label>Loan term<i class="label-tooltip icon-info-sign glyphicon glyphicon-info-sign" data-toggle="tooltip" data-placement="top" title="" data-original-title="Tooltip"></i>
</label>
</div>
<div class="calculators-sliders">
<input type="range" value="0" min="12" max="84" step="12" tabindex="-1" data-bind="value: loanTerm">
</div>
<div class="calculators-inputs">
<div class="input-group input-append">
<input name="loanTerm" class="form-control" type="text" placeholder="0" required="" data-bind="number, live: loanTerm" data-parsley-min="12" data-parsley-max="84" data-parsley-type="digits" data-parsley-validation-threshold="1" data-parsley-trigger="keyup" data-parsley-pattern="^(12|24|36|48|60|72|84)$" data-parsley-errors-container="#affordabilityCalErrorTerm">
<span class="input-group-addon add-on">mo</span>
</div>
</div>
<div class="calculators-inputs-error" id="affordabilityCalErrorTerm"></div>
</div>
<div class="calculators-form-field credit-apr">
<div class="calculators-labels">
<label>APR*<i class="label-tooltip icon-info-sign glyphicon glyphicon-info-sign" data-toggle="tooltip" data-placement="top" title="" data-original-title="Tooltip"></i>
</label>
</div>
<div class="calculators-sliders">
<input type="range" value="0" min="0" max="30" step="0.1" tabindex="-1" data-bind="value: interestRate">
</div>
<div class="calculators-inputs">
<div class="input-group input-append">
<input name="interestRate" class="form-control" type="text" placeholder="0" required="" data-bind="number, live: interestRate" data-parsley-min="0" data-parsley-max="30" data-parsley-validation-threshold="1" data-parsley-trigger="keyup" data-parsley-pattern="^[0-9]\d*(\.\d+)?$" data-parsley-maxlength="5" data-parsley-errors-container="#affordabilityCalErrorApr">
<span class="input-group-addon add-on">%</span>
</div>
</div>
<div class="calculators-inputs-error" id="affordabilityCalErrorApr"></div>
</div>
<div class="calculators-form-field credit-reduction">
<div class="calculators-labels">
<label>Down payment<i class="label-tooltip icon-info-sign glyphicon glyphicon-info-sign" data-toggle="tooltip" data-placement="top" title="" data-original-title="Tooltip"></i>
</label>
</div>
<div class="calculators-sliders">
<input type="range" value="0" min="0" max="20000" step="100" tabindex="-1" data-bind="value: dPayment">
</div>
<div class="calculators-inputs">
<div class="input-group input-prepend">
<span class="input-group-addon add-on">$</span>
<input name="downPayment" class="form-control" type="text" placeholder="0" data-bind="number, live: dPayment" data-parsley-min="0" data-parsley-max="20000" data-parsley-validation-threshold="1" data-parsley-trigger="keyup" data-parsley-errors-container="#affordabilityCalErrorDown">
</div>
</div>
<div class="calculators-inputs-error" id="affordabilityCalErrorDown"></div>
</div>
<div class="calculators-actions">
<div class="calculators-buttons">
<input type="submit" value="Calculate">
</div>
</div>
</form>
What I have now:
This is what I need:
The original table and table-cell solution - http://jsfiddle.net/0jvnryhx/1/
New solution due to the updates from #ChaniLastnamé http://jsfiddle.net/8pq6thr7/
.input-group {
margin-bottom: 20px;
position: relative;
overflow: hidden;
clear: both;
}
.add-on {
width: 30px;
position: absolute;
left: 0;
top: 0;
}
.form-control {
margin-left: 30px;
}
Then you can manually adjust the width of the input the boxes to make them fit the container (visually full width), everything needs to be fixed width though.
Should be simple enough to do with just a calc().
.form-control{
width: calc(100% - 30px);
}
Here is a CodePen
Can you support flexbox? If so this is your solution:
.input-group {
display: -webkit-flex;
display: flex;
-webkit-align-items: baseline;
align-items: baseline;
/* make it pretty */
background: lightgrey;
/* whatever width you want */
width: 300px;
}
.input-prepend span {
/* that width you said needed to be there */
width: 30px;
/* align the $ against the input */
text-align: end;
}
.input-prepend input {
/* use all the space */
width: 100%;
/* make the input after the $ in layout */
-webkit-order: 2;
order: 2;
}
<div class="input-group input-prepend">
<input name="monthlyBudget" class="form-control" placeholder="0" required="" data-bind="number, live: monthlyBudget" data-parsley-min="50" data-parsley-max="5000" data-parsley-validation-threshold="1" data-parsley-trigger="keyup" data-parsley-errors-container="#affordabilityCalErrorBudget" type="text">
<span class="input-group-addon add-on">$</span>
</div>
If the browsers you need do not support flexbox. There are a few options. First I really really hope you’re able to render the span before the input instead of after the way it is in the code you posted. You also need to ensure there are no spaces in your HTML as that will cause this issue. If this HTML comes from a pre-rendered output you probably won’t have that issue.
If you can make those tweaks to the HTML this is your solution:
.input-group {
/* make it pretty */
background: lightgrey;
/* whatever width you want */
width: 300px;
}
.input-prepend span {
/* can’t set width properly while inline */
display: inline-block;
/* that width you said needed to be there */
width: 30px;
/* align the $ against the input */
text-align: end;
}
.input-prepend input {
/* use all the space minus the 30px from above */
width: calc(100% - 30px);
/* change the way width is calculated */
box-sizing: border-box;
}
<div class="input-group input-prepend"><span class="input-group-addon add-on">$</span><input name="monthlyBudget" class="form-control" placeholder="0" required="" data-bind="number, live: monthlyBudget" data-parsley-min="50" data-parsley-max="5000" data-parsley-validation-threshold="1" data-parsley-trigger="keyup" data-parsley-errors-container="#affordabilityCalErrorBudget" type="text"></div>
Finally if you really seriously can’t touch your markup AND you can’t support flexbox. You can do this which is a bit hacky but in the scheme of things not horrible:
.input-group {
/* make it pretty */
background: lightgrey;
/* whatever width you want */
width: 300px;
position: relative;
}
.input-group span {
/* can’t set width properly while inline */
display: inline-block;
/* that width you said needed to be there */
width: 30px;
/* align the $ against the input */
text-align: end;
/* pull this out of flow */
position: absolute;
/* vertically align with input */
top: 2px;
}
.input-group input {
/* use all the space */
width: 100%;
/* allow space for $ */
margin-left: 34px;
}
<div class="input-group input-prepend">
<input name="monthlyBudget" class="form-control" placeholder="0" required="" data-bind="number, live: monthlyBudget" data-parsley-min="50" data-parsley-max="5000" data-parsley-validation-threshold="1" data-parsley-trigger="keyup" data-parsley-errors-container="#affordabilityCalErrorBudget" type="text">
<span class="input-group-addon add-on">$</span>
</div>
Hope that helps!

External CSS is not working

I am using external CSS for some style ,
my link tag is as follow ,
<link href="<%=request.getContextPath()%>/css2/form.css" rel="stylsheet" TYPE="text/css">
the CSS file has following content
#CHARSET "ISO-8859-1";
legend {
padding: 0;
margin-top:-20px;
margin-left: -20px;
margin-right:-40px;
margin-bottom: -9px;
border: 0;
color: #999999;
background-color: #918D8D;
}
.input-group{
margin-left:15px;
}
and I used these classes in jsp as follow,
<div class="form-group">
<label for="dob" class="control-label col-xs-4">Date Of
Birth(DOB) :</label>
<div class="col-xs-8">
<div class="col-lg-8 input-group date form_date1" data-date-format="dd MM yyyy" data-link-format="yyyy-mm-dd">
<input type="text" class="form-control " size="10" name="dob" id="date" ">
<span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
</div>
</div>
</div>
why it is not working , here i am trying to add margine to text box.
Not sure which css you want to apply to your textbox. But if you want to apply input-group to your textbox then update your input tag as mentioned below :
<input type="text" class="form-control input-group" size="10" name="dob" id="date" ">
and apply !important to the margin of css input-group as mentioned below :
.input-group{
margin-left:15px !important;
}