问题
I have a DropDownList in my aspx file like this:
<asp:DropDownList runat="server" ID="MaxRec">
<asp:ListItem>10</asp:ListItem>
<asp:ListItem>50</asp:ListItem>
<asp:ListItem>100</asp:ListItem>
<asp:ListItem>150</asp:ListItem>
<asp:ListItem Selected="True">200</asp:ListItem>
</asp:DropDownList>
In Chrome it renders like this:
How can i set the alignment on all ListItems to be to the right so that values are properly aligned? I tried setting style="text-align:right" on the DropDownList and on the ListItems but it doesn't have any effect. I need a solution that also works on Chrome.
Thanks for replies!
回答1:
Adding the following style will align the numbers as required but will move the drop down arrow to the left instead of the right.
Other than using this I assume the inability to right align select options may be a limitation in Chrome.
.drop-down-list
{
direction: rtl;
}
回答2:
the below code works for me
<head>
<style type="text/css">
select.myDropDownList {
text-align: right;
}
</style>
</head>
<asp:DropDownList ID="myDropDownList" Runat="server" CssClass="myDropDownList">
<asp:ListItem>10</asp:ListItem>
<asp:ListItem>50</asp:ListItem>
<asp:ListItem>100</asp:ListItem>
<asp:ListItem>150</asp:ListItem>
</asp:DropDownlist>
来源:https://stackoverflow.com/questions/6938374/how-can-i-set-alignment-for-a-listitem-in-a-dropdownlist