Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何在svg处于“状态”时转换填充颜色;内容:url(……)”等;_Html_Css_Svg_Css Transitions_Pseudo Element - Fatal编程技术网

Html 如何在svg处于“状态”时转换填充颜色;内容:url(……)”等;

Html 如何在svg处于“状态”时转换填充颜色;内容:url(……)”等;,html,css,svg,css-transitions,pseudo-element,Html,Css,Svg,Css Transitions,Pseudo Element,我试图做的是使用CSS转换来更改“content:url(..)中svg的填充颜色,而不是完全替换图像 HTML: <h3>Hello World</h3> 你好,世界 CSS body: { background-color: #121212; } h3:after { content: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="115" hei

我试图做的是使用CSS转换来更改“content:url(..)中svg的填充颜色,而不是完全替换图像

HTML:

<h3>Hello World</h3>
你好,世界
CSS

body: { background-color: #121212; }

h3:after {
  content: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="115" height="10" viewBox="0 0 115 10"><defs><style>.a{fill:#013963;}</style></defs><title>header-btm-sm-2</title><rect class="a" width="9" height="10"/><rect class="a" x="76" width="9" height="10"/><rect class="a" x="89" width="9" height="10"/><rect class="a" x="13" width="4" height="10"/><rect class="a" x="26" width="4" height="10"/><rect class="a" x="34" width="4" height="10"/><rect class="a" x="55" width="4" height="10"/><rect class="a" x="63" width="4" height="10"/><rect class="a" x="111" width="4" height="10"/><rect class="a" x="102" width="4" height="10"/><rect class="a" x="42" width="9" height="10"/></svg>');
  display: block;
  transition: all .25 ease-in;
}

h3:hover:after {
  content: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="115" height="10" viewBox="0 0 115 10"><defs><style>.a{fill:#f6f6f6;}</style></defs><title>header-btm-sm-2</title><rect class="a" width="9" height="10"/><rect class="a" x="76" width="9" height="10"/><rect class="a" x="89" width="9" height="10"/><rect class="a" x="13" width="4" height="10"/><rect class="a" x="26" width="4" height="10"/><rect class="a" x="34" width="4" height="10"/><rect class="a" x="55" width="4" height="10"/><rect class="a" x="63" width="4" height="10"/><rect class="a" x="111" width="4" height="10"/><rect class="a" x="102" width="4" height="10"/><rect class="a" x="42" width="9" height="10"/></svg>');
}
body:{背景色:#121212;}
h3:之后{
内容:url('data:image/svg+xml;utf8,.a{fill:#013963;}header-btm-sm-2');
显示:块;
过渡期:全部25分钟;
}
h3:悬停:之后{
内容:url('data:image/svg+xml;utf8,.a{fill:#f6f6f6;}header-btm-sm-2');
}

简单的回答是你不能,对不起

更具体地说,您不能跨文档边界设置svg图像的样式。您只能设置内联svg的样式。您的方法的问题是,content属性不允许您在页面中插入或内联内容。基本上,您在那里做的是创建一个“shadow”img标记,因此img标记中有关svg的限制也适用于这里

这个问题已经有了答案。例如,见:

你有多种选择来解决你的问题。您可以内联svg内容,并按照通常的方式设置其样式

然而,有一个巧妙的小把戏大多数人都不知道;这是使用
currentColor
关键字。这样,您就可以使用
color
属性在任何父元素上继承css设置的当前颜色,并在接受颜色的任何其他属性中使用该属性。在本例中,我使用h3元素的颜色作为第一个圆的填充颜色

这种方法的优点是不需要任何关于svg结构的知识,如果它是精心设计的,那就是

svg{
高度:1米;
}
h3{
颜色:红色;
过渡:所有0.5秒
}
h3:悬停{
颜色:绿色
}
你好
简单的回答是你不能,对不起

更具体地说,您不能跨文档边界设置svg图像的样式。您只能设置内联svg的样式。您的方法的问题是,content属性不允许您在页面中插入或内联内容。基本上,您在那里做的是创建一个“shadow”img标记,因此img标记中有关svg的限制也适用于这里

这个问题已经有了答案。例如,见:

你有多种选择来解决你的问题。您可以内联svg内容,并按照通常的方式设置其样式

然而,有一个巧妙的小把戏大多数人都不知道;这是使用
currentColor
关键字。这样,您就可以使用
color
属性在任何父元素上继承css设置的当前颜色,并在接受颜色的任何其他属性中使用该属性。在本例中,我使用h3元素的颜色作为第一个圆的填充颜色

这种方法的优点是不需要任何关于svg结构的知识,如果它是精心设计的,那就是

svg{
高度:1米;
}
h3{
颜色:红色;
过渡:所有0.5秒
}
h3:悬停{
颜色:绿色
}
你好