I have a select box that I want to be aligned to the right, but I want to keep the options dropdown aligned to the left. Like so:
<select>
<option>item</option>
</select>
And the CSS:
select { direction: rtl; }
option { direction: ltr; }
But setting the direction of the select tag also sets the direction of the select dropdown menu. See here
Is this even possible? I know that I could, as an alternative, build a custom select functionality with js, but I'd like to keep it simple if I can.
You can style the option elements to some extent. Using the * CSS selector you can style the options inside the box that is drawn by the system. That is true only because the all selector targets the shadow DOM innards, you can target those manually per browser.
The <select> element has some unique attributes you can use to control it, such as multiple to specify whether multiple options can be selected, and size to specify how many options should be shown at once.
For example, the en-US locale (for US English) specifies left-to-right. Most Western languages, as well as many others around the world, are written LTR. The opposite of LTR, RTL (Right To Left) is used in other common languages, including Arabic ( ar ) and Hebrew ( he ).
direction: rtl;
is not exactly text alignment. Or to be precise text alignment is a side effect of direction. Note that direction also affects position of the dropdown arrow in your setup.
Conventional browsers do not allow you to style select element (it looks significantly different on different platforms, especially mobiles).
In Sciter you can style <select>
parts individually as select components are normal DOM elements there:
select > caption { text-align:right; }
select > button { ... }
select > popup > option { text-align:left; }
I've made it possible as Sciter is designed specifically for desktop UI and <select>
styling is a must there.
As a solution for plain web pages I would suggest to use <select>
substitutes like http://getbootstrap.com/components/#btn-dropdowns
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