3

在此处输入图像描述

当您选择交叉线时,上图显示了黄色区域之外不需要的红色选择。我想在黄色部分内选择,如下所示:

在此处输入图像描述

HTML:

<div id="parent">
    <div id="child">
        This is some content... This is a long lonnnnnnng content.
    </div>
</div>

CSS:

#parent {
    width: 200px;
    background-color: #666;
}

#child {
    padding: 50px;
    background-color: #ff0;
}

::selection {
    background-color: #f00;
}

你知道如何实现这一目标吗?

在这里运行代码:http: //jsfiddle.net/3AESf/

4

2 回答 2

3

您可以使用display: inline-block;on#parent来解决它

于 2013-02-02T08:25:36.110 回答
0

如果display:inline-block不是一种选择,另一种解决方案是添加

overflow: hidden;

#parent. 这也有效。

于 2013-02-02T09:06:37.357 回答