如何在特定页面上应用CSS类?

问题描述 投票:-2回答:3

我有2个自定义帖子类型:

  • 单actress.php
  • 单films.php

我知道可以将特定的CSS类放在前面的文件名中。例:

.single .nameclass(理论上应该只适用于single.php)

...但不是!。这也影响其他自定义帖子类型从单一开始(single-actress.php&single-films.php)

我怎样才能在single.php(Wordpress的正常帖子)中申请,而在其他自定义帖子类型中没有?

php css wordpress class custom-post-type
3个回答
1
投票

在wordpress中,如果要将css应用于特定页面。每个页面都有一个名为page-id-11的唯一类

enter image description here

enter image description here

使用此page-id-11作为父类,您可以专门将css应用于任何页面

希望这可以帮助

如果有帮助,请接受答案


0
投票

不完全确定你的特定情况的细节,但也许css :not()伪类会派上用场。就像是

.single:not(.one-cpt,.another-cpt) {

这可能会或可能会有所帮助,具体取决于您的主题,您的确切目标等。此外,在:not中有多个类可能只在Safari中支持,尽管可能有一个jquery解决方法。


0
投票

在header.php文件中,修改以下行:

<body <?php body_class(); ?>>

对此:

<body <?php body_class('posttype-' . $post->post_type); ?>>

这将为body标签posttype-abcdef添加一个类,以便您可以定位它。

© www.soinside.com 2019 - 2024. All rights reserved.