The color of the text changes from its default color when not in use

Hey there, let me break this down for you...

I'm currently in the process of styling a contact form.

I've managed to change the text color of my input focus to white.

However, when I click away from the form, the inputted text color reverts back to black.

So, here's my query - how can I style the color of the inputted text when I click off the form?

Check out an example below:

* {
  background: red;
}

.contact-formula {
  height: auto;
  width: 100%;
  padding-left: 32.5%;
}

input {
  width: 50%;
  height: 5vh;
  display: block;
  background: transparent;
  border: none;
  border-bottom: .25vh solid orange;
}

input[type=submit] {
  width: 20%;
  margin-top: 2.5vh;
  text-align: center;
  background: orange;
  color: white;
  font-size: 2.5vh;
  cursor: pointer;
}

textarea {
  width: 50%;
  background: transparent;
  border: none;
  border-bottom: .25vh solid orange;
  resize: none;
  height: 15vh;
}

label {
  color: white;
  font-size: 2.5vh;
}

::placeholder {
  font-size: 3vh;
  color: white;
  text-transform: uppercase;
}

textarea:focus,
input:focus {
  color: white;
  font-size: 3vh;
}

input:focus,
select:focus,
textarea:focus,
button:focus {
  outline: none;
}
<div class="contact-formula">
  <form name="htmlform" method="post" action="html_form_send.php">
    <input type="text" name="first_name" maxlength="50" size="30" placeholder="First Name" autofocus><br>
    <input type="text" name="last_name" maxlength="50" size="30" placeholder="Last Name"><br>
    <input type="text" name="email" maxlength="80" size="30" placeholder="email"><br>
    <textarea name="comments" maxlength="1000" cols="25" rows="6" placeholder="Message"></textarea><br>
    <input type="submit" value="Submit">
  </form>
</div>

I'm looking for some guidance on what I might be missing.

Thanks a bunch in advance!

Answer №1

The issue arises when using the :focus pseudo-class. Removing the :focus resolves the problem.

* {
  background: red;
}

.contact-formula {
  height: auto;
  width: 100%;
  padding-left: 32.5%;
}

input {
  width: 50%;
  height: 5vh;
  display: block;
  background: transparent;
  border: none;
  border-bottom: .25vh solid orange;
}

input[type=submit] {
  width: 20%;
  margin-top: 2.5vh;
  text-align: center;
  background: orange;
  color: white;
  font-size: 2.5vh;
  cursor: pointer;
}

textarea {
  width: 50%;
  background: transparent;
  border: none;
  border-bottom: .25vh solid orange;
  resize: none;
  height: 15vh;
}

label {
  color: white;
  font-size: 2.5vh;
}

::placeholder {
  font-size: 3vh;
  color: white;
  text-transform: uppercase;
}

textarea,
input {
  color: white;
  font-size: 3vh;
}

input:focus,
select:focus,
textarea:focus,
button:focus {
  outline: none;
}
<div class="contact-formula">
  <form name="htmlform" method="post" action="html_form_send.php">
    <input type="text" name="first_name" maxlength="50" size="30" placeholder="First Name" autofocus><br>
    <input type="text" name="last_name" maxlength="50" size="30" placeholder="Last Name"><br>
    <input type="text" name="email" maxlength="80" size="30" placeholder="email"><br>
    <textarea name="comments" maxlength="1000" cols="25" rows="6" placeholder="Message"></textarea><br>
    <input type="submit" value="Submit">
  </form>
</div>

Answer №2

If you simply include input[type=text] {color: white;}

* {
  background: red;
}

.contact-formula {
  height: auto;
  width: 100%;
  padding-left: 32.5%;
}

input {
  width: 50%;
  height: 5vh;
  display: block;
  background: transparent;
  border: none;
  border-bottom: .25vh solid orange;
}

input[type=text] {
  color: white;
  font-size: 3vh;
}

input[type=submit] {
  width: 20%;
  margin-top: 2.5vh;
  text-align: center;
  background: orange;
  font-size: 2.5vh;
  cursor: pointer;
}

textarea {
  width: 50%;
  background: transparent;
  border: none;
  border-bottom: .25vh solid orange;
  resize: none;
  height: 15vh;
}

label {
  color: white;
  font-size: 2.5vh;
}

::placeholder {
  font-size: 3vh;
  color: white;
  text-transform: uppercase;
}


input:focus,
select:focus,
textarea:focus,
button:focus {
  outline: none;
}
<div class="contact-formula">
  <form name="htmlform" method="post" action="html_form_send.php">
    <input type="text" name="first_name" maxlength="50" size="30" placeholder="First Name" autofocus><br>
    <input type="text" name="last_name" maxlength="50" size="30" placeholder="Last Name"><br>
    <input type="text" name="email" maxlength="80" size="30" placeholder="email"><br>
    <textarea name="comments" maxlength="1000" cols="25" rows="6" placeholder="Message"></textarea><br>
    <input type="submit" value="Submit">
  </form>
</div>

Answer №3

it would be best to simply eliminate the :focus on textarea, input:

* {
  background: red;
}

.contact-formula {
  height: auto;
  width: 100%;
  padding-left: 32.5%;
}

input {
  width: 50%;
  height: 5vh;
  display: block;
  background: transparent;
  border: none;
  border-bottom: .25vh solid orange;
}

input[type=submit] {
  width: 20%;
  margin-top: 2.5vh;
  text-align: center;
  background: orange;
  color: white;
  font-size: 2.5vh;
  cursor: pointer;
}

textarea {
  width: 50%;
  background: transparent;
  border: none;
  border-bottom: .25vh solid orange;
  resize: none;
  height: 15vh;
}

label {
  color: white;
  font-size: 2.5vh;
}

::placeholder {
  font-size: 3vh;
  color: white;
  text-transform: uppercase;
}

textarea,
input {
  color: white;
  font-size: 3vh;
}

input:focus,
select:focus,
textarea:focus,
button:focus {
  outline: none;
}
<div class="contact-formula">
  <form name="htmlform" method="post" action="html_form_send.php">
    <input type="text" name="first_name" maxlength="50" size="30" placeholder="First Name" autofocus><br>
    <input type="text" name="last_name" maxlength="50" size="30" placeholder="Last Name"><br>
    <input type="text" name="email" maxlength="80" size="30" placeholder="email"><br>
    <textarea name="comments" maxlength="1000" cols="25" rows="6" placeholder="Message"></textarea><br>
    <input type="submit" value="Submit">
  </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

What to do when encountering a problem with HTML, CSS, and JS while loading a webpage from an SD card to a WebView

I am facing an issue while loading an HTML file from the SD card to a webview. The problem is that the CSS, images, and videos are not loading properly in the webview. Compatible with Android 4.4 KitKat and Chrome version Not compatible with versions belo ...

Leveraging the Bootstrap 3 audio player, although displaying a standard HTML5 output

When trying to use the Bootstrap 3 player to display an audio player, I'm encountering an issue where the page only shows a default black HTML5 audio player output. Here is my current directory structure: miuse/ application/ bootstrap/ ...

Discover the concealed_elem annotations through the power of JavaScript

As I work on my new website, I am struggling with narrowing down the web code. I came across a solution that seems fitting for what I need, but unfortunately, I can't seem to make it work: I attempted the non-jQuery solution, however, I must be missi ...

AngularJS button click not redirecting properly with $location.path

When I click a button in my HTML file named `my.html`, I want to redirect the user to `about.html`. However, when I try using `$location.path("\about")` inside the controller, nothing happens and only my current page is displayed without loading `abou ...

Exploring the impact of JavaScript tags on website performance in accordance with W3

While researching website optimization strategies today, I came across an article discussing the benefits of moving JavaScript scripts to the bottom of the HTML page. I am curious if this approach aligns with W3C's recommendations since traditionally ...

A guide on seamlessly transitioning from a mobile website to the corresponding native app

I am currently working on a mobile website project. This website is built using basic HTML and is accessed through a URL on a web browser, not as a native app or through PhoneGap. The client has requested links to their Facebook, Pinterest, YouTube, Twitt ...

What is the method for placing a badge above a Font Awesome icon?

Is it possible to add a badge with numbers like 5, 10, or 100 on top of the Font Awesome symbol (fa-envelope)? I am looking for something like this: However, I am struggling to figure out how to place the badge on top of the symbol. You can see my attempt ...

Is there a way to automatically scroll 50 pixels down the page after pressing a button?

Is there a way to make my page scroll down in Angular when a button is clicked? I attempted to use this code, but it didn't have the desired effect. What is the best method for scrolling the page down by 50px? window.scrollBy(0, 50); ...

What steps can I take to create a textbox that expands as more text is

Looking to create a unique textbook design that starts out with specific width and height dimensions, but expands downward as users type beyond the initial space. Wondering if CSS can help achieve this functionality? In a standard textbox, only a scroll ba ...

The simplest way to increase the size of a child element in order to generate a scrollable area

When working with HTML, it's important to consider how the size of a child div affects the parent div. If the child div is larger than its parent, scrollbars will appear on the parent div if the appropriate style rules are set. However, I'm inte ...

Error: ReactJs unable to find location

I'm attempting to update the status of the current page when it loads... const navigation = \[ { name: "Dashboard", href: "/dashboard", current: false }, { name: "Team", href: "/dashboard/team", current: fa ...

What is the significance of vendor prefixes in the world of CSS3?

While I can see the rationale behind using prefixes for experimental non-official features to avoid conflicts, what is the reason for using them on shadows and similar elements? Shouldn't all vendors be implementing effects consistently according to ...

Customize the List Box Appearance for a Specific HTML Item (Option)

I am working on achieving a specific behavior. When using a listBox (or comboBox), the first element (such as "choose one") should have a unique style. Here is an example of code to test: <style type="text/css"> .testX {font-style: italic;} </ ...

Attempting to create a dynamic dropdown menu with animated effects triggered by a key press

I've been attempting to construct a menu that initially appears as a small icon in the corner. Upon pressing a key (currently set to click), the checkbox is activated, initiating the animation. Most of the menu and animation are functional at this po ...

"Learn the process of converting HTML content into a string in an Android application and then displaying

I utilized this/this to Print Receipts in part of POS(Point of Sale) from EPSON Printer Obtaining data Json from URL (within the Json Object is html print template): { "response": { "status": "<table>.... </table>" } } Hence, ...

Changing the appearance of a radio button dynamically upon clicking

I am currently working on a dynamic pickup date form that utilizes radio buttons. My goal is to change the style of the selected value when a user clicks on it. Below is the code I have tried, but it has not been successful: foreach ($period as $day){ ech ...

having difficulty selecting a list item within the <nav> and <ul> tags using Selenium WebDriver

Within the nav tag, there is a list of elements. The goal is to click on the first element in the list. Below is the given HTML: <aside id="left-panel" style="overflow: visible;"> <div id="selectedBrand" class="custum-brand-info login-info"> ...

Ways to transfer data from TypeScript to CSS within Angular 6

Trying to work with ngClass or ngStyle, but I'm struggling with passing the value. Here's my current code: strip.component.ts import { ... } from '@angular/core'; @Component({ selector: 'app-strip', templateUrl: &apo ...

Having difficulty configuring Compass in WebStorm

Trying to integrate Compass into an existing WebStorm project has been challenging for me as the CSS files are not linking properly. Despite my efforts to modify the relative links, I have not yet managed to resolve the issue. The folders and config.rb we ...

The process of retrieving CSS attributes from a control found by XPath using Selenium IDE

During my Selenium IDE script execution, I am looking to identify and handle an error state. This specific error state is visually highlighted on the page with a select control changing its background color to a light shade of red. The xpath for the selec ...