Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do text inputs have extra padding?

I'm trying to overlay text on an <input type="text"> (for cross-browser placeholder support). I've found that my positioning is always off by a couple of pixels, because of some kind of padding which can't be removed by setting padding: 0;. The suggestions here and here do not solve the problem.

You can see this padding in the following screenshot from Chrome, as the white space between the blue highlight and the yellow border:

enter image description here

How can I a) remove this space; or b) measure it using Javascript?

like image 336
1'' Avatar asked Aug 24 '13 22:08

1''


People also ask

How give space between input with CSS?

The break tag is meant for single line breaks, and not more than one in a row. If you want to add extra whitespace between pieces of text, use CSS padding and margins instead for cleaner code. Or, you can use an HTML <p> tag, as we'll see next.

How to give space between textbox in HTML?

Just add the col-xs-offset-2 class to your second input. This class adds margin-left to the element, and keep the horizontal line you need.

Is padding added to height?

. height() does not include padding (even where box-sizing: border-box) . innerHeight() includes padding but not border.

How to set length of input number in HTML?

Input value length You can specify a minimum length (in characters) for the entered value using the minlength attribute; similarly, use maxlength to set the maximum length of the entered value, in characters. The example below requires that the entered value be 4–8 characters in length.


1 Answers

If you replace the default borders with your own, the padding goes away (at least for me, on Chrome/Mac):

enter image description here

This is the CSS I used:

input {
    padding: 0;
    outline: none;
    border: 1px solid red;
}

http://jsfiddle.net/NZZ5B/

like image 181
bfavaretto Avatar answered Oct 25 '22 05:10

bfavaretto