I'm using an input tag and have set a placeholder value in it. Now, I want to set the padding for the placeholder text inside it, but I can't.
Here is what I've tried:
HTML
<form><input class="tbsearchbar" type="search" name="search_tb" placeholder="Test"></form>
CSS
placeholder {
padding-top: 10px;
}
Definition and Usage. The ::placeholder selector selects form elements with placeholder text, and let you style the placeholder text. The placeholder text is set with the placeholder attribute, which specifies a hint that describes the expected value of an input field.
The “placeholder” property is used to get or set the placeholder of an input text. This can be used to change the placeholder text to a new one. The element is first selected using a jQuery selector. The new placeholder text can then be assigned to the element's placeholder property.
If we want to apply only right padding to an element, then we have to use only padding-right property in the id selector. And, then we have to set only one value to the property as shown in the following example: <! Doctype Html>
You can align the placeholder text (right, left or center) using CSS ::placeholder selector property.
This works (tested on Chrome):
#yourid::placeholder {
padding-left: 3px;
}
For all browsers:
#yourid::-webkit-input-placeholder { /* Chrome/Opera/Safari */
padding-left: 3px;
}
#yourid::-moz-placeholder { /* Firefox 19+ */
padding-left: 3px;
}
#yourid:-ms-input-placeholder { /* IE 10+ */
padding-left: 3px;
}
#yourid:-moz-placeholder { /* Firefox 18- */
padding-left: 3px;
}
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