html - 将媒体查询规则直接添加到 SVG 路径、多边形或矩形
问题描述
我有这个 SVG,它正在通过添加为图像CSS
,但我想在较小的屏幕上隐藏它的一部分。SVG
如果将其本身直接添加到 中,这将不是问题HTML
,但由于我只有这种方式,所以该类不起作用。
甚至可以media query
直接将path, polygon, rect
直接添加到 SVG 本身,还是有其他方法可以做到这一点?
SVG 已作为背景图像添加到 :before 元素中。
所以像这样的事情......
<svg height="210" width="500">
<polygon points="100,10 40,198 190,78 10,78 160,198" style="fill:lime;stroke:purple;stroke-width:5;fill-rule:nonzero;"/>
<polygon style="@media(max-width: 992px) {display: none}" points="150,10 40,108 190,78 10,78 160,198" style="fill:blue;stroke:purple;stroke-width:5;fill-rule:nonzero;"/>
</svg>
解决方案
编辑:我似乎找到了一个部分解决方案:可以<style>
在 SVG 中添加一个标签,并在其中应用 .class 样式......
但它似乎只有当 SVG 是页面上唯一的元素时才有效,而不是在其他元素中......
<svg>
<style type="text/css">
@media screen and (max-width: 992px) {
.class {
display: none;
}
}
</style>
</svg>
推荐阅读
- groovy - Groovy 编译器配置:想要全局 CompileStatic 但关闭 TypeChecking
- angularjs - AngularJS:在ng-options中显示多个值时呈现空选项
- dart - 类型“字符串”不是预期类型“int”的子类型
- postgresql - Postgres 9.6 - jsonb 列中特定字段的平均值,并按同一 jsonb 列中的另一个字段分组
- python - 修改列表元素意外更改了它引用的原始列表
- javascript - 为多个文本区域使用隐藏的输入类型,创建多个插入
- php - 使用 PHP 在 Docker 问题中设置 LEMP
- xamarin.forms - 在 JWT 中使用什么来检查过期时间
- javascript - 如何理解以下代码的逻辑?
- r - dplyr 使用函数参数作为 by.x 和 by.y 在函数侧加入数据框