I have this simple fiddle with standard <select>
html element, all what am trying to do is give center alignment for <option>
tags.
I've tried already text-indent: 20px
but its center only the visible tag in the select!
How can I center it?
Dropdown button can be positioned in the center of the page by setting the “text-align” property of dropdown div to center. The following example contains a simple Bootstrap dropdown menu with an added class “my-menu”. The property “text-align: center” is added to the class.
To horizontally center a block element (like <div>), use margin: auto; Setting the width of the element will prevent it from stretching out to the edges of its container.
If we wanted to horizontally center that text on the page, then we can use the text-align property. If you wanted to horizontally center all of the text on the page, then you can use the text-align property in the body selector. In this next example, we have some more text in our HTML.
Solution 1: (A simple solution)
select {
...
padding: 0 0 0 20px;
}
DEMO 1
Solution 2: (added 27-10-2017)
Only the selected number will be centered.
* Probably not yet supported by Safari
select {
...
text-align: center;
text-align-last: center;
}
DEMO 2
You can just use
select {
text-align: center;
}
See modified JSFiddle
Unfortunately, this works for Firefox only. For Chrome, you must use padding-left
similar to @CTravel's solution
select {
padding-left: 20px;
}
Modified JSFiddle
But this doesn't work on the option
elements in Firefox, so this isn't a cross-browser solution either.
don't use
select {
...
padding: 0 0 0 20px;
}
or
select {
text-align: center;
}
they are no working in select. maybe you can use JQuery's select style:JQuery UI Select
Check this link out:
http://filamentgroup.com/lab/jquery_ui_selectmenu_an_aria_accessible_plugin_for_styling_a_html_select/
as stated elsewhere, it is not possible with plain CSS. (Not for all browsers anyhow)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With