How can I implement Stack Overflow-like watermarks in forms?

后端 未结 5 1795
天涯浪人
天涯浪人 2020-12-28 10:28

I remember seeing a tutorial somewhere that talks of how to style your input forms in a more “usable” way.

Essentially, you have a placeholder value and when you ent

5条回答
  •  再見小時候
    2020-12-28 10:53

    I wrote this example which I—for lack of a better name—called persistent placeholders.

    It requires a little more markup, a div wrapping a label and input, but that solves a lot of other problems (like placeholders getting into your form data or password fields not working) and the actual markup is very clean to read. You end up with something like this:

    and after including the CSS and JS, it just works.

提交回复
热议问题