html - 选择性样式 css3

标签 html css

这是我的代码:

<table width="562" cellspacing="0" cellpadding="0" border="0" align="center" class="genericClass">
     Some nested tags
</table>

我的风格是:

table.genericClass  a { ...  } 
table.genericClass  p,li,div,td {}

但是所有的 divp 和所有列出的标签都得到了上面提到的样式,这不是预期的。我的语法有误吗?

最佳答案

现在您正在从 DOM 中选择所有 divlitd。如果您只想将样式添加到具有类 genericClass 的表中的元素,您的代码应该是:

table.genericClass a {
  /**your properties and values here**/
} 
table.genericClass p,
table.genericClass li,
table.genericClass div,
table.genericClass td {
  /**your properties and values here**/
}

或者如果你想单独设置它们的样式:

table.genericClass p{
  /**your properties and values here**/
}
table.genericClass li{
  /**your properties and values here**/
}
table.genericClass div{
  /**your properties and values here**/
}
table.genericClass td {
  /**your properties and values here**/
}

关于html - 选择性样式 css3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41249059/

相关文章:

javascript - 为什么这些警报成倍增加?

php - Eclipse PDT 中的 HTML 所见即所得编辑器

javascript - 将文件拖放到标签上

css - 是否可以将 div 样式设置为梯形?

html - 打破 PDF 中的 html 表格

html - 堆栈显示 :block, 但保留内部文本的宽度 - 这可能吗?

php - 在我的 sidebar.php 文件中将西里尔文编码为 UTF-8,该网站中断

c# - 字符字面量中的字符太多是什么错误

javascript - 如何修复 jQuery SlideToggle 动画故障?

html - 为什么我的页脚会浮到顶部?