【发布时间】:2018-06-28 14:30:18
【问题描述】:
我想为子类 .gm-style .gm-style-iw 的父元素编写样式。我也使用过 :parent ,但它不起作用。这两个类是动态出现在 DOM 中的。
我被困在这里。请帮忙。
【问题讨论】:
-
不,它不工作
标签: css typescript google-maps-markers openinfowindowhtml
我想为子类 .gm-style .gm-style-iw 的父元素编写样式。我也使用过 :parent ,但它不起作用。这两个类是动态出现在 DOM 中的。
我被困在这里。请帮忙。
【问题讨论】:
标签: css typescript google-maps-markers openinfowindowhtml
使用纯 CSS 是不可能的,您可以使用 Javascript 来做到这一点,但没有选择使用纯 CSS 来做到这一点,抱歉。
:parent 是一个概念,说明它在实施时的样子。
编辑 - JS
let a = document.querySelectorAll('.gm-style');
for(let i = 0; i < a.length; i++) {
a[i].parentNode.classList.add('');
}
即使在 IE11 中也应该可以使用,只需将要添加的类及其应获取的样式插入到父级中即可。
【讨论】: