How to Align the content of a Placeholder within a TextArea?

2

Well my problem is that I have a <textarea> on my page and I use the attribute placeholder= to give the value of user such that: <textarea id="usuario_nick" placeholder="usuario">

The problem is that the text of the textarea is automatically aligned to the left but I want it to be aligned towards the center of textarea not I mean only horizontally also vertically right in the center is it possible? Is there a way to move only the placeholder value in that textarea as a padding-top y right ?.

I know that you can take the placeholder with ::-webkit-input-placeholder but this takes me all and I want it to happen only in 1 specific.

    
asked by theboshy 10.08.2017 в 22:39
source

2 answers

4
  

I know that the placeholder can be taken with :: - webkit-input-placeholder but this takes me all and I want it to happen only in 1 specific.

You should only prefix the selector you want to change the pseudo-elemento ::placeholder . The selector can be a class ( eg: .miclase ), an id ( eg: #miId ), etc.

  

I want it to be aligned towards the center of the textarea I do not mean only horizontally also vertically right in the center is it possible?

To align it vertically you can specify a height specific for textarea and then the same value for line-height of placeholder .

  

Is there a way to move only the placeholder value in that textarea as a padding-top and right?

Yes, you should only indicate the padding-top you want to apply.

So for example:

.ph-center {
  height: 100px;
}
.ph-center::-webkit-input-placeholder {
  text-align: center;
  line-height: 100px;/* Centrado vertical */
}
<textarea placeholder="usuario"></textarea>
<textarea class="ph-center" placeholder="usuario"></textarea>
    
answered by 10.08.2017 / 23:10
source
4

You can access using id.

This would be the code:

#miid::placeholder {
  color: red;
  text-align: center;
  padding-top: 30px;
}
<textarea id="miid" placeholder="placeholder" rows="5"></textarea>
    
answered by 10.08.2017 в 23:12