Chrome, FF, ie input the cursor element cannot be centered

Source: Internet
Author: User
Background input CSS style:
{            height:50px;width:386px;border:0;position:absolute;top:0;left:0; padding:0px;            line-height:50px;font-size:14px;.border-left-radius(4px);        }

 

You can try it. When Chrome is opened, the cursor appears in the upper left corner of the input element. Instead of centered as expected. The reasons for this are as follows:

  • IE: The cursor height is consistent with font-size regardless of whether the row contains text.
  • FF: When the row contains text, the cursor height is the same as font-size. When this row has no text, the cursor height is the same as the input height.
  • Chrome: When the row has no text, the cursor height is the same as line-height; when the row has text, the cursor height ranges from the top of the input to the bottom of the text (both cases are when line-height is set). If line-height is not set, it is consistent with font-size.
Solution:

Set line-height to a relatively small value, and use padding to center the vertical direction:

{            height:50px;width:386px;border:0;position:absolute;top:0;left:0; padding:16px 0 16px 4px;            line-height:18px;font-size:14px;.border-left-radius(4px);        }

 

Chrome, FF, ie input the cursor element cannot be centered

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.