简体   繁体   English

引导表行 hover 与某些行例外

[英]Bootstrap table row hover with exceptions of some rows

I have a table that supports hovering via class="table-hover" .我有一个支持通过class="table-hover"的表。 However, I want certain rows (that have different colours) not to be highlighted upon hovering.但是,我希望在悬停时不突出显示某些行(具有不同颜色的行)。

I have copied the hover rule from bootstrap and adjusted to it tr.no-hover:我已经从引导程序中复制了 hover 规则并调整为 tr.no-hover:

.table-hover tbody tr.no-hover:hover > td,
.table-hover tbody tr.no-hover:hover > th {
    background-color: inherit;
}

My idea was, that this way it should display the orginal (ie. unhovered) colour of the row, since I wanted the no-hover to genericly apply to differently coloured rows.我的想法是,这样它应该显示行的原始(即未悬停)颜色,因为我希望no-hover一般适用于不同颜色的行。 But that did not work.但这没有用。 Neither did specifying transparent as colour.也没有将transparent指定为颜色。

Essentially, what I need is to remove the hover-effect on some rows.本质上,我需要的是删除某些行的悬停效果。 Is there any way to do this?有没有办法做到这一点?

For everyone interested how to get this to work, I found a solution which works with removing the hover-effect without specifying a seperate hover-colour for each colour in use. 对于每个有兴趣如何使其工作的人,我找到了一种解决方案,它可以消除悬停效果,而无需为每种使用的颜色指定单独的悬停颜色。

http://plnkr.co/edit/phGI6csBqmOXML1spLV4?p=preview http://plnkr.co/edit/phGI6csBqmOXML1spLV4?p=preview

The key point here is to set the custom colour on the tr element, that way the cells will be coloured correctly and additionally with 这里的关键点是在tr元素上设置自定义颜色,这样细胞就会正确着色,另外还有

.table-hover > tbody > tr.no-hover:hover > td,
.table-hover > tbody > tr.no-hover:hover > th {
    background-color: inherit;
}

what is inherited, is the colour of the tr. 继承的是tr的颜色。

Unfortunately I don't have an IE at hand to test its behaviour. 不幸的是,我手头没有IE来测试它的行为。

This is especially useful, when you use custom colours in some of your table rows and the rest should be Bootstrap's default colours. 当您在某些表行中使用自定义颜色时,这尤其有用,其余的应该是Bootstrap的默认颜色。 That way you don't have to replicate Bootstrap's hover colour. 这样您就不必复制Bootstrap的悬停颜色。

Since you need to be more selective in terms of which rows you want the hover effect applied to, it's probably easier to create your own CSS hover effects rather than using bootstrap's table-hover class. 由于您需要在应用悬停效果的行方面更具选择性,因此创建自己的CSS悬停效果可能更容易,而不是使用bootstrap的table-hover类。

Demo (thanks dfsq for the base): http://plnkr.co/edit/INuppBzm7r4r7bqvCJm5?p=preview 演示(感谢dfsq的基础): http ://plnkr.co/edit/INuppBzm7r4r7bqvCJm5?p = preview

You can use the following CSS (using not selector) to apply a background color on hover to table rows without a specific class. 您可以使用以下CSS(使用非选择器)在悬停时将背景颜色应用于没有特定类的表行。

CSS: CSS:

tr:not(.no-hover):hover {
    background-color: green;
}
.table-hover tbody tr.no-hover.success:hover > td,
.table-hover tbody tr.no-hover.success:hover > th {
    background-color: $brand-success;
}

.table-hover tbody tr.no-hover.warning:hover > td,
.table-hover tbody tr.no-hover.warning:hover > th {
    background-color: $brand-warning;
}

and so on, i would say... 等等,我会说......

I could only get this to work with bootstrap by setting a no-hover background color, and using this in both the tr and td class definitions:我只能通过设置无悬停背景颜色来使其与引导程序一起使用,并trtd class 定义中使用它:

<tr class='no-hover'><td class='no-hover'>Some Text</td></tr>

.no-hover {
   background-color: blue;
}

If you want to specify the hover color also, you can add:如果您还想指定 hover 颜色,您可以添加:

.table-hover tbody tr:not(.no-hover):hover td, .table-hover tbody tr:not(.no-hover):hover th {
    background-color: green;
}

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

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