Create a variety of colors with a simple click

A form has been created for the footer where clicking on an input causes the text and border-bottom to transition from grey to white.

Visit Code Pen

HTML:

<div class="footer">

<div class="footerContainer">

    <form>

        <input type="text" class="name" placeholder="Name"/>

        <input type="text" class="subject" placeholder="Subject"/>

        <input type="tel" class="phone" placeholder="Phone Number"/>

        <textarea type="text" class="details" placeholder="Details"></textarea>

        <input type="submit" class="submit" placeholder="Submit"/>

    </form>

</div>

CSS:

.footer{
height: 100%;
width: 100%;
background-color: grey;
display: flex;
justify-content: center;
align-items: center;
}

.footerContainer{
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: darkgrey;
    width: 25%;
    padding: 2vw;
    margin: 2vw;
}

.name, .subject, .phone{
    background-color: transparent;
    border: 0;
    border-bottom: solid #bababa 1px;
    height: 2.8vw;
    font-size: 2vw;
    color: #bababa;
    transition: color linear 0.5s;
    margin-bottom: 1vw;
    font-family: 'Lora', sans-serif;
    width: 100%;
}

textarea{
    background-color: transparent;
    border: 0;
    border-bottom: solid #bababa 1px;
    height: 10vw;
    font-size: 2vw;
    color: #bababa;
    transition: color linear 0.5s;
    margin-bottom: 1vw;
    font-family: 'Lora', sans-serif;
    resize: none;
    width: 100%;
}

.submit{
    float: right;
    border: 1px solid black;
    border-radius: 0.4vw;
    height: 2vw;
    width: 4.5vw;
    font-size: 1vw;
    background-color: #92F398;
    cursor: pointer;
}

input::-webkit-input-placeholder, textarea::-webkit-input-placeholder{
    color: #bababa;
    transition: color linear 0.5s;
}

input:focus::-webkit-input-placeholder, textarea:focus::-webkit-input-placeholder{
    color: white;
    transition: color linear 0.5s;
}

input:focus, textarea:focus{
    color: white;
    border-bottom: solid white 1px;
    transition: color linear 0.5s;
}

input:focus,
select:focus,
textarea:focus,
button:focus {
    outline: none;
}

The desired outcome is for the inputted text in the form to remain white even when the user clicks off of it (which currently does not happen).

I apologize if this post does not fully comply with the guidelines, as there are many. I have done my best to present the information in a structured manner.

Answer №1

Here's a little trick you can use:

input:valid{
  color: white;
}

By adding this CSS, all valid input will have a text color of white.

Additionally, you can include minlength="4" to the input to determine when the color should change.

Give it a try and see for yourself!

Check out this CodePen link for an example.

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

Are you looking to test your website's performance under limited bandwidth conditions

Similar Query: How can I test a website for low bandwidth? Would it be possible to mimic a slow internet connection to test my website's performance? I need to simulate lower speed conditions in order to observe how the site behaves. ...

Creating a form in HTML to retrieve two variables from a PHP page using the GET method

After spending several hours working on this issue, I am still struggling to get it functioning correctly. The page where my form is located can be found at /index.php?action=pagename. My goal is to retrieve a variable from the URL /index.php?action=pagena ...

The Impreza theme is experiencing difficulty displaying Font Awesome icons

Recently, I had a client who needed a WordPress website. After working on the project on my own server, I finally completed it and transferred the entire site to the client's main domain at gulugalmarketing.com. Everything was functioning perfectly o ...

Leveraging the XMLHTTP object to extract data from websites with VBA

I am currently working on extracting the "key people" information from a Wikipedia page: https://en.wikipedia.org/wiki/Abbott_Laboratories and inserting that data into my Excel spreadsheet. I have successfully achieved this using xml http, which I find ef ...

Utilizing React JS: Displaying or Concealing Specific Components Based on the URL Path

Is there a way to dynamically change the navbar items based on the URL without having separate navbar components for each side? My current navbar design features 3 links on the left side and 3 links on the right, but I want to display only one side at a ti ...

What is the best way to set a fixed width for my HTML elements?

I am facing an issue with my user registration form where error messages are causing all elements to become wider when they fail validation. I need help in preventing this widening effect. How can I achieve that? The expansion seems to be triggered by the ...

Is the CSS after-before property not functioning properly?

In my CSS code, I am utilizing the after and before tags. This is the structure of my div. However, I am facing an issue where my after tag is not functioning as expected. While everything else seems to be working fine, the after and before tags are not di ...

The console is showing an error message stating that the variable "i" is not

Currently, I am developing the dashboard for my discord.js bot. While working on it, I encountered an issue where a variable I created to select an array from my JSON file is being reported as undefined by the console. $(function() { $.getJSON( "./data/ ...

Taking steps when a number is enclosed within a span

Testing a simple code with similar action to what I want. Apologies for any language errors, hoping to be understood :-) The HTML code snippet: <div class="pagination"> <a href="#" class=""><span>1</span></a> <a href=" ...

Using a Javascript while loop to iterate through an array and display the elements in the .innerHTML property

As a newcomer to Javascript, I am in the process of teaching myself. My current task is to develop a function that will display each element of the array AmericanCars with a space between them. I have successfully been able to show an individual element u ...

Automate CSS slideshow playback using JavaScript

Using only CSS, I created a basic slideshow where the margin of the element changes upon radio button click to display the desired slide. You can view the functionality in the code snippet below. Additionally, I implemented auto play for this slideshow usi ...

Prevent Google Autofill from replacing current values in fields of a react form

When using a simple form in React within a modal, I encountered an issue with autofill functionality. If a user uses autofill for one field, such as the email field, it also updates other fields - including ones that have already been manually filled out. ...

How can I ensure that a form submission still functions properly even when the submit button disappears due to an onBlur event in React and Next

I am facing an issue with a form on my website that triggers an event upon submission. Within the form, there is a textarea field. When you click on the textarea, a submit button appears. However, it disappears when you click out of the textarea. This fun ...

Styling limitations encountered when using lang="scss" with scoped css

My current project involves using Quasar and I am attempting to style the first column of q-table: <style lang="scss" scoped> td:first-child { background-color: #747480 !important; } </style> Unfortunately, this code does not seem to have a ...

Styling a Form Submission with CSS

I am currently working on a website that contains the following PHP code: echo "<form action='choice.php' method='post'>"; echo "<input type='submit' name='choice' value='left' /> "; As I am i ...

Show full-screen images on click using Ionic framework

Currently, I am working on developing a mobile app using the Ionic framework. I have created a layout that resembles the one shown in this Card Layout. My question is: How can I make the card image display in full screen when clicked by the user and retur ...

Can you explain the function of the forward slash in the HTML img tag?

Currently, I am in the process of learning html/css by following the tutorial provided by W3Schools.com. The part of the code that is causing me some difficulty can be found at http://www.w3schools.com/css/tryit.asp?filename=trycss_vertical-align Specific ...

Extract content from an HTML element and transfer it to PHP

Alright, listen up. I've got a task at hand where I need to fetch some information from my database by calling a PHP page through a link (<a href='name.php'>). Let's just say the code is speaking louder than my words: <?php ...

Harvesting information from an HTML table

I have a table displaying the following values: turn-right Go straight turn-left How can I extract only the 2nd value, "Go straight"? Here is the code snippet I tried: var text = $('#personDataTable tr:first td:first').text(); The code above ...

Can I use npm's jQuery in an old-school HTML format?

I am looking to incorporate jQuery into a project without having to rely on the website or CDN for downloading the library. As someone new to npm, I am curious to know if following these steps would be advisable or potentially problematic down the line. Wh ...