Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the padding of placeholder text

Tags:

html

css

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;
}
like image 615
RS92 Avatar asked May 20 '15 17:05

RS92


People also ask

Can I style the placeholder text?

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.

How do I change the placeholder text?

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.

How do you padding a textbox in HTML?

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>

Can you center placeholder text?

You can align the placeholder text (right, left or center) using CSS ::placeholder selector property.


1 Answers

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;
}
like image 146
iPzard Avatar answered Oct 08 '22 22:10

iPzard