When using ordinary CSS if you want to style your place holder you use these css selectors :
::-webkit-input-placeholder {
color: red;
}
But I can't figure out how to apply these type of styles in react inline styles.
<input type="text" placeholder="A red placeholder text..">
Use the placeholder prop to set a placeholder on an input field in React, e.g. <input type="text" placeholder="Your first name" /> . The placeholder text of an input field is shown until the user types something in the field. Copied!
Note: In most browsers, the appearance of placeholder text is a translucent or light gray color by default.
To change background color on click in React:Set the onClick prop on the element. When the element is clicked, set the active state. Use a ternary operator to conditionally set the background color based on the state variable.
Simply give your "input" tag an "id" or a "class" and put your css style in App.css inside src. e.g
//App.css or external stylesheet
#inputID::placeholder {
color: #ff0000;
opacity: 1;
}
//your jsx code
<input type="text" id="inputID" placeholder="Your text here" />
That actually worked for me.
You can't use ::-webkit-inline-placeholder
inline.
It is a pseudo-element that (much like e.g. :hover
) can only be used in your stylesheet:
The non-standard proprietary
::-webkit-input-placeholder
pseudo-element represents the placeholder text of a form element.
Source
Instead, assign a class to the React component via the className
property and apply the style to this class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With