html5 - CSS input effect not working if required is removed -


the label effect work if required there in input tag. effect not work if remove required attribute click see working fiddle there solution this.

html

<div class="group "> <input type="text" required="" class="module-input" /> <label >name</label> </div> 

snippet:

.module-input {    font-size: 14px;    padding-top: 12px;    display: block;    width: 97%;    border: none;    border-bottom: 1px solid #94a3a9;    background-color: transparent;    color: #5a686d;    margin-bottom: 2%;  }    input:focus {    outline: none;  }    .group {    position: relative;    margin-bottom: 25px;  }      /* label */    label {    color: #94a3a9;    font-size: 14px;    font-weight: normal;    position: absolute;    pointer-events: none;    left: 0.5%;    top: 10px;    transition: 0.2s ease all;    -moz-transition: 0.2s ease all;    -webkit-transition: 0.2s ease all;  }      /* active state */    input:focus+label,  input:valid+label {    top: -8px;    font-size: 12px;    color: #94a3a9;  }
<div class="group ">    <input type="text" class="module-input" />    <label>name</label>  </div>

you have css input:valid ~ label means: put label on top if input valid.

when remove required attribute, input becomes valid default. without required attribute, label effect wont work default.

you should use input[required]:valid ~ label


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -