html - 仅当元素具有具有特定类的子元素时才选择该元素

标签 html css css-selectors

<分区>

我有这个标记:

<div class="container page-content">

</div>

通常类 page-content 有一个填充:

.container.page-content{
    padding-top: 160px;
}

但在特定页面上,我的 div 中有一个类“item-pagehome”:

<div class="container page-content">
   <div class="item-pagehome">
     Some Content ... 
   </div>
</div>

在这种特殊情况下,我想禁用 .page-content 的 padding-top。但是我该怎么做呢?

我尝试选择:

.page-content:has(> .item-pagehome){
   padding-top: 0px;
}

但这不起作用......

How can I select a div only when it is a specific child class, in this case .item-pagehome?

最佳答案

.container.page-content .item-pagehome {
    margin-top: -160px;
}

关于html - 仅当元素具有具有特定类的子元素时才选择该元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38724222/

相关文章:

html - 使用 bootstrap 和第 n 个子项的下拉菜单样式

html - CSS 在不增加文本大小的情况下增加复选框大小

python - ElementNotInteractableException : element not interactable error while trying to search for stock on www. finanzen.net 使用 Selenium 和 Python

jquery - 根据表格中的行调整字体大小

javascript - 如何通过id获取jquery制作的元素

html - 三级菜单未显示在带有 css 的正确位置

css - 仅限 SIFR'ing <LI> parent

jquery - jquery中的选择器问题

javascript - 从 codepen 复制时,JS 或 CSS 不起作用

javascript - 有人可以用最简单的术语解释如何使用事件监听器吗?