是否可以在div标签中添加占位符 [英] Is it possible to add placeholder in div tag
本文介绍了是否可以在div标签中添加占位符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我的 div
元素为空时,我想向用户显示一些文本。
尝试向我的占位符属性> div
,但文字未显示。
< div placeholder = > < / div>
如果我的 div
元素为空?
解决方案
使用javascript有很多选项,但如果你想在css.Try :
html:
< ; div contentEditable = true data-text =在这里输入文字>< / div>
[contentEditable = true]:empty:not(:focus):before {
content:attr(data-text)
}
I would like to display some text to the user when my
div
element is empty.I have tried adding a placeholder attribute to my
div
but the text is not being displayed.<div placeholder="Enter the text"> </div>
How can I display a message when my
div
element is empty?解决方案There are lot of options using javascript, but if you want to do it in css.Try this:
html:
<div contentEditable=true data-text="Enter text here"></div>
css:
[contentEditable=true]:empty:not(:focus):before{ content:attr(data-text) }
这篇关于是否可以在div标签中添加占位符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文