css - p :tree TreeNode background-color

标签 css primefaces css-specificity

我有以下场景: 我想使用 PrimeFaces 建立一个网站。以下部分呈现为白色,但它应该是红色的。

        <p:tree value="#{index.root}" var="node" style="width: 100%">
            <p:treeNode type="FAIL" styleClass="fail">
                <span style="cursor: pointer;"
                    onclick="this.parentNode.parentNode.firstChild.click();"> <h:outputText
                        value="#{node}" /> <h:commandButton value="Mark as handled" />
                </span>
            </p:treeNode>
        </p:tree>

索引.css

.fail {
    background-color: red;
    color: white;
}

在 Firefox Inspector 中调查 treeNode 我看到以下结构

firefoxinspector

如果我取消选中 background-color: transparent from .ui-tree .ui-tree-node 部分,树将呈现红色(应该是)。

有人知道为什么浏览器会出现这种行为以及我该如何解决它吗?

谢谢。

最佳答案

原因是,.fail 不如 .ui-tree .ui-tree-node 具体。 检查https://css-tricks.com/specifics-on-css-specificity/https://specificity.keegan.st/查看 css 特异性如何工作。

关于css - p :tree TreeNode background-color,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34611595/

相关文章:

html - 仅使用 CSS 的百分比饼图

javascript - 在 jQuery UI 日期选择器中自定义月份

validation - 如果 inputText 验证失败或 ajax 调用开始,则停用 commandButton 功能

css - CSS 特异性的最佳实践?

css - 如何在不使用 !important 的情况下提高优先级?

html - 溢出滚动已 overflow hidden

html - 我如何使用 CSS 来做到这一点?

css - 禁止子元素从父元素继承样式

java - 自定义在 h :ajax call 之后响应

css - 为什么这个 CSS 选择器不比另一个更具体?