我有 <div id='mydiv'> 我需要选择所有 pre 和 div 的子元素#mydiv.
I have <div id='mydiv'> and I need to select all pre and div elements that are children of #mydiv.
我可以这样做:
div#mydiv > pre, div#mydiv > div
但是,是否可以做到只引用一次#mydiv?
but, can it be done so that #mydiv is referenced only once?
div#mydiv > pre, div
将选择页面上的所有 div,无论它们是否是 #mydiv 的子级,因此逗号不是一种方法.也许还有另一种我不知道的语法?
will select all divs on the page regardless if they're children of #mydiv, so the comma isn't a way to do it. Maybe there's another kind of syntax I don't know about?
你必须引用 #mydiv 两次...
You'll have to reference #mydiv twice...
#mydiv > pre, #mydiv > div
我删除了无关的 div 元素选择器,因为 ID 足够具体.
I removed the extraneous div element selector as the ID is specific enough.
这篇关于如何选择作为给定元素的子元素的多个元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
:target 为空时的 CSS 选择器CSS selector when :target empty(:target 为空时的 CSS 选择器)
CSS 直接后代 (>) 在选择性方面没有任何价值Does the CSS direct decendant (gt;) not have any value in selectivity?(CSS 直接后代 (gt;) 在选择性方面没有任何价值吗?)
使用 querySelectorAll().方法返回的结果是否有序?Using querySelectorAll(). Is the result returned by the method ordered?(使用 querySelectorAll().方法返回的结果是否有序?)
Safari 错误:当使用 JS 删除项目时,first-child 不更Safari bug :first-child doesn#39;t update display:block when items are removed with JS(Safari 错误:当使用 JS 删除项目时,first-child 不更新
nth-子 CSS 选择器nth-Child CSS selectors(nth-子 CSS 选择器)
对多个 HTML 标签使用相同的 ID?Using same ID for multiple HTML tags?(对多个 HTML 标签使用相同的 ID?)