Is it possible to add placeholder in div tag

前端 未结 4 1229
南方客
南方客 2020-12-04 12:26

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 t

4条回答
  •  一向
    一向 (楼主)
    2020-12-04 12:53

    There are lot of options using javascript, but if you want to do it in css.Try this:

    html:

    css:

    [contentEditable=true]:empty:not(:focus):before{
        content:attr(data-text)
    }
    

    Demo

提交回复
热议问题