html5 progress css,CSS content: attr() on HTML5 progress doesn't work
問題
HTML
CSS
progress { margin: 50px; width:250px; border:0; }
CSS (Attempt 1)
progress:before, progress:after { content: attr(data-value); }
CSS (Attempt 2)
progress::-webkit-progress-bar:before,
progress::-webkit-progress-bar:after { content: attr(data-value); }
progress::-moz-progress-bar:before,
progress::-moz-progress-bar:after { content: attr(data-value); }
CSS (Attempt 3)
progress::-webkit-progress-value:before,
progress::-webkit-progress-value:after { content: attr(data-value); }
progress::-moz-progress-value:before,
progress::-moz-progress-value:after { content: attr(data-value); }
None of the above attempts succeeded. Also tried each of the above versions with different CSS code blocks, for :before and :after.
OBJECTIVE
To inject CSS generated content before and after the HTML5 element. Is this possible?
JsFiddle Demo
http://jsfiddle.net/pankajparashar/MNL2C/
UPDATE
When I use the following CSS it works.
progress::-webkit-progress-bar:before,
progress::-webkit-progress-bar:after { content: '123'; }
CONCLUSION
Apparently when we inject static content in the CSS, it works. But if we use the content from data-* it doesn't.
回答1:
In my original comment, I said:
I don't think this is possible as content within the progress element is never displayed if the browser can already draw the progress bar, similarly to content within an object or iframe.
To put it another way, this classifies progress as a replaced element. Just as with the traditional input and other form elements that are replaced elements, as well as img, CSS2.1 doesn't have much to say about using generated content with it:
Note. This specification does not fully define the interaction of :before and :after with replaced elements (such as IMG in HTML). This will be defined in more detail in a future specification.
It's well-established that Gecko-based browsers choose not to support generated content for replaced elements, whereas WebKit-based browsers allow it to some extent, at least for form elements that are replaced elements. (Interestingly, progress::before and progress::after do not work in any browser.) So if you're asking if it's possible to do this cross-browser, the answer is no, and has always been no.
As for why WebKit browsers can insert strings and not attr() values, I'm not certain. Both CSS2.1 and CSS3 Units and Values state that attr() should take values from attributes of the actual element generating those pseudo-elements, since pseudo-elements can't have attributes themselves anyway. This is where I'm stumped.
Perhaps the browser is incorrectly trying to take the data-value attribute from ::-webkit-progress-bar and ::-webkit-progress-value and not the progress element, which is why content is failing when using attr() but working when using a string.
Perhaps the root of the problem lies in the very fact that you're trying to add generated content to other pseudo-elements, which again seems to work in WebKit browsers for whatever bizarre reason. Unlike the above issue with generated content within replaced elements, the current Selectors 3 spec and the upcoming Selectors 4 spec are both very clear on this: you are not supposed to have more than one pseudo-element per complex selector. Of course, WebKit has infamously flouted various rules when it comes to implementing pseudo-elements, so in hindsight it does not surprise me to see WebKit mess up doing so.
Either way, the real conclusion is that the implementation of CSS generated content is extremely poor beyond the scope of the current standard of CSS2.1 + Selectors, by which I mean generated content for replaced elements such as input and progress, and nesting of pseudo-elements in a single selector.
回答2:
It doesn't accept text all you need to do is to tweak your css.
HTML:
80% Done
CSS:
progress { margin: 0px; width:250px; border:0; }
/* CSS (Attempt 1) */
progress:before, progress:after { content: attr(data-value); }
/* CSS (Attempt 2) */
progress::-webkit-progress-bar:before,
progress::-webkit-progress-bar:after { content: attr(data-value); }
progress::-moz-progress-bar:before,
progress::-moz-progress-bar:after { content: attr(data-value); }
/* CSS (Attempt 3) */
progress::-webkit-progress-value:before,
progress::-webkit-progress-value:after { content: attr(data-value); }
progress::-moz-progress-value:before,
progress::-moz-progress-value:after { content: attr(data-value); }
.percentage{
float: left;
margin-left:100px;
margin-top: -20px;
position: absolute;
display: block;
color: #FFF;
}
回答3:
It appears that @BoltClock is correct - the content: attr(value) is looking for the value attribute on the shadow DOM element of -webkit-progress-value, not on the actual element:
h4 { margin: 2em 0 0; }
progress {
-webkit-appearance: none;
appearance: none;
position: relative;
}
progress::-webkit-progress-value:before {
position: absolute;
right: 0;
bottom: -125%;
}
progress.show-value::-webkit-progress-value:before {
content: attr(value);
}
progress.show-data-value::-webkit-progress-value:before {
content: attr(data-value);
}
progress.show-style::-webkit-progress-value:before {
content: attr(style);
}
progress.show-pseudo::-webkit-progress-value:before {
content: attr(pseudo);
}
attr(value):
attr(data-value):
attr(style):
attr(pseudo)
來源:https://stackoverflow.com/questions/18162649/css-content-attr-on-html5-progress-doesnt-work
總結
以上是生活随笔為你收集整理的html5 progress css,CSS content: attr() on HTML5 progress doesn't work的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: html+店铺+可视化编辑器,开源在线可
- 下一篇: 微型计算机接口位于什么之间,io接口位于