0

I'm trying to create an input with an icon indicating its purpose, but it's not rendering how I like: enter image description here

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.

K. Russell Smith
  • 133
  • 1
  • 11

2 Answers2

0

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>
0

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.

L. Alejandro M.
  • 619
  • 6
  • 14