[英]Can't override CSS directive with caret selector
I have an SVG file (inline in an HTML page) with about 60 buttons .我有一个 SVG 文件(内嵌在 HTML 页面中),其中包含大约60 个按钮。
Each of them has two additional states , each of which has an ID of the form:他们每个人都有两个额外的状态,每个状态都有一个形式的ID:
<g id="mov0-1"><!-- mouseover state -->
<g id="mod0-1"><!-- mousedown state -->
Initially the mouseover and mousedown states are hidden in CSS :最初 mouseover 和 mousedown 状态隐藏在 CSS 中:
g[id^='mod'] { display: none; }
g[id^='mov'] { display: none; }
When there is a mouseover, the state should change, using this function:当有鼠标悬停时,state应该改变,使用这个 function:
var obj = document.getElementById('link' + c + '-' + x);
obj.addEventListener('mouseover', mov.bind(null, x, c), false);
...
function mov(x, c){
var obj_id = 'mov' + c + '-' + x;
var obj = document.getElementById(obj_id);
obj.style.display = 'block';
}
The above function fails.上面的 function 失败了。 However, if I replace the CSS caret with a list of individual buttons, the function works :
但是,如果我用单个按钮列表替换 CSS 插入符,则 function 有效:
g#mov1-0{display:none;}
g#mod1-0{display:none;}
Why is this happening?为什么会这样?
Is there a way I can keep my elegant two-line solution that hides 120 buttons instead of having to list them all separately?有没有一种方法可以保留隐藏 120 个按钮的优雅的两行解决方案,而不必单独列出它们?
NB the SVG's are generated automatically by Adobe Illustrator, and I can't use CSS classes .注意SVG 是由 Adobe Illustrator 自动生成的,我不能使用CSS 类。
So it was a boneheaded mistake.所以这是一个愚蠢的错误。
The parent objects also had ID's that began with mov and mot , so when I hid the unused buttons, I also hid their parent containers.父对象也有以mov和mot开头的 ID,所以当我隐藏未使用的按钮时,我也隐藏了它们的父容器。
Lesson 1: be careful with wildcards .第 1 课:小心使用通配符。
Lesson 2: when something breaks, don't assume it's because of some elaborate technical thing instead of a stupid error .第 2 课:当出现问题时,不要假设这是因为一些复杂的技术问题而不是愚蠢的错误。
Lesson 3: build a simple test case to reproduce the problem .第 3 课:构建一个简单的测试用例来重现问题。
Renaming the parent containers (Illustrator layers) fixed the problem.重命名父容器(Illustrator 层)解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.