html - 如何选择没有 firstChild 或 nth-child() 的 child 的 child ?

标签 html css

我有一个这样的表:

<div id="unique_id">
    <div></div>
    <div>
        <div>
            <div class="common_class">
                <table>
                </table>
            </div>
        </div>
    </div>
</div>

我想选择 common_class 中的表,但是,我正在选择其他东西。我想要这样的东西:

#unique_id > .common_class > table

但是,这不起作用。为此,div.common_class 必须是 div#unique_id 的子级。

注意:我必须支持 IE7,所以没有 nth-child() 选择器。另外,我试图避免使用 javascript。注意:允许使用 firstChild,但我正在寻找某个点的第二个 div。

GC

最佳答案

#unique_id > .common_class 要求 .common_class#unique_id直接子级(并且这不是你的情况)。

只要避免那里的>:

#unique_id .common_class > table {
  width: 100px;
  height: 100px;
  border: 1px solid red;
}
<div id="unique_id">
    <div></div>
    <div>
        <div>
            <div class="common_class">
                <table>
                </table>
            </div>
        </div>
    </div>
</div>

或者使用精确树:#unique_id > div > div > .common_class > table(但你真的不应该使用这个一种 CSS)。

关于html - 如何选择没有 firstChild 或 nth-child() 的 child 的 child ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41232103/

相关文章:

html - 为什么在 django 中使用 xhtml2pdf 呈现为 pdf 时,html 表中的某些列会崩溃?

html - Bootstrap 示例不呈现灰色框。其他都好吗?

javascript - Contenteditable 元素修改后会更改 ID

html - CSS 优先级规则

javascript - 为什么 div 背景不在第一个之后循环更新?

javascript - jquery 中是否有 linkedin 配置文件 url 的内置验证?

javascript - 将 CSS 属性值与 Eclipse 中的字符串进行比较

javascript - 单击单选按钮后启用<选择> <选项>

html - 如何在不扭曲宽高比的情况下将 1000x1000 图像调整为 200x300 图像

悬停时CSS下拉菜单宽度变化