Effect on Label in WordPress Contact Form 7 When Input Field is Populated

Currently, I am attempting to achieve the floating label effect on Contact Form 7 and have encountered an issue. Although I have successfully implemented the label effect on input:focus, I am struggling to make it persist once text has been entered and focus moves to the next input field.

In essence, I need the label to remain visible when the input is not empty.

Below is a snippet of 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 here is the corresponding 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 recognize that the selector .wpcf7-form input:valid + .eticheta is not functioning properly due to them not sharing the same parent. The input is nested within a span element. Despite this challenge, I am determined to find a solution.

Answer №1

.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>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to dynamically expand and collapse all table rows, with the latest row always remaining visible, using pure JavaScript?

I have a form input field where I enter data. The entered data is then displayed in a table as a new row, with the most recent entry at the top. What I want to achieve is to show only the newest row in the table and hide all other rows. When I hover over ...

What causes Google fonts to fail on Heroku but succeed when used locally?

I am currently using express and heroku to host a prototype of a landing page. While the webpage functions properly when running locally, I encounter font loading issues when accessing it on heroku most of the time... The CSS files are located under /pub ...

How to Use JQuery to Retrieve the Nearest TD Element's Text Content

Hey there, here is some HTML code that I need help with: <tbody> <tr> <td class="text-center"><input type="text" class="form-control cardSerialNumber"></td> <td class="text-center"><button type="button" onc ...

Troubleshooting CSS navigation bar hamburger dilemma

Currently, I am facing an issue with a toggle button on my website. When I click on the hamburger menu, the navigation bar does not show up even though the toggle feature is working perfectly fine. I have tried combining different sources to solve this pro ...

What are some ways to prevent popups from being hidden by CSS?

I encountered a problem with my popup that I created using pure CSS. When I move my mouse to the top or bottom of the window, the popup disappears. However, if my cursor is in the body area, the popup appears as intended. I have not used any JavaScript in ...

The code functions properly when tested on a local server, but doesn't produce any results when

Currently, I am working on customizing a premade website and have been tasked with making a modification. The goal is to implement a confirmation box that appears when a button to delete a meeting task is clicked, rather than immediately deleting it. Afte ...

The Selenium python tool is reporting that the element at coordinates (X, Y) is not clickable, as another element is blocking it from receiving the click. It's important to note that

Here is a link to an online store that I need to extract information from. Specifically, I am looking to access the Most Helpful, positive, negative, most recent, and certified buyers' sections in order to scrape the values within them. Unfortunately, ...

Issue: Unable to locate a change supporting element '[object Object]' of the type 'object - Angular 7'

An angular service has been created for the specified purpose: CheckTicket(barcode, codEspec, diaHoraEspec):Observable<Ticket[]>{ //read ticket return this.http.get<Ticket[]>(`${this.checkticket_url}${barcode}?token=${this.token}&a ...

Adjust the height of the image using CSS while maintaining its aspect ratio within the Gall-Peters projection

I've implemented a Gall-Peters projection on my website and I'm looking for the right CSS code to maintain its aspect ratio. I want the image to take up 100% of the available width without elongating the countries' shapes. Can anyone help wi ...

Define the position of a scrolled area within an HTML document to create a

In my current project, I have a scrollable area that highlights the selected div in gray. The HTML is written using Ember (hbs) and includes code to handle this functionality. Below is an example of how the div looks: Here is the corresponding HTML (hbs): ...

PyQt TreeView scrollbar obstructing the header

I've been experimenting with the QTreeView widget (instead of QListView) in order to have a horizontal header. Additionally, I wanted to use stylesheets to customize the colors and appearance of the header and scrollbars. However, there is an issue w ...

My goal is to create collapsible and expandable rows within this table

Discover the code snippet here, without pasting the entire content... As an illustration, let's utilize this example: <head> </head> <body> <table> <tr> <th></th> < ...

Conceal the div element if the value is either undefined or empty in AngularJS

I am experiencing an issue where I get 2 different values when I use console.log($scope.variable). The values shown are undefined and ''. Based on this value, I need to hide a div. Here's what I have tried: <div ng-hide="$scope.variable ...

Attempting to transmit multiple variables

Can anyone provide assistance with passing multiple variables from one page to another? I am able to pass a single variable, but I need to send more than one by clicking a link. Below is a snippet of my code containing the rows I want to transmit to the ne ...

Tips for adjusting the item count in mat-autocomplete

For quite some time now, I've been attempting to adjust the number of items in a mat-autocomplete without any luck. My project involves using material.angular.io Below is a snippet of my code import { Component, OnInit } from '@angular/core&a ...

Using Javascript's document.write function to modify the content of a PHP page

Here is a Javascript function that capitalizes the first letter of a string: function capitalizeFL(string) { return string.charAt(0).toUpperCase() + string.slice(1); } In a file named statuswindow.php, there are PHP scripts that use this function to ...

Updating VAT amount using AJAX on Cart and Checkout pages in Woocommerce

I have a condition in my code that updates the VAT value to 0 if the condition is true. The code works well, but it requires reloading the page to reflect the updated VAT value. Is there a way to update the VAT value without needing to reload the page? Her ...

When incorporating props into styled components, the outcome often turns out to be unexpectedly

I have implemented styled components to change the text color by passing props. <Button variant = 'colour' type="submit" form="myForm" className="submit-btn"> Submit </Button& ...

Signal for a complete 360 degree rotation of an image

Looking to enhance my 360 image rotator with an indicator that fades out after the first image. I added this function to the end of my 360.js: (function(){ if( $('#first').css('visibility','hidden')) { $('#rotat ...

Restricting zooming to only occur within the img element in a UI

Is there a method to enable image zoom inside specific divs without affecting the overall page zoom? At the moment, I have: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale ...