Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

input从右到左显示文字,并且光标始终在右侧。text-align和direction的区别 #13

Open
lovelmh13 opened this issue Feb 10, 2020 · 0 comments

Comments

@lovelmh13
Copy link
Owner

其实很简单:

.input {
    text-align: right
}

需要分清和direction: rtl;的区别

text-align是让文本靠右,而direction: rtl;是改变文本的方向

<style type="text/css">
    div.one {
        text-align: right
    }
    div.two {
        direction: rtl;
    }
</style>

<div class="one">Some text. Right-to-left direction.</div>
<div class="two">Some text. Left-to-right direction.</div>

.class的显示效果只是让文字整体平移到右边
.two除了文字移到了右侧显示,文字也发生了改变。 会先成:.Some text. Left-to-right direction,看见区别了吗?句号位置变了。

经过我的测试,如果只是改变文本内容direction: rtl;会改变符号和文字的位置,而文字如果也想从右往左写,只需要稍加改动,就可以把顺序完全颠倒,变成从右往左写:

div.two {
    direction: rtl;
    unicode-bidi:bidi-override;
}

就会变成:
Some text. Left-to-right direction.

但是,如果换成是input,除了显示跟本文的显示方式一样以为,光标是不一样的。
direction: rtl; 因为是改文字方向,所以光标也改成了在左边。使用backspacedelete按键也会相反。
text-align: right是改变了文字的位置,而不是方向,光标是正常的,所以这个才是我们需要用的属性。

@lovelmh13 lovelmh13 changed the title input从右到左显示文字,并且光标始重在右侧。text-align和direction的区别 input从右到左显示文字,并且光标始终在右侧。text-align和direction的区别 Feb 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant