问题

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相关推荐

  1. HTML5实践 -- 使用css装饰你的图片画廊 - part2

    转载请注明原创地址:http://www.cnblogs.com/softlover/archive/2012/11/20/2779893.html 在上一讲中,我们的解决方案使用到了jquery去创 ...

  2. inline-block是html5,详解CSS display:inline-block的应用

    本文详细描述了display:inline-block的基础知识,产生的问题和解决方法以及其常见的应用场景,加深了对inline-block应用的进一步理解. 基础知识 display:inline- ...

  3. html 画廊代码,HTML5实践-使用css装饰图片画廊的代码分享(二)

    在上一讲中,我们的解决方案使用到了jquery去创建一个span标签.在这一讲中我们将用一种更好的解决方式,使用:before 和 :after 伪类.:before经常会用到,他可以用来添加额外的元 ...

  4. 好程序员HTML5前端教程-css的引入方式和选择器

    好程序员HTML5前端教程-css的引入方式和选择器 01.引入css方式(重点掌握) 行内样式 内接样式 外接样式 3.1 链接式 3.1 导入式 css介绍 现在的互联网前端分三层: HTML:超 ...

  5. html5的calc,CSS 计算属性 calc()的完整指南(下)

    calc() 只作用于属性值 calc() 用于长度和其他数值 不能在媒体查询中使用 混合单位 与预处理器数学比较 本文接着之前未完的工作,恰好是周末,一次把它完成.如果我的工作对你有帮助,希望可以点 ...

  6. CSS中的长度单位和HTML5中多媒体标签的使用

    CSS中的长度单位和HTML5中多媒体标签的使用 第一部分.长度单位 1.基本长度单位 2.长度单位的换算 第二部分.vw.vh.vmin.vmax 1.vw.vh.vmin.vmax的含义 2.vw ...

  7. HTML5七夕情人节表白网页(情人节满屏爱心HTML5特效) HTML+CSS+JS 求婚 html生日快乐祝福代码网页 520情人节告白代码 程序员表白源码 抖音3D旋转相册 js烟花代码

    HTML5七夕情人节表白网页❤情人节满屏爱心HTML5特效❤ HTML+CSS+JS 求婚 html生日快乐祝福代码网页 520情人节告白代码 程序员表白源码 抖音3D旋转相册 js烟花代码 css爱 ...

  8. 7.18 阿里巴巴企业黄页HTML实现、HTML标签介绍、frameset框架、HTML5标签、CSS

    阿里巴巴企业黄页HTML实现.HTML标签介绍.frameset框架.HTML5标签.CSS 一.阿里巴巴企业黄页HTML 二.HTML标签介绍 三.frameset框架.iframe框架 frame ...

  9. html自动平分宽度,HTML5使用纯CSS实现“按比例平分”整个垂直空间

    HTML5使用纯CSS实现"按比例平分"整个垂直空间 需求 需要实现头部固定在"屏幕"上方+中部滚动+底部固定在"屏幕"下方的页面布局样式. ...

最新文章

  1. 【Qt】设置窗口透明度
  2. 解决ASP.NET中的各种乱码问题
  3. jdbc oracle存储过程,java jdbc 执行oracle存储过程
  4. 字符串匹配BF/RK/BM/KMP算法
  5. python画柱状图-python plotly画柱状图代码实例
  6. xshell常用指令
  7. C语言实现贪吃蛇小游戏
  8. 截图工具当前未在计算机上运行 请重启_截图并订在屏幕上 用作对比、对照、参考,非常实用...
  9. 【应急响应】————7、服务器大量发包
  10. C# 使用openxml解析PPTX中的文本内容
  11. Cfree-5各种抽风解决办法
  12. [matlab]三维画图
  13. 【记录】前端知识点 - Vue
  14. 微信小程序——获取用户unionId
  15. c#读蓝牙数据_通过蓝牙接收数据到c#程序
  16. 基于C语言的词法分析器构建
  17. Kafka安装与验证
  18. Ubuntu 20.04 系统最快安装WRF软件手册
  19. java outputstream乱码_OutputStream 输出有乱码
  20. 壮实学数据技术05:数据调度

热门文章

  1. c#对象集合去重_C# List集合去重操作注意点
  2. 机器人水库涵洞检测_2019 届高三上学期期末教学质量检测原创卷 03
  3. html的vue项目怎么兼容ie,vue 项目在ie浏览器的兼容问题
  4. c语言怎么判断是不是标识符,C语言判断输入是否为C语言标识符(示例代码)
  5. linux如何把nfs数据导出来,linux – NFS导出已经挂载NFS的目录(在服务器上)
  6. linux shell 脚本 2,理解Linux Shell和基本的Shell脚本(2)
  7. 不显示调用super_让不懂编程的人爱上iPhone开发(2017秋iOS11+Swift4+Xcode9版)-第7篇
  8. 谈谈程序链接及分段那些事
  9. 释放linux 内存
  10. html5测试 2345,HTML5实例测试