css - 我可以仅使用 CSS 根据包含的列表项的数量设置 ListView 的样式吗?

标签 css list border

在我的页面上,我有许多 listviews

有些包含单个列表项,有些包含多个元素。我正在寻找一种方法来设置顶部/底部边框,具体取决于仅使用 CSS 的列表项的数量。

所以在单个元素列表中,边框应该是:

listitem > border-top & border-bottom

两个元素列表

listitem > border-top
listitem > border-top & border-bottom

三个以上的元素列表

listitem > border-top
listitem > border-top & border-bottom
listitem > border-bottom

现在我有这个 CSS

.inputList li:not( .inputList li:first-child, .inputList li:last-child) {
    border-top-width: 1px;
    border-bottom-width: 1px;
    }
.inputList li:first-child {
    border-bottom-width: 1px;
    }
.inputList li:last-child {
    border-top-width: 1px;
    }

但这并没有让我走得太远,我正在使用 not: 我宁愿尽量避免(因为缺乏 IE 支持)

知道这是否可能吗?

谢谢!

最佳答案

你只需要

.inputList li:first-child {
   border-top: 1px solid black;
}
.inputList li {
   border-bottom: 1px solid black;
}

有了它,您将始终在顶部和底部以及两者之间有一个边框。

关于css - 我可以仅使用 CSS 根据包含的列表项的数量设置 ListView 的样式吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11793609/

相关文章:

c# - 如何去除 WIndows 10 上的蓝色调整大小窗口边框

javascript - Vue.js 过渡交错不起作用

javascript - JQuery show element 其中有一个元素的类在

css - 1px vs 瘦,IE vs Excel 问题

c# - XAML-Datagrid 跳转到行

python - 如何返回仅对应于特定日期的字符串中分号后的数字?

blackberry - 黑莓上弹出窗口的白色边框

css - 使用指南针 - 不应用 foundation.css 的 css 样式

html - 一个像素在 Firefox 和 chrome 中有所不同

c++ - 对列表和对的混淆