html - 如何在CSS中带第n个 child ?

标签 html css css-selectors

如何为 html 中除最后一个元素之外的所有元素选择 :nth-child()。

这是有效的吗=

  td:nth-child:not(last-child){

    //Some css//
    }

我正在使用 text-overflow:ellipsis 属性来隐藏 <td> 中表的溢出元素。

使用 even 成功了, odd这个<td>的 child . 我希望在除表的最后一个子节点之外的所有 td block 中使用此省略号。

我已经试过了-

.table-condensed tbody tr  td:nth-child:not(last-child) a
 {
     white-space: nowrap;
    text-overflow: ellipsis;
    width: 150px;
    display: block;
    overflow: hidden;

}

但这显然不是一个技巧。有什么建议吗?

最佳答案

有点啰嗦,但应该可以解决问题:

tr:not(:last-child) > td, tr:last-child > td:not(:last-child) {
    // styles
}

Here's a fiddle

关于html - 如何在CSS中带第n个 child ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16336365/

相关文章:

html - css: float div中的重叠标题h1

php - 将样式从 PHP 移动到头部

HTML:创建子菜单时遇到问题,如何创建第三级菜单?

html - 如何在 html 中将 <img> 正好放在另一个 <img> 下?

javascript - 第一个子样式仅适用于第一个元素

javascript - GameOver 后 Gusser Game 不重新加载页面

IE 中的 CSS 中断

html - <a> 与它的 <li> 父级大小相同,显示为 : table-cell

html - 使 div 响应并设置样式以显示新闻

jquery - 我如何定位 jquery 或 css 中的下一个或同级元素?