JohnFx
JohnFx

Reputation: 34907

Is there a css or html attribute to center the contents of an input tag?

This is probably best explained with a visual.

As shown below, I have two <input> elements for the user to enter dates.

alt text

Is there a CSS or HTML attribute that will allow me to center the contents (in my case, the dates) horizontally in the displayed input areas instead of left-aligning them?

Note: I am not trying to align the controls themselves, just what is inside them.

Upvotes: 4

Views: 1909

Answers (2)

Novikov
Novikov

Reputation: 4489

<input type="text" style="text-align:center;" />

Upvotes: 4

Topera
Topera

Reputation: 12389

Use text-align: center

CSS

input.date {
    text-align: center;
}

HTML

<input class="date" type="text" value="123"  />

See in jsfiddle.

Upvotes: 0

Related Questions