HTML - DIV的占位符

时间:2015-07-09 10:06:00

标签: html css html5

我希望我的DIV标记有一个占位符,当DIV没有聚焦且没有文本时会出现。我知道这有多个SO链接,但是每个人提供的通用解决方案似乎对我没用。以下是HTML和CSS。为什么这不起作用?

代码:



#composeBody:empty:not(:focus):before{
  content:attr(data-placeholder);
  color: #555;
  display: block; /* For Firefox */
}

<div id="composeBody" data-placeholder="Start composing your message..." contenteditable="true"></div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

there are lot of options using javascript, but if you want to do it in css.Try this:[contentEditable=true]:empty:not(:focus):before{
    content:attr(data-text)
}

html: div( contentEditable=true data-text="Enter text here")(/div)