html - 如何排除css中的特定类?
问题描述
这是我的CSS:
.single-post .container {
width: 60%;
}
not(.single-post) .container{
min-width:92%;
}
我想要实现的是:我希望容器宽度在单个帖子页面上为 60%,在其他每个页面上为 92%。所以,我试图通过使用not(.single-post)从第二行代码中排除.single-post类,但它不起作用。
但是,第一行代码工作正常。
解决方案
您可以先声明一般情况,然后再声明更具体的情况。声明的顺序很重要(级联)。运行以下示例进行检查。
.container{
width:92%;
background-color: blue;
}
.single-post .container {
width: 60%;
background-color: red;
}
<!-- normal page -->
<div>
<div class="container">
</div>
</div>
<p> </p>
<!-- single post post page -->
<div class="single-post">
<div class="container">
</div>
</div>
推荐阅读
- arrays - 使用上下文 api 时没有渲染
- node.js - 尝试使用 pm2 启动项目时出现 EADDRINUSE 错误
- javascript - 如何混淆我的 Android 项目资产中的一些 Javascript 文件?
- php - 为每个产品字段添加一个子字段 - Symfony Forms
- java - 我在 java.sql.BatchUpdateException 中遇到错误:ORA-00917:缺少逗号
- mysql - 为什么ansible无法连接MySql?
- katalon-studio - Katalon Analytics 未显示从测试集合执行的所有测试套件的结果
- c# - 从可观察集合中绑定组合框项目源时遇到问题
- java - 使用 ContentCachingRequestWrapper 后缺少所需的请求正文
- javascript - 在服务器上创建 Zip 存档并在客户端下载