1

Why does my cursor start top right in this example?

See when I click inside the field, it's top right then when I type it moves to the centre. Any ideas why?

http://jsfiddle.net/2Ltm5adw/

HTML:

<label class="input">
    <span>Email address</span>
    <input type="text" />
</label>

CSS:

input, select, textarea {
    line-height:50px;
    width:100%;
    padding-left:20px;
    display: block;
}

.input span {
  position: absolute;
  z-index: 1;
  cursor: text;
  pointer-events: none;
  color: #999;
  /* Input padding + input border */
  padding: 7px;
  /* Firefox does not respond well to different line heights. Use padding instead. */
  line-height: 50px;
  /* This gives a little gap between the cursor and the label */
  margin-left: 2px;
}

.input input, .input textarea, .input select {
  z-index: 0;
  padding: 6px;
  margin: 0;
  font: inherit;
  line-height: 50px;
}
4
  • 2
    on FF it sits center - but i bet it's how some browsers render the line-height, why aren't you using placeholder="Email"? Commented Nov 19, 2014 at 12:24
  • removeline-height: 50px; set height instead Commented Nov 19, 2014 at 12:26
  • 1
    input type='email' will do some basic checks to see if the formatting is correct Commented Nov 19, 2014 at 12:30
  • Some people are confused with your goal. I guess you are just trying to style the standard input instead of creating your own input. As said by others, there's an issue in the line-height with some browsers. You can use height instead. Commented Nov 19, 2014 at 13:01

5 Answers 5

2

Because of the line-height. Replace it with height:

input,
select,
textarea {
  border: 2px solid $gray-lighter;
  border-bottom: 1px solid $gray-lighter;
  border-top: 1px solid $gray-lighter;
  height: 50px;
  /*replace with height*/
  width: 100%;
  padding-left: 20px;
  background: $white;
  display: block;
}
.input span {
  position: absolute;
  z-index: 1;
  cursor: text;
  pointer-events: none;
  color: #999;
  /* Input padding + input border */
  padding: 7px;
  /* Firefox does not respond well to different line heights. Use padding instead. */
  line-height: 50px;
  /* This gives a little gap between the cursor and the label */
  margin-left: 2px;
}
.input input,
.input textarea,
.input select {
  z-index: 0;
  padding: 6px;
  margin: 0;
  font: inherit;
  height: 50px;
  /*replace height*/
}
<label class="input">
  <span>Email address</span>
  <input type="text" />
</label>

Sign up to request clarification or add additional context in comments.

Comments

0

Demo

It's because of line-height. try height instead line-height.It works fine

.input input, .input textarea, .input select {
 z-index: 0;
 padding: 6px;
 margin: 0;
 font: inherit;
 height: 50px;
}

Comments

0

Just remove line-height from inputs and replace them with padding: 20px 7px;

.input span {
  position: absolute;
  z-index: 1;
  cursor: text;
  pointer-events: none;
  color: #999;
  /* Input padding + input border */
  padding: 7px;
  /* Firefox does not respond well to different line heights. Use padding instead. */
  line-height: 50px;
  /* This gives a little gap between the cursor and the label */
  margin-left: 2px;
}
.input input,
.input textarea,
.input select {
  z-index: 0;
  padding: 6px;
  margin: 0;
  font: inherit;
  padding: 20px 7px;
}
<label class="input">
  <span>Email address</span>
  <input type="text" />
</label>

Comments

0

Whats wrong with this ? Saves mucking around

<label for="emailID">Email Address : </label>
    
    <input type="email" id="emailID" placeholder="Your Email Address"/>

And stylable.

#emailID {width:300px;background-color:green;color:white;border-radius:5px;}
 <label for="emailID">Email Address : </label>
        
        <input type="email" id="emailID" placeholder="Your Email Address"/>

Comments

0

Here is your updated JSFiddle Link, Check out your issue has been solved or not !!

Changes Made:

.input span {
  padding: 20px;
  line-height: 25px;
}
.input input, .input textarea, .input select {
  padding: 20px;
  height: 25px;
}

1 Comment

Please ensure to include information in your answer as to what you have done to fix the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.