如何使用除主页之外的 CSS 规则

Jak*_*uya 1 html css wordpress

我正在使用此代码

#main-header::after {
content: "";
background-image: url('xxxx');
background-size:cover;
opacity: 1.0;
top: -45%;
left: 0;
bottom: 0;
right: 0;
position: absolute;
z-index: -1;
}
Run Code Online (Sandbox Code Playgroud)

我希望它在除主页之外的所有页面中都能正常工作,因为我有一个全角滑块,我该怎么做?我在 Wordpress 上使用这个自定义 CSS。谢谢!!

Shi*_*rma 12

您可以使用 body 类来使用 class exclude 选择器,例如How to exclude specific class name in CSS selector?

所以你的代码将变成:

body:not(.home) #main-header::after {
content: "";
background-image: url('xxxx');
background-size:cover;
opacity: 1.0;
top: -45%;
left: 0;
bottom: 0;
right: 0;
position: absolute;
z-index: -1;
}
Run Code Online (Sandbox Code Playgroud)