should i always use bdo for text direction?

筅森魡賤 提交于 2019-12-05 03:38:16

You should normally not use the bdo element, or its CSS counterpart, since they are meant to be used in exceptional situations, where you need to override the normal bidirectionality rules. They mean forced writing direction, which means that the inherent directionality of letters will be overridden.

For any normal text in a right-to-left language, <div dir=rtl>...</div> is adequate. In fact, in most cases, you don’t need even that, since by default, Latin, Greek, and Cyrillic letters will run left to right, Arabic and Hebrew letters will run right to left, and neutral characters will follow suit. But the dir attribute is still a useful precaution against special cases and against browser bugs.

Using dir rather than corresponding CSS is preferable since writing direction is not just a casual presentational suggestion, like fonts and colors and backgrounds, but an integral part of a writing system.

So you should use bdo only if you have a good reason to override the birectionality algorithm. If you are wondering whether you have a good reason, you don’t have. But here’s an example. If you write

The letters &#x5d0;, &#x5d1;, and &#x5d2;...

then the visual order will be wrong, since the Hebrew letters א and ב will appear in a wrong visual order (given the English-language context). The comma between them is neutral, so they run right to left. To prevent this, you would write

The letters <bdo dir=ltr>&#x5d0;, &#x5d1;,</bdo> and &#x5d2;...

There is no reason to expect bdo to become deprecated. It has its uses, though rare, and within the relevant scope, it serves its purpose. It is more logical to use HTML rather than CSS in those rare occasions, and more practical to use HTML rather than control characters that override normal directionality.

It shows that it is included in the HTML5 spec http://www.w3.org/wiki/HTML/Elements/bdo and on the https://developer.mozilla.org/en-US/docs/Web/HTML/Element/bdo it shows that is a Candidate Recommendation for HTML5. Will it be deprecated? Most likely not.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!