将CSS应用于除具有特定父元素的元素之外的所有元素 [英] Apply css to all element except one who has specific parent

查看:199
本文介绍了将CSS应用于除具有特定父元素的元素之外的所有元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将CSS应用于除侧边栏之外的所有页面。让我给你看一个例子

I want to apply CSS to all pages except sidebars. Let me show you an example

.page #buddypress ul.group li

我想将CSS应用于所有< li> 标记是 ul.group 类的子级。这里的问题是,此类在侧边栏中也存在,并且我不想更改侧边栏的样式。我只想将CSS应用于页面部分而不是侧边栏。

I want to apply CSS to all <li> tags that are children of ul.group class. Problem here is that this class is also exist in sidebar and I don't want to change styling of sidebar. I just want to apply CSS to the page section and not to the sidebar.

我除了某种:not(.class)操作来做到这一点。

I except some kind of :not(.class) operation to do that.

这是我要尝试的

.page :not(.sidebar) #buddypress ul.group li

但是这个技巧对我不起作用。我真的很感谢有人能解决我的问题。我想将CSS应用于除侧边栏之外的所有部分。

But this trick doesn't work for me. I really appreciate if someone could solve my problem. I want to apply CSS to all sections except sidebar.

这是我的HTML外观:

Here is what my HTML looks like:

<body>
<div id="buddypress">
<ul class="groups">
<li> </li>
</div>
<div class="sidebar">
<ul class="groups">
<li> </li>
</div>


推荐答案

尝试此代码

div:not(.sidebar) ul.group li {
  border: 1px solid red;
}
// Here i have used div, but you can use whatever tag you have used for sidebar

<body class="page">

  <div class="sidebar">
    <ul class="group">
      <li>1</li>
      <li>2</li>
      <li>3</li>
    </ul>
  </div>
  
  <div class="page-section">
    <ul class="group">
      <li>1</li>
      <li>2</li>
      <li>3</li>
    </ul>
  </div>
  
</body>

这篇关于将CSS应用于除具有特定父元素的元素之外的所有元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆