:not(:empty) CSS selector is not working?

后端 未结 11 1036
我寻月下人不归
我寻月下人不归 2020-11-28 06:22

I\'m having a heck of a time with this particular CSS selector which does not want to work when I add :not(:empty) to it. It seems to work fine with any combina

相关标签:
11条回答
  • 2020-11-28 06:34

    Since placeholder disappear on input, you can use:

    input:placeholder-shown{
        //rules for not empty input
    }
    
    0 讨论(0)
  • 2020-11-28 06:36

    Another pure CSS solution

    .form{
      position:relative;
      display:inline-block;
    }
    .form input{
      margin-top:10px;
    }
    .form label{
        position:absolute;
        left:0;
        top:0;
        opacity:0;
        transition:all 1s ease;
    }
    input:not(:placeholder-shown) + label{
        top:-10px;
        opacity:1;
    }
    <div class="form">
        <input type="text" id="inputFName" placeholder="Firstname">
        <label class="label" for="inputFName">Firstname</label>
    </div>
    <div class="form">
        <input type="text" id="inputLName" placeholder="Lastname">
        <label class="label" for="inputLName">Lastname</label>
    </div>

    0 讨论(0)
  • 2020-11-28 06:38

    It is possible with inline javascript onkeyup="this.setAttribute('value', this.value);" & input:not([value=""]):not(:focus):invalid

    Demo: http://jsfiddle.net/mhsyfvv9/

    input:not([value=""]):not(:focus):invalid{
      background-color: tomato;
    }
    <input 
      type="email" 
      value="" 
      placeholder="valid mail" 
      onchange="this.setAttribute('value', this.value);" />

    0 讨论(0)
  • 2020-11-28 06:38

    This should work in modern browsers:

    input[value]:not([value=""])
    

    It selects all inputs with value attribute and then select inputs with non empty value among them.

    0 讨论(0)
  • 2020-11-28 06:48

    pure css solution

    input::-webkit-input-placeholder {
        opacity: 1;
        -webkit-transition: opacity 0s;
        transition: opacity 0s;
        text-align: right;
    }
    /* Chrome <=56, Safari < 10 */
    input:-moz-placeholder {
        opacity: 1;
        -moz-transition: opacity 0s;
        transition: opacity 0s;
        text-align: right;
    }
    /* FF 4-18 */
    input::-moz-placeholder {
        opacity: 1;
        -moz-transition: opacity 0s;
        transition: opacity 0s;
        text-align: right;
    }
    /* FF 19-51 */
    input:-ms-input-placeholder {
        opacity: 1;
        -ms-transition: opacity 0s;
        transition: opacity 0s;
        text-align: right;
    }
    /* IE 10+ */
    input::placeholder {
        opacity: 1;
        transition: opacity 0s;
        text-align: right;
    }
    /* Modern Browsers */
    
    *:focus::-webkit-input-placeholder {
       opacity: 0;
       text-align: left;
    }
    /* Chrome <=56, Safari < 10 */
    *:focus:-moz-placeholder {
        opacity: 0;
        text-align: left;
    }
    /* FF 4-18 */
    *:focus::-moz-placeholder {
        opacity: 0;
        text-align: left;
    }
    /* FF 19-50 */
    *:focus:-ms-input-placeholder {
        opacity: 0;
        text-align: left;
    }
    /* IE 10+ */
    *:focus::placeholder {
        opacity: 0;
        text-align: left;
    }
    /* Modern Browsers */
    
    input:focus {
        text-align: left;
    }
    
    0 讨论(0)
提交回复
热议问题