div 实现 placeholder

96
作者 静候那一米阳光
2017.08.12 13:33 字数 16
<style>
[placeholder]:empty:before {
  content: attr(placeholder);
  color: #999;
}

[placeholder]:empty:focus:before {
  content: "";
}
</style>

<div placeholder="please input"></div>

配合 contenteditable

<div contenteditable="true" placeholder="please input..." style="border:1px solid #ccc"></div>

拓展阅读:Placeholder for contenteditable div——Stack Overflow

前端