How to create a label inside an <input> element?

后端 未结 13 584
悲哀的现实
悲哀的现实 2021-01-29 22:54

I would like to insert a descriptive text inside an input element that disappers when the user click on it.

I know it is a very common trick, but I do not know how to do

13条回答
  •  温柔的废话
    2021-01-29 23:26

    In my opinion, the best solution involves neither images nor using the input's default value. Rather, it looks something like David Dorward's solution.

    It's easy to implement and degrades nicely for screen readers and users with no javascript.

    Take a look at the two examples here: http://attardi.org/labels/

    I usually use the second method (labels2) on my forms.

提交回复
热议问题