Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default input element size

The input element by default is size="20" if this is not defined inline or a CSS style rule is attributed to it.

How do you make the default the actual size of the value? For other elements:

<div style="display: inline; width: auto;">
    The box will only fit the width of it's content
</div>

width: auto is all you need. I cannot put a defined width since the value may be longer. For example:

<input id="short" type="text" value="1000" />
<input id="long" type="text" value=" Areally long name is in this input field." />

I want #short to be the size of 1000 (essentially size="4" + the padding) but the #long to be as long as needed. These inputs are coming in programatically so I can't simply put a short class on the one's I want short and a long class on the one's I want long. I would really just like it if I could put:

input { width: auto; }

Anyway to do this?

like image 442
o_O Avatar asked Jul 31 '12 20:07

o_O


People also ask

What is default size of input in HTML?

The Input Text size Property in HTML DOM is used to set or return the value of the size attribute of an Input Text Field. The size attribute is used to define the width of a text field. Its default value is 20.

What is default height of input?

The input element by default is size="20" if this is not defined inline or a CSS style rule is attributed to it.

What is the default value of input?

Definition and Usage Note: The default value is the value specified in the HTML value attribute. The difference between the defaultValue and value property, is that defaultValue contains the default value, while value contains the current value after some changes have been made.


1 Answers

The input element by default is size="20"

This "default size" depends on the browser, the version and your OS. It is not possible to do this in inline styles.

the best solution is to set width and padding so it adds up to 100%

input {
  width: 98%;
  padding: 1%;
}

then set it to absolute left and right 0

<fieldset>
    <input type="text" />
</fieldset>

finally add this css

<style type="text/css">
    fieldset {
      position: relative;
    }

    input {
        position: absolute;
        left: 0;
        right: 0;
    }
</style>
like image 154
Sato Avatar answered Oct 02 '22 18:10

Sato