我想知道如何设置新<meter>标签的样式。
<meter>
<meter value=80 min=0 max=100> 80/100 </meter>
我只想更改背景颜色和值颜色,但找不到正确的CSS属性。对于基于Webkit的浏览器,我发现了以下这些:
meter::-webkit-meter-horizontal-bar { -webkit-appearance: meter; background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#DDD), color-stop(0.2, #EEE), color-stop(0.45, #CCC), color-stop(0.55, #CCC), to(#DDD)); } Pseudo element meter::-webkit-meter-horizontal-optimum-value { -webkit-appearance: meter; background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#AD7), color-stop(0.2, #CEA), color-stop(0.45, #7A3), color-stop(0.55, #7A3), to(#AD7)); } Pseudo element meter::-webkit-meter-horizontal-suboptimal-value { -webkit-appearance: meter; background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#FE7), to(#FE7), color-stop(0.2, #FFC), color-stop(0.45, #DB3), color-stop(0.55, #DB3)); } Pseudo element meter::-webkit-meter-horizontal-even-less-good-value { -webkit-appearance: meter; background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#F77), to(#F77), color-stop(0.2, #FCC), color-stop(0.45, #D44), color-stop(0.55, #D44)); } Pseudo element meter::-webkit-meter-vertical-bar { -webkit-appearance: meter; background: -webkit-gradient(linear, 0% 0%, 100% 0%, from(#DDD), to(#DDD), color-stop(0.2, #EEE), color-stop(0.45, #CCC), color-stop(0.55, #CCC)); } Pseudo element meter::-webkit-meter-vertical-optimum-value { -webkit-appearance: meter; background: -webkit-gradient(linear, 0% 0%, 100% 0%, from(#AD7), to(#AD7), color-stop(0.2, #CEA), color-stop(0.45, #7A3), color-stop(0.55, #7A3)); } Pseudo element meter::-webkit-meter-vertical-suboptimal-value { -webkit-appearance: meter; background: -webkit-gradient(linear, 0% 0%, 100% 0%, from(#FE7), to(#FE7), color-stop(0.2, #FFC), color-stop(0.45, #DB3), color-stop(0.55, #DB3)); } Pseudo element meter::-webkit-meter-vertical-even-less-good-value { -webkit-appearance: meter; background: -webkit-gradient(linear, 0% 0%, 100% 0%, from(#F77), to(#F77), color-stop(0.2, #FCC), color-stop(0.45, #D44), color-stop(0.55, #D44)); }
在哪里可以找到基于壁虎的浏览器(Firefox),Opera和IE的正确CSS属性?
我在Webkit浏览器中使用以下代码对仪表进行了精细的渐变设计:
meter { -webkit-appearance: none; } //Crucial, this will disable the default styling in Webkit browsers meter::-webkit-meter-bar { background: #FFF; border: 1px solid #CCC; } meter::-webkit-meter-optimum-value { background: #87C7DE; background: -moz-linear-gradient(top, #a1d4e6 0%, #6bb4d1 100%); background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #a1d4e6), color-stop(100%, #6bb4d1)); background: -webkit-linear-gradient(top, #a1d4e6 0%, #6bb4d1 100%); background: -o-linear-gradient(top, #a1d4e6 0%, #6bb4d1 100%); background: -ms-linear-gradient(top, #a1d4e6 0%, #6bb4d1 100%); background: linear-gradient(to bottom, #a1d4e6 0%, #6bb4d1 100%); filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#a1d4e6', endColorstr='#6bb4d1',GradientType=0); }
但是,CSS-Tricks的Chris Coyier 建议使用以下HTML代码:
<div class="meter"> <span style="width: 25%"></span> </div>
…而不是HTML5 <meter>或<progress>标记。在目前的时间点(2013年2月),我同意他的看法:
<progress>
更糟糕的是,跨浏览器的情况差异很大,即使在不同的WebKit浏览器之间也是如此。伪元素也不一致。我讨厌这样挂东西,但这确实是另一个话题。可以这么说,对于这些特定的进度条,div / span是目前的问题。
浏览器只是不似乎真的准备好接受新的HTML5标准标签<meter>和<progress>。话虽如此,我建议人们克服对未来直奔的渴望,而宁愿追求视觉上可行的东西,直到进一步注意。我还应该提到,在当前时间点上,当前浏览器对这些标签的支持率为53%……这对我来说不值得,但我将由您的项目自行决定。