[英]How to select <html> tag in CSS when the source HTML has multiple nested <html> tags?
I'm working on making a dark mode for the Kaplan website tests so I don't blind myself studying.我正在为 Kaplan 网站测试制作一个黑暗模式,这样我就不会盲目地学习。
The following HTML code is representative of the structure of the source, and the tag with id="stylish-23" is what's added by a chrome extension to change the page's CSS styling:下面的 HTML 代码代表了源的结构,id="stylish-23" 的标签是由 chrome 扩展添加的,用于更改页面的 CSS 样式:
<html> // html 1
<html> // html 2
<html> // html 3
<html> // html 4
<div id="divQuestions"> </div> //actual tag I want to change
</html> // html 4
</html> // html 3
</html> // html 2
<style id="stylish-23" type="text/css">...</style>
</html> // html 1
I put div#divQuestions
in the style tag's CSS and it does not appear to have any effect at all.我将
div#divQuestions
放在样式标签的 CSS 中,它似乎根本没有任何效果。 Due to the nature and limitation of the extension, I'm only able to add CSS to the style tag, and the CSS appears to not be able to select HTML tags (or at least when I do, nothing happens). Due to the nature and limitation of the extension, I'm only able to add CSS to the style tag, and the CSS appears to not be able to select HTML tags (or at least when I do, nothing happens). I've noticed that dragging the style tag into html #4 in developer console will properly apply the CSS.
我注意到将样式标签拖到开发人员控制台中的 html #4 将正确应用 CSS。
The element in question's CSS from inspect:有问题的元素 CSS 来自检查:
My CSS in the style tag:我在样式标签中的 CSS:
div#divQuestions {
background: black;
}
Thanks for the help!谢谢您的帮助!
#divQuestions
selector works for me if I fix the div's closing tag (or even if I don't, as it turns out):如果我修复了 div 的结束标签(或者即使我没有,结果证明),
#divQuestions
选择器对我有用:
<html> <html> <html> <html> <div id="divQuestions"> </div> </html> </html> </html> <style id="stylish-23" type="text/css"> #divQuestions { padding: 48px; background: aliceblue; border: 4px solid blue; } </style> </html>
nth-of-type
is a selector that matches the nth element of their "type". nth-of-type
是匹配其“类型”的第 n 个元素的选择器。
So, you can do this:所以,你可以这样做:
html:nth-of-type(1)
html:nth-of-type(2)
html:nth-of-type(3)
...
Or, you can do this since you said "multiple nested tags":或者,您可以这样做,因为您说过“多个嵌套标签”:
html
html > html
html > html > html
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.