简体   繁体   English

如何防止网站中笨拙的文本选择行为

[英]How to prevent clumsy text selection behaviour in websites

I noticed that in some websites, text selection behaves in a somewhat clumsy manner: the user click and hold the left button, and then move it in the direction of the text he/she wants to select, and then an entire portion of text on the opposite side of the movement gets selected. 我注意到在某些网站中,文本选择的行为有些笨拙:用户单击并按住向左按钮,然后将其向他/她想要选择的文本方向移动,然后将整个文本部分机芯的另一侧被选中。

This is not something that happen everywhere, and it's hard do describe, so I will provide an example. 这并不是随处可见,很难描述,因此我将提供一个示例。 I've found this really cool article . 我发现这篇文章很酷 Check the last line of it: 检查它的最后一行:

ENV:REDIRECT_STATUS is my new best friend.

If I click on the left of this line, and drag a little to the right (say, up till the : ), I expect to have the ENV: portion of this line selected. 如果我点击该线的左侧,并拖动一点点向右(比方说,在这之前的: ),我希望有ENV:此行选择的部分。 Instead, what gets selected is the remainder of this line ( REDIRECT_STATUS is my new best friend. ) plus every comment and the sidebar! 取而代之的是,选择的是该行的其余部分( REDIRECT_STATUS is my new best friend. ), 加上每个注释和侧边栏! I am using Firefox 15.0.1, but already notice this behaviour in Chrome and Internet Explorer. 我正在使用Firefox 15.0.1,但已经在Chrome和Internet Explorer中注意到此行为。

So what I want to know is, why this happen, and what needs to be done in order to prevent this glitch. 所以我想知道的是,为什么会发生这种情况,以及需要采取什么措施来防止这种故障。

PS: please excuse me for not being clear on this subject; 附言:请原谅我对此事不清楚。 I found this issue really hard to describe on words. 我发现这个问题很难用言语来形容。

It all has to do with the HTML markup and the CSS. 所有这些都与HTML标记和CSS有关。 The browsers tend to select the text in the same order as it appears in the HTML. 浏览器倾向于按照与HTML中出现的顺序选择文本。 Adding padding like Tim Down suggested can help user select the text because it gives a little margin of error in the text selection. 建议添加类似Tim Down的填充可以帮助用户选择文本,因为它在文本选择中提供了少许误差。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM