HTML text field's label showing in three lines

169 Views Asked by At

I have created a input text field and given a label to it using html but instead of showing label in one line I am facing problem that the label is showing in three lines.

label {
  display: inline-block;
  position: relative;
  width: 5px;
  top: 0px;
  left: -193px;
  color: #999;
  font-family: 'Helvetica', sans-serif;
  font-size: 16px;
  font-weight: lighter;
  z-index: 1;
  transition: all 0.2s ease-in;
}
<input type="text" name="verficationcode" required autocomplete="off">
<label for="verficationcode">Enter code here</label>

Image

4

There are 4 best solutions below

0
On

Comment out or adjust the width property:

label {
    display: inline-block;
    position: relative;
    /*width: 5px;*/
    top: 0px; 
    /*left: -193px;*/
    color: #999;
    font-family: 'Helvetica', sans-serif;
    font-size: 16px;
    font-weight: lighter;
    z-index: 1;
    transition: all 0.2s ease-in;
}
<input type="text" name="verficationcode" required autocomplete="off">
<label for="verficationcode">Enter code here</label>

0
On

try this css,

label{
    white-space:nowrap;
}

but you can use placeholder instead of label like this

<input type="text" name="verficationcode" required autocomplete="off" placeholder="Enter verification code here">
0
On

Change Position of html and using this css

label{
    display: inline-block;
    position: relative;
    top:0px; 
    padding-right:15px;
    color:#999;
    font-family:'Helvetica', sans-serif;
    font-size:16px;
    font-weight: lighter;
    z-index:1;
    transition: all 0.2s ease-in;
}

label{
    display: inline-block;
    position: relative;
    top:0px; 
    padding-right:15px;
    color:#999;
    font-family:'Helvetica', sans-serif;
    font-size:16px;
    font-weight: lighter;
    z-index:1;
    transition: all 0.2s ease-in;
}
<label for="verficationcode">Enter code here</label>
<input type="text" name="verficationcode" required autocomplete="off">

0
On

Please review below code. Remove position, left, top property from CSS that is not needed here.

label{
    display: inline-block;
    width: auto;
    color:#999;
    font-family:'Helvetica', sans-serif;
    font-size:16px;
    font-weight: lighter;
    z-index:1;
    transition: all 0.2s ease-in;
}
<input type="text" name="verficationcode" required autocomplete="off">
<label for="verficationcode">Enter code here</label>

May be it will help you. Thanks.