search

Home  >  Q&A  >  body text

css3选择器能否区分有输入与无输入的input?

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

PHP中文网PHP中文网2788 days ago541

reply all(3)I'll reply

  • 黄舟

    黄舟2017-04-17 11:09:14

    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>
    

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 11:09:14

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

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 11:09:14

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

    reply
    0
  • Cancelreply