dir - HTML: HyperText Markup Language 编辑

The dir global attribute is an enumerated attribute that indicates the directionality of the element's text.

It can have the following values:

  • ltr, which means left to right and is to be used for languages that are written from the left to the right (like English);
  • rtl, which means right to left and is to be used for languages that are written from the right to the left (like Arabic);
  • auto, which lets the user agent decide. It uses a basic algorithm as it parses the characters inside the element until it finds a character with a strong directionality, then applies that directionality to the whole element.

Usage notes: This attribute is mandatory for the <bdo> element where it has a different semantic meaning.

  • This attribute is not inherited by the <bdi> element. If not set, its value is auto.

  • This attribute can be overridden by the CSS properties direction and unicode-bidi, if a CSS page is active and the element supports these properties.

  • As the directionality of the text is semantically related to its content and not to its presentation, it is recommended that web developers use this attribute instead of the related CSS properties when possible. That way, the text will display correctly even on a browser that doesn't support CSS or has the CSS deactivated.

  • The auto value should be used for data with an unknown directionality, like data coming from user input, eventually stored in a database.

Browsers might allow users to change the directionality of <input> and <textarea>s in order to assist with authoring content. Chrome and Safari provide a directionality option in the contextual menu of input fields while Internet Explorer and Edge use the key combinations Ctrl + Left Shift and Ctrl + Right Shift. Firefox uses Ctrl/Cmd + Shift + X but does NOT update the dir attribute value.

Specifications

SpecificationStatusComment
HTML Living Standard
The definition of 'dir' in that specification.
Living StandardNo change from latest snapshot, HTML 5.1
HTML 5.1
The definition of 'dir' in that specification.
RecommendationSnapshot of HTML Living Standard, no change from HTML5
HTML5
The definition of 'dir' in that specification.
RecommendationSnapshot of HTML Living Standard, from HTML 4.01 Specification it added the auto value, and is now a true global attribute.
HTML 4.01 Specification
The definition of 'dir' in that specification.
RecommendationSupported on all elements but <applet>, <base>, <basefont>, <bdo>, <br>, <frame>, <frameset>, <iframe>, <param>, and <script>.

Browser compatibility

BCD tables only load in the browser

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:43 次

字数:7277

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文