css3选择器能否区分有输入与无输入的input?
PHP中文网
PHP中文网 2017-04-17 11:07:14
0
3
537

例如用伪类:focus可以区分获取焦点与无焦点的元素,并且是动态的
我想在页面input没有输入东西时一种表现,当用户一输入时又一种表现,动态的,能用选择器区分开来吗?

PHP中文网
PHP中文网

认证0级讲师

reply all(3)
黄舟

There seems to be no input, but the placeholder can be partially customized, such as setting a background color, etc. This also achieves the purpose of distinguishing whether there is content using pure CSS.

::-webkit-input-placeholder {
    color: #000;
    background: red;
    border: 1px solid #000;
}

However, you can also consider using <p contenteditable></p> and p:empty to implement the text box and its status with or without input.

<style>
    p:empty {
        color: #999;
    }
    p:empty::before {
        content: "Empty";
    }
</style>

<p contenteditable></p>
小葫芦

No, it is more appropriate to use JS to achieve this effect.

大家讲道理

It doesn’t seem to exist at the moment, but if it does, it will definitely be more convenient than JS

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template