I'm working on a site that supports many different locales. Our next locale is Hebrew, which is a right-to-left language. I'm setting the dir=rtl
and lang=he
on the HTML element, and certain things shift around (as they should).
A lot of the website uses elements with absolute positioning setting the left value. Is there a way to make it so when you are in rtl mode that it would switch it to be the right value?
I know that I could have a rtl
class on my html element and do css overrides when that class is present, but the project is pretty large and it would not be fun to hunt down all of these occurrences manually.
The text-orientation CSS property sets the orientation of the text characters in a line. It only affects text in vertical mode (when writing-mode is not horizontal-tb ). It is useful for controlling the display of languages that use vertical script, and also for making vertical table headers.
If position: absolute; or position: fixed; - the right property sets the right edge of an element to a unit to the right of the right edge of its nearest positioned ancestor. If position: relative; - the right property sets the right edge of an element to a unit to the left/right of its normal position.
Shortcuts: Ctrl+Shift+J -- switch to RTL Ctrl+Shift+E -- switch to LTR Note 1: If one or both of the shortcuts don't work, it means that something else is mapped to them.
I think adding classes would be more robust, but considering how much no-fun that would be, hunt them down with JavaScript!
Codepen
$(document).ready(function () {
var elsToFlip = $('*')
elsToFlip.each(function () {
var pos = $(this).css('position')
, left = $(this).css('left')
if (pos === 'absolute' && left !== 'auto') {
$(this).css({
left: 'initial'
, right: left
})
}
})
})
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