如何在表格标题中双击禁用蓝色选择?

时间:2013-12-21 19:53:21

标签: html css

我遵循了表头结构:

<th>
 <a ng-click="sort_by(order)" style="color: #555555;">
   <span ng-transclude="">
       <span class="ng-scope">Some text</span>
   </span>
   <i class="icon-chevron-down"></i>
 </a>
</th>

问题是,当我双击标题链接时,背景被选中(蓝色)并且看起来很乱。

如何避免这种行为?

谢谢,

enter image description here

1 个答案:

答案 0 :(得分:4)

您可以使用user-select:none,这将禁用th元素的选择。

jsFiddle example - 尝试突出显示元素。

th {
    -moz-user-select: none;
    -webkit-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

可以找到对此属性的支持here.


如果您担心支持,可以使用::selection将颜色从蓝色更改为透明。此方法具有 little 更多支持。

jsFiddle example - 尝试突出显示元素。

th::selection {
    color:transparent;
}
th::-moz-selection {
    color:transparent;
}

IE9支持它。 Reference here.

相关问题