html - CSS adjacent sibling selector fails when parent element class is added
问题描述
This works perfectly
.content-wrapper.row-fluid + .footer.row-fluid {
margin-top: 40px;
}
This successfully targets the sibling correctly only on page with body classed path-frontpage
.path-frontpage .footer.row-fluid {}
And this works for the div above footer on page with body classed path-frontpage
.path-frontpage .content-wrapper.row-fluid {}
But this does not set the footer margin-top to zero on page with body classed path-frontpage
. Chrome inspector shows the first rule is in effect. Why? Or rather - how do I get the margin negated just on pages with body class path-frontpage
?
.path-frontpage .content-wrapper.row-fluid + .path-frontpage .footer.row-fluid {
margin-top: 0px;
}
解决方案
True usage
.path-frontpage .content-wrapper.row-fluid + .footer.row-fluid {
margin-top: 0px;
}
For your code to work, html should was like this.
div { border:1px solid #ff0000; height: 30px; }
.content-wrapper.row-fluid + .footer.row-fluid {
margin-top: 40px;
}
.path-frontpage .content-wrapper.row-fluid + .path-frontpage .footer.row-fluid {
margin-top: 0px;
}
<body class="path-frontpage">
<div class="content-wrapper row-fluid">wrapper
</div>
<div class="path-frontpage"> <!-- I added -->
<div class="footer row-fluid">footer
</div>
</div>
</body>
推荐阅读
- javascript - 将 formData 传递给 Express 中间件,Req.body 返回空对象
- c# - WinForms - 当应用程序启动时没有可用的 Internet 连接时 mscorlib.dll 中的 System.Reflection.TargetInvocationException
- node.js - 部署到 Beanstalk 时遇到问题
- javascript - 带有延迟的Javascript无限循环
- javascript - 是否有任何解决方案来处理 Selenium Web 驱动程序中的窗口打印功能弹出“另存为 pdf”?
- github-actions - Github Actions:使用提交摘要确定 npm 版本
- javascript - 在 React Native 中多次调用单选按钮功能
- javascript - 有没有一种优雅的方法可以找到由 moment.js 日期组成的数组的平均日期?
- python - 为什么我会收到 CommandError:App 'appname' 在 heroku 中没有迁移?
- python-3.x - 加入多个熊猫数据框