DIV用伪元素实现CSS的placeholder效果

2021-03-17 09:42:21

placeholder 是HTML5中input的属性,但该属性并不支持除input以外的元素

 

但我们可以使用Css before选择器来实现完全相同的效果



<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Div+placeholder</title>    <style>    .rich{        color:balck;        width:100px;        height:100px;        border: 1px solid red;        margin: 20px 50%;    }    /*为空时显示 element attribute content*/    .rich:empty:before{        content: attr(placeholder);   /* element attribute*/        /*content: 'this is content';*/        color:#red;    }    /*焦点时内容为空*/    .rich:focus:before{        content:none;    }    </style></head><body>    <div class='rich' contenteditable="true" placeholder='当 element 内容为空时,我就会出现'></div></body></html>

  

 效果:

 


  • 2019-04-25 15:40:16

    JS对象是否拥有某属性如何判断

    原型链上继承过来的属性无法通过hasOwnProperty检测到,返回false。 需注意的是,虽然in能检测到原型链的属性,但for in通常却不行。

  • 2019-04-30 11:23:36

    elasticsearch和analysis-ik的安装使用

    全文搜索和中文分词主要介绍了两组全文搜索加中文分词方案; TNTSearch+jieba-php这套组合对于博客这类的小项目基本够用了;

  • 2019-04-30 11:42:24

    php7+laravel+coreseek(sphinx)中文搜索初步实现(Linux)

    官网www.coreseek.cn已不能下载,所以需从网上找资源, 注意的一点是,笔者安装coreseek-3.2.14版本后,使用时提示client版本高于server版本的错误, php的sphinx扩展,为使用者,为client;coreseek是系统服务,为server