Тег input, атрибут type

Атрибут type

Сообщает браузеру, к какому типу относится элемент формы.

Синтаксис

Обязательный атрибут

Значения

В табл. 1 перечислены возможные значения атрибута type и получаемый вид поля формы.

Табл. 1. Значения type

Тип Описание Вид
button Кнопка.
checkbox Флажки. Позволяют выбрать более одного варианта из предложенных. Пиво Чай Кофе
file Поле для ввода имени файла, который пересылается на сервер.
hidden Скрытое поле. Оно никак не отображается на веб-странице.
image Поле с изображением. При нажатии на рисунок данные формы отправляются на сервер.
password Обычное текстовое поле, но отличается от него тем, что все символы показываются звездочками. Предназначено для того, чтобы никто не подглядел вводимый пароль.
radio Переключатели. Используются, когда следует выбрать один вариант из нескольких предложенных. Пиво Чай Кофе
reset Кнопка для возвращения данных формы в первоначальное значение.
submit Кнопка для отправки данных формы на сервер.
text Текстовое поле. Предназначено для ввода символов с помощью клавиатуры.
Читайте также:  Unexpected eof while parsing python ошибка

В HTML5 добавлены новые значения, представленные в табл. 2.

Табл. 2. Значения type в HTML5

Тип Описание
color Виджет для выбора цвета.
date Поле для выбора календарной даты.
datetime Указание даты и времени.
datetime-local Указание местной даты и времени.
email Для адресов электронной почты.
number Ввод чисел.
range Ползунок для выбора чисел в указанном диапазоне.
search Поле для поиска.
tel Для телефонных номеров.
time Для времени.
url Для веб-адресов.
month Выбор месяца.
week Выбор недели.

Поддержка этих значений браузерами показана в табл. 3.

Табл. 3. Поддержка браузерами значений HTML5

Значение Internet Explorer Chrome Opera Safari Firefox Android iOS
color 21.0+ 11.01+
date 5.0+ 10.62+ 5.0+ 5.0+
datetime 5.0+ 10.62+ 5.0+ 5.0+
datetime-local 5.0+ 10.62+ 5.0+ 5.0+
email 10.0 5.0+ 10.62+ 5.0+ 4.0+ 2.3+ 3.1+
month 5.0+ 10.62+ 5.0+ 5.0+
number 10.0 6.0+ 10.62+ 5.0+ 2.3+ 4.0+
range 10.0 5.0+ 10.62+ 5.0+ 23.0+ 5.0+
search 10.0 5.0+ 11.01+ 5.0+ 4.0+ 4.0+
tel 10.0 5.0+ 11.01+ 5.0+ 4.0+ 3.1+
time 5.0+ 10.62+ 5.0+ 5.0+
url 10.0 5.0+ 10.62+ 5.0+ 4.0+ 2.3+ 3.1+
week 5.0+ 10.62+ 5.0+ 5.0+

Значение по умолчанию

       

Пиво Чай Кофе

       

Введите число от 1 до 10

Источник

HTML Input Types

This chapter describes the different types for the HTML element.

HTML Input Types

Here are the different input types you can use in HTML:

Tip: The default value of the type attribute is «text».

Input Type Text

defines a single-line text input field:

Example

This is how the HTML code above will be displayed in a browser:

Input Type Password

defines a password field:

Example

This is how the HTML code above will be displayed in a browser:

The characters in a password field are masked (shown as asterisks or circles).

Input Type Submit

defines a button for submitting form data to a form-handler.

The form-handler is typically a server page with a script for processing input data.

The form-handler is specified in the form’s action attribute:

Example

This is how the HTML code above will be displayed in a browser:

If you omit the submit button’s value attribute, the button will get a default text:

Example

Input Type Reset

defines a reset button that will reset all form values to their default values:

Example

This is how the HTML code above will be displayed in a browser:

If you change the input values and then click the «Reset» button, the form-data will be reset to the default values.

Input Type Radio

defines a radio button.

Radio buttons let a user select ONLY ONE of a limited number of choices:

Example

Choose your favorite Web language:

This is how the HTML code above will be displayed in a browser:

Input Type Checkbox

defines a checkbox.

Checkboxes let a user select ZERO or MORE options of a limited number of choices.

Example

This is how the HTML code above will be displayed in a browser:

I have a bike
I have a car
I have a boat

Input Type Button

defines a button:

Example

This is how the HTML code above will be displayed in a browser:

Input Type Color

The is used for input fields that should contain a color.

Depending on browser support, a color picker can show up in the input field.

Example

Input Type Date

The is used for input fields that should contain a date.

Depending on browser support, a date picker can show up in the input field.

Example

You can also use the min and max attributes to add restrictions to dates:

Example

Input Type Datetime-local

The specifies a date and time input field, with no time zone.

Depending on browser support, a date picker can show up in the input field.

Example

Input Type Email

The is used for input fields that should contain an e-mail address.

Depending on browser support, the e-mail address can be automatically validated when submitted.

Some smartphones recognize the email type, and add «.com» to the keyboard to match email input.

Example

Input Type Image

The defines an image as a submit button.

The path to the image is specified in the src attribute.

Example

Input Type File

The defines a file-select field and a «Browse» button for file uploads.

Example

Input Type Hidden

The defines a hidden input field (not visible to a user).

A hidden field lets web developers include data that cannot be seen or modified by users when a form is submitted.

A hidden field often stores what database record that needs to be updated when the form is submitted.

Note: While the value is not displayed to the user in the page’s content, it is visible (and can be edited) using any browser’s developer tools or «View Source» functionality. Do not use hidden inputs as a form of security!

Example

Input Type Month

The allows the user to select a month and year.

Depending on browser support, a date picker can show up in the input field.

Example

Input Type Number

The defines a numeric input field.

You can also set restrictions on what numbers are accepted.

The following example displays a numeric input field, where you can enter a value from 1 to 5:

Example

Input Restrictions

Here is a list of some common input restrictions:

Attribute Description
checked Specifies that an input field should be pre-selected when the page loads (for type=»checkbox» or type=»radio»)
disabled Specifies that an input field should be disabled
max Specifies the maximum value for an input field
maxlength Specifies the maximum number of character for an input field
min Specifies the minimum value for an input field
pattern Specifies a regular expression to check the input value against
readonly Specifies that an input field is read only (cannot be changed)
required Specifies that an input field is required (must be filled out)
size Specifies the width (in characters) of an input field
step Specifies the legal number intervals for an input field
value Specifies the default value for an input field

You will learn more about input restrictions in the next chapter.

The following example displays a numeric input field, where you can enter a value from 0 to 100, in steps of 10. The default value is 30:

Example

Input Type Range

The defines a control for entering a number whose exact value is not important (like a slider control). Default range is 0 to 100. However, you can set restrictions on what numbers are accepted with the min , max , and step attributes:

Example

The is used for search fields (a search field behaves like a regular text field).

Example

Input Type Tel

The is used for input fields that should contain a telephone number.

Example

Input Type Time

The allows the user to select a time (no time zone).

Depending on browser support, a time picker can show up in the input field.

Example

Input Type Url

The is used for input fields that should contain a URL address.

Depending on browser support, the url field can be automatically validated when submitted.

Some smartphones recognize the url type, and adds «.com» to the keyboard to match url input.

Example

Input Type Week

The allows the user to select a week and year.

Depending on browser support, a date picker can show up in the input field.

Источник

HTML input inside table cell

enter image description here

I have a table that will contain many columns and I would like to add input fields inside header cells, but I would like for the input to fit the width depending on the body content. This is how it looks like without the input fields: And this is how it looks like with the input fields: As it can be seen, columns like ‘index’ and ‘Is Active’ are taking too much space, and I would like to maintain the first layout as much as possible. I tried to set input width to 100% and auto, but it doesn’t seem to help very much. The current css looks like:

.table < font-family: Arial, Helvetica, sans-serif; >.table thead < position: sticky; top: 0; >.table thead th < border: 1px solid #e4eff8; background: white; cursor: pointer; >.table thead th.header-label < cursor: pointer; background: linear-gradient(0deg, #e4eff8, #4578a2 5%, #e4eff8 150%); color: white; border: 1px solid white; >.table th, .table td < padding: 0.2rem 0.5rem; text-align: center; >.table td < border: 1px solid #e4eff8; >.table input
 
Index Name Phone Company Registered Is Active
0 Paige Bean +1 (871) 458-2959 MOREGANIC 2018-12-27T11:28:50 -01:00 false
1 Knox Holman +1 (880) 497-2808 MAINELAND 2017-05-07T02:54:22 -01:00 false
2 Brandy Colon +1 (969) 513-2827 NEXGENE 2017-06-07T06:42:31 -00:00 true
3 Suzette Austin +1 (863) 445-3604 JETSILK 2015-10-24T11:10:41 -01:00 true
4 Downs Cain +1 (822) 574-2617 INSECTUS 2017-10-19T08:18:09 -01:00 true
5 Michael Yang +1 (875) 492-3905 DELPHIDE 2016-08-15T01:31:55 -01:00 false

enter image description here

So how do you make this happen with pure css, without hard coding the width of each column?

Источник

Оцените статью