问题描述
例如,我想执行类似以下的操作:
For example, I'd like to do something like the following:
.myRedPath {
fillcolor: red;
}
...
<v:path class="myRedPath" v="..."/>
以红色填充我的路径。这是否可能与VML元素的填充和笔画属性的颜色和不透明度?如果是,如何?
to fill my paths with a red color. Is this possible with the color and opacity of the fill and stroke attributes for VML elements? If so, how?
推荐答案
如其他答案所述,您可以使用将样式表中指定的任何样式应用于VML元素,因为行为受支持从IE5到IE9。
As mentioned in other answers, you may use DHMTL behaviors to apply any style specified in your style sheet to your VML element as behaviors are supported from IE5 to IE9.
首先创建一个HTC文件,例如:vmlcss.htc:
Start by creating a HTC file, eg: vmlcss.htc:
<PUBLIC:COMPONENT>
<PUBLIC:ATTACH EVENT="onpropertychange" ONEVENT="onpropertychange()" />
<PUBLIC:METHOD NAME="refresh" />
<SCRIPT LANGUAGE="JScript">
function onpropertychange()
{
if (event.propertyName == "className")
{
refresh();
}
}
function refresh()
{
// Set any VML attribute you may define in your stylesheet
element.fillcolor = element.currentStyle["fillcolor"];
element.strokecolor = element.currentStyle["strokecolor"];
// etc.
}
refresh();
</SCRIPT>
</PUBLIC:COMPONENT>
然后将其应用到您的VML元素。对于您的特定示例,您将使用:
Then apply it to your VML elements. For your particular example, you would use:
<style>
v\:path
{
behavior: url(vmlcss.htc);
}
</style>
最后,指定如示例中所示的样式:
Finally, specify the styles as shown in your example:
.myRedPath
{
fillcolor: red;
strokecolor: yellow;
}
您可能想修改行为文件以添加对。
You may want to modify the behavior file to add support for all VML attributes.
可以使用这样的技术来编写一个使用VML或SVG绘制形状的库(取决于浏览器支持),并允许通过CSS设置样式。随后可以使用此类行为文件将对的支持添加到VML对象通过将每个SVG样式映射到相应的VML属性。
One could use such a technique to write a library that draws shapes using VML or SVG (depending on the browser support) and allows styling through CSS. Support for SVG styles could then be added to the VML objects using such a behavior file by mapping each SVG style to the corresponding VML attributes.
这篇关于是否可以使用CSS在VML路径上设置填充和笔触颜色和不透明度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!