Wordpress Contact Form 7 label effect when input not empty

Viewed 105

I am trying to get the floating label effect on Contact Form 7 and ran into a problem. I got the label effect to work on input:focus but I can not get the effect to hold once I enter letters and move to the next input.

In other words I need to label to stay up when the input is not empty.

here's my code:

<div class="wrapper-flex wrapper-form">
   <div class="input-wrapper">
      <label for="your-name"> [text* your-name]<span class="eticheta">FULL NAME</span></label>
   </div><!-- input-wrapper -->
</div><!-- wrapper-flex -->

and the css:

.wpcf7-form .input-wrapper{
    width:47%;
    height: 50px;
    position: relative;
}

.wpcf7-form input{
    width:100% !important;
    background: none !important;
    border:none !important;
    height: 30px !important;
    margin:20px 0 0 0 !important;
}

.wpcf7-form .eticheta{
    width: 100%;
    display: block;
    transition: all 0.3s ease;
    position: absolute;
    top:10px;
}

.wpcf7-form label:focus-within .eticheta, .wpcf7-form input:valid + .eticheta
{
top:0px;
}

I understand that .wpcf7-form input:valid + .eticheta doesn't work as they do not have the same parent. The input has a span around it. I am guessing that's why it doesn't work but I cannot figure out how to get it done

1 Answers

.form-parent {
  width: 323px;
  height: auto;
  background: transparent
    url("https://3.bp.blogspot.com/-gvfHlb6JnY4/VPnwlkELmhI/AAAAAAAAKDU/9lgOeCd279E/s1600/contact-button.png")
    no-repeat right 10px;
  position: fixed;
  top: 150px;
  left: -275px;
  z-index: 9999999;
  transition: all ease 0.6s;
  -moz-transition: all ease 0.6s;
  -webkit-transition: all ease 0.6s;
  -o-transition: all ease 0.6s;
}
.form-parent:hover {
  left: 0;
}
.cc-float-form {
  background: -moz-linear-gradient(top, #2b2a2b 5%, #0a0a0a 100%);
  background: -webkit-linear-gradient(top, #2b2a2b 5%, #0a0a0a 100%);
  background: -o-linear-gradient(top, #2b2a2b 5%, #0a0a0a 100%);
  background: -ms-linear-gradient(top, #2b2a2b 5%, #0a0a0a 100%);
  background: linear-gradient(to bottom, #2b2a2b 5%, #0a0a0a 100%);
  color: #fafafa;
  padding: 10px;
  width: 250px;
  border: 2px solid #000;
  border-radius: 5px;
  -moz-border-radius: 5px;
  -webkit-border-radius: 5px;
}
#ContactForm1 {
  display: none;
}
.contact-form-area {
  background: #222;
  width: 245px;
  padding: 10px 0px;
  border: 1px solid #111;
  box-shadow: 2px 2px 2px #111 inset;
  -webkit-box-shadow: 2px 2px 2px #111 inset;
  font-family: Verdana, Geneva, sans-serif;
  color: #fafafa;
  font-size: 12px;
}
#cc {
  float: right;
  font-size: 9px;
  margin-top: -10px;
  color: #777;
}
#cc a {
  color: #777;
  text-decoration: none;
}
<div class='form-parent'>
        <form name="contact-form" class="cc-float-form">
        <p></p>
        Name:<br />
        <input class="contact-form-area" id="ContactForm1_contact-form-name" name="name" size="30" value="" type="text" />
        <p></p>
        Email:
        <span style="color:red;">*</span><br />
        <input class="contact-form-area" id="ContactForm1_contact-form-email" name="email" size="30" value="" type="text" />
        <p></p>
        Message: <span style="color:red;">*</span><br />
        <textarea class="contact-form-area"  id="ContactForm1_contact-form-email-message" name="email-message" cols="25" rows="5"></textarea>
        <p></p>
        <input class="contact-form-button contact-form-button-submit" id="ContactForm1_contact-form-submit" value="Send" type="button" />
        <p></p>
        <div style="text-align: center; max-width: 222px; width: 100%">
        <p class="contact-form-error-message" id="ContactForm1_contact-form-error-message"></p>
        <p class="contact-form-success-message" id="ContactForm1_contact-form-success-message"></p>
        </div>
        <div id="cc">
        By <a href="https://prio-soft.blogspot.com/" target="_blank">Prio-Soft™</a>
        </div>
        </form>
        </div>

Related