首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >WordPress子CSS与父CSS冲突

WordPress子CSS与父CSS冲突
EN

Stack Overflow用户
提问于 2018-07-17 06:45:22
回答 1查看 153关注 0票数 0

只有我的子主题的样式表中的某些样式正在应用于我的站点,而其他样式被忽略,而我的父主题的样式正在被应用。有什么想法吗?

子主题的functions.php

代码语言:javascript
复制
<?
   add_action ('wp_enqueue_scripts', 
   'senorpicoculinary_child_and_parent_stylesheets');

function senorpicoculinary_child_and_parent_stylesheets() {
    wp_enqueue_style( 
        'parent-style',
        get_template_directory_uri().'/assets/stylesheet.css'); 

    /* For the child style, I didn't use get_directory_uri() because
       that seems to point to style.css, and our styling file is stylesheet.css*/
    wp_enqueue_style( 
        'child-style',
        get_stylesheet_directory_uri().'/assets/stylesheet.css'); 
}
?>

父主题functions.php

代码语言:javascript
复制
function add_theme_scripts() {
  wp_enqueue_style( 
        'generic-style',
    get_stylesheet_directory_uri().'/style.css');
    wp_enqueue_style( 
      'favicon',
      get_template_directory_uri().'/favicon.ico');
  wp_enqueue_style( 
        'bootstrap',
    get_template_directory_uri(). '/assets/bootstrap.min.css');
  wp_enqueue_style( 
        'megamenu-stylesheet',
        get_template_directory_uri(). '/assets/megamenu.css');  
  wp_enqueue_style( 
        'webfont-kit',
    get_template_directory_uri().'/assets/MyFontsWebfontsKit.css'); 

  wp_enqueue_style( 
        'tv-style',
        get_template_directory_uri().'/assets/stylesheet.css');  

}
add_action( 'wp_enqueue_scripts', 'add_theme_scripts' );
?>

CSS子主题

代码语言:javascript
复制
h1 {
    font-family: 'momoco_inlineinline';  //doesn't work
    color: blue; //works
}

body {
    background-color: black; // doesn't work
  }

父主题CSS (全部应用,而不是我的子主题的样式)

代码语言:javascript
复制
h1 {
  font-size: 1.4em;
  margin: 0 0 .5em 0;
  font-family: AvenirLT-Roman;
  border-bottom: 1px solid #CCCCCC;
}
body {
  background-color: #F1F1F1;
  margin: 0;
  padding: 0;
  font-size: 100%;
  font-family: AvenirLT-Roman;
}
EN

回答 1

Stack Overflow用户

发布于 2018-07-17 07:14:17

我要提前告诉你,这被广泛认为不是最好的做法,但我和许多web开发人员都这样做。使用!important强制某些属性。

例如:

代码语言:javascript
复制
h1 {
    font-family: 'momoco_inlineinline' !important;  //this will work ;)
    color: blue; //works
}

body {
    background-color: black !important; // this too :)
  }

理想情况下,您可能希望找出导致这种情况发生的原因,并可能更改您的工作流程。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51371011

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档