<分区>
假设我有以下标记
<div class="xxx yyy zzz"> <!-- This div is generated by JS and the class names change all the time -->
<div class="aaa"> Hello </div>
</div>
如何在不知道父 div 的类名的情况下仅使用 CSS 来定位父 div 的 css?
Ex: parent.aaa { background: #fff; }
<分区>
假设我有以下标记
<div class="xxx yyy zzz"> <!-- This div is generated by JS and the class names change all the time -->
<div class="aaa"> Hello </div>
</div>
如何在不知道父 div 的类名的情况下仅使用 CSS 来定位父 div 的 css?
Ex: parent.aaa { background: #fff; }
最佳答案
无法使用 CSS 定位元素的父元素。会很好!
您可以使用 javascript 找到该元素,然后将一个类添加到父级,然后为添加的类设置样式:
// javascript - jquery
$(".aaa").parent().addClass("parentClass");
// css
.parentClass {
... your styles ...
}
关于html - 父 div 的 objective-c ss,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18155183/