是否可以为 CSS 创建一个数组?
<style>
#info1, #info2, #info3, #info4 {
display: none;
}
</style>
假设我有 20 个由 id="info1"、id="info2"标识 20 次的隐藏 div。但我不想在我的样式中声明#info1、#info2、... #info20。这可以用数组或其他方法来完成吗?
最佳答案
好吧,可以选择使用属性选择器:
[id^="info"] { /* gets all elements where id starting with info */
display: none;
}
您可以找到有关属性选择器的更多信息 here .
关于css - css 中用于多个 ID 的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22307051/