Text Selection Behavior in Chrome and Firefox for Elements with Padding

When a user selects text div, most browsers change the background color of the text. You can customize that background color with CSS like so:

.test::-moz-selection  {
    background: red;
}
.test::selection {
    background: red;
}

However, I am noticing some strange behavior in Chrome when you modify the selection background.

Sometimes the entire element is selected including the padding, sometimes just the text portion is selected, and sometimes a portion of the padding is selected. Below is a link to a jsfiddle, try selecting the Xs. How can I get consistent behavior out of Chrome? (Either all padding or no padding should be selected).

http://jsfiddle.net/L8kzLy6h/3/

If you try it in Firefox, the selection is much more consistent (padding is not selected).

链接地址: http://www.djcxy.com/p/41398.html

上一篇: 如何删除火狐的按钮上的虚线轮廓以及链接?

下一篇: Chrome和Firefox中用于填充元素的文本选择行为