html - 带有::-moz-progress-bar css 的多类选择器

标签 html css css-selectors

我需要根据它们的值用不同的颜色为进度条着色。 我有这个测试片段

<div>
    pbar tests            
    <br>
    <progress class="pbar-0" max="100" value="0"></progress>
    <br>
    <progress class="pbar-10" max="100" value="10"></progress>            
    <br>
    <progress class="pbar-30" max="100" value="30"></progress>
    <br>
    <progress class="pbar-60" max="100" value="60"></progress>
    <br>
    <progress class="pbar-90" max="100" value="90"></progress>
    <br>
    <progress class="pbar-100" max="100" value="100"></progress>
</div>

和下面的CSS

*/*begin progress bar*/
progress,          /* All HTML5 progress enabled browsers */
progress[role]     /* polyfill */
{

    /* Turns off styling - not usually needed, but good to know. */
    appearance: none;
    -moz-appearance: none;
    -webkit-appearance: none;

    /* gets rid of default border in Firefox and Opera. */ 
    border: none;

    /* Needs to be in here for Safari polyfill so background images work as expected. */
    background-size: auto;

    /* Dimensions */
    width: 150px;
    height: 15px;
    border-radius: 3px;

}
/* Polyfill */
progress[role]:after {
    background-image: none; /* removes default background from polyfill */
}
/* Ensure fallback text doesn't appear in polyfill */
progress[role] strong {
    display: none;
}
progress,                          /* Firefox  */ 
progress[role][aria-valuenow] {    /* Polyfill */
    background: #f2f1f1 !important; /* !important is needed by the polyfill */
}
/* Chrome */
progress::-webkit-progress-bar {
    background: #f2f1f1;
}
/* IE10 */
progress {
    color: black;
}
/* Firefox */
progress::-moz-progress-bar { 
    background: black;  
}
/* Chrome */
progress::-webkit-progress-value {
    background: black;
}
/* Polyfill */
progress[aria-valuenow]:before  {
    background: black;
}
.pbar-0,.pbar-10,.pbar-30::-moz-progress-bar {
    background: red;
}

.pbar-60::-moz-progress-bar {
    background: yellow;
}


/*end progress bar*/*

我无法将多个类与 ::-moz-progress-bar 选择器匹配:

.pbar-0,.pbar-10,.pbar-30::-moz-progress-bar {
    background: red;
}

只有 pbar-30 是红色的。我在这里做错了什么?

是否可以像这样编写多重选择器,或者我需要一个一个地编写它们?

最佳答案

您需要在每个类选择器中重复伪元素。

请注意,在这种情况下,您仍然可以将所有三个选择器组合到一个规则中,因为它是完全相同的特定于供应商的伪元素:

.pbar-0::-moz-progress-bar, .pbar-10::-moz-progress-bar, .pbar-30::-moz-progress-bar {
    background: red;
}

当每个选择器都有不同的供应商前缀时,您只需要将选择器组拆分为单独的规则,就像您对其他几个规则所做的那样(例如 progress::-moz-progress-barprogress::-webkit-progress-value)。

关于html - 带有::-moz-progress-bar css 的多类选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23473062/

相关文章:

html - 如何使用 Selenium 测试是否为必填字段触发了 HTML5 验证?

css - 将输入文本显示为跨度,宽度问题

html - 更改备用元素 css 的背景颜色

html - CSS选择与第二个按钮具有相同类的第一个按钮

css - 对属于某个类的已访问链接进行样式设置

javascript - 我怎样才能使这个禁用的输入充当启用的输入并在您单击按钮时滚动?

javascript - 浏览器如何在编码标签内呈现此内联 JavaScript?

javascript - 当我们尝试关闭窗口时鼠标悬停并弹出的弹跳

jquery - 相关类显示

jquery - 如果文档在 30 天内未更新,如何取消突出显示文本