html - How do you style a text input so that there's an icon on the left without using background-image? -


i'm trying create text input similar username , password input shown in pearson's testnav login (ignore yellow box).

pearson's testnav login

to make icon on left, use background-image property. wondering if possible achieve same effect without using images. i've gotten pretty close, there 2 problems. border right of icon box rounded, , if click icon doesn't focus input. tried making input box background transparent , putting icon behind it, chrome overrides background color if site in password manager.

here's css/html of attempt: html:

<div class="field">   <input type="text">   <div class="icon">     <i class="fa fa-user"></i>   </div> </div> 

css:

.field input {     outline: none;     border: 0px solid #fff;     font-size: 14px;     padding: 5px 5px 5px 44px;     position: absolute;      width: 260px;     height: 40px;      box-sizing: border-box;     border: 1px solid #ccc;     border-radius: 5px;     box-shadow: 0px 0px 0px 0px rgba(186,213,232,1);      transition: border 0.5s ease-in-out 0s, box-shadow 0.3s ease-in-out 0s; }  .field input:focus {     border: 1px solid #2977ff;     box-shadow: 0px 0px 10px 2px rgba(186,213,232,1); }  .field .icon {   display: flex;     justify-content: center;     align-items: center;       height: 36px;     width: 36px;     padding: 0;     border: 1px solid #eee;     border-radius: 3px;     margin: 1px 0px 0px 1px;     position: absolute;     background-color: #eee; } 

try changing icon div label

<div class="field">   <input type="text" id="this-input">   <label class="icon" for="this-input">     <i class="fa fa-user"></i>   </label> </div> 

that way when clicked focuses element references (for="this-input")

to fix border radius. change icon style

border-radius: 3px; 

to

border-radius: 3px 0 0 3px; 

this starts top left corner , says 3px top left, 0 top right, 0 bottom right, , 3px bottom left borners


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -