For all default inputs, the text you fill starts on the left. How do you make it start on the right?
This question is related to
html
css
forms
html-input
Try this in your CSS:
input {
text-align: right;
}
To align the text in the center:
input {
text-align: center;
}
But, it should be left-aligned, as that is the default - and appears to be the most user friendly.
The accepted answer here is correct but I'd like to add a little info. If you are using a library / framework like bootstrap there may be built in classes for this. For example bootstrap uses the text-right
class. Use it like this:
<input type="text" class="text-right"/>
<input type="number" class="text-right"/>
As a note this works on other input types as well, like numeric as shown above.
If you aren't using a nice framework like bootstrap then you can make your own version of this helper class. Similar to other answers but we are not going to add it directly to the input class so it won't apply to every single input on your site or page, this might not be desired behavior. So this would create a nice easy css class to align things right without needing inline styling or affecting every single input box.
.text-right{
text-align: right;
}
Now you can use this class exactly the same as the inputs above with class="text-right"
. I know it isn't saving that many key strokes but it makes your code cleaner.
Without CSS: Use the STYLE property of text input
STYLE="text-align: right;"
@Html.TextBoxFor(model => model.IssueDate, new { @class = "form-control", name = "inv_issue_date", id = "inv_issue_date", title = "Select Invoice Issue Date", placeholder = "dd/mm/yyyy", style = "text-align:center;" })
If you want to get it aligned to the right after the text looses focus you can try to use the direction modifier. This will show the right part of the text after loosing focus. e.g. useful if you want to show the file name in a large path.
input.rightAligned {_x000D_
direction:ltr;_x000D_
overflow:hidden;_x000D_
}_x000D_
input.rightAligned:not(:focus) {_x000D_
direction:rtl;_x000D_
text-align: left;_x000D_
unicode-bidi: plaintext;_x000D_
text-overflow: ellipsis;_x000D_
}
_x000D_
<form>_x000D_
<input type="text" class="rightAligned" name="name" value="">_x000D_
</form>
_x000D_
The not selector is currently well supported : Browser support
input[type=text] { text-align:right }
_x000D_
<form>_x000D_
<input type="text" name="name" value="">_x000D_
</form>
_x000D_
Source: Stackoverflow.com