About adjusting the input cursor size in input

Source: Internet
Author: User

I encountered a problem in the project before.

The input text box is simulated with a background image. It sets the same height as line-height to enable the input text to be centered,

When you click input, the input cursor is actually as high as the height of input, but when you start to input text, the cursor becomes as high as the text,

The cursor is as high as the input height in chrome,

The cursor in IE is the same as the text size.

I have never figured out why this is the case. Today, I only learned the reason after hearing a discussion from Luo yunli.

The preliminary conclusions 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 a small height for the input height, and then fill it with padding, which can basically solve the problem of all browsers.

  input  {  
height : 16px ;
padding : 4px 0px ;
font-size : 12px ;
}

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.