2016-11-10 74 views
1

我使用的WordPress主題在標題中有一些內聯css,而我試圖更改的其中一項是標題的頂部/底部填充。在內嵌CSS它列爲:Override inline css

<head> 
    ... 
     <style type="text/css" data-type="vc_custom-css"> 
     #site-header:not(.shrink) .site-title { padding: 60px 0 !important; } 
     </style> 
    </head> 

<body class="home page page-id-24236 page-child parent-pageid-5 page-template-default logged-in admin-bar wpb-js-composer js-comp-ver-4.12.1 vc_responsive customize-support"> 
    <div id="page" class="layout-fullwidth"> 
     <div id="site-header-wrapper"> 
      <header id="site-header" class="site-header" role="banner"> 
       <div class="container container-fullwidth"> 
       <div class="header-main logo-position-left header-layout-fullwidth header-style-3"> 
       <div class="site-title">         
        <h1><a href="#" rel="home"></h1>  
       </div> 
       </div> 
       </div> 
      </header> 
     </div> 
    </div> 
</body> 

東北角,#網站標題:{!...重要}不是(.shrink).site標題不會在我的styles.css的工作。

我曾嘗試以下,它仍然不工作:

[style]#site-header:not(.shrink).site-title { padding: 1px 0 !important; } 

我如何得到它的覆蓋?

+0

難道你不恨內嵌樣式?他們真的很臭。我會稍後發佈一個答案.... –

回答

2

風格塊不是樣式表很臭。當主題開發人員將它們放入主題時,我真的很鄙視它。唯一更糟的是內聯樣式(即<div style="padding: 5px !important;">)。那些幾乎不可能克服。

在你的情況下,有一對夫婦的下鍋tastic的方式來解決這個問題哈克。

在你的子主題的functions.php文件,你可以使用下面的(誠然哈克)解決方案:

// We're adding a HIGH priority of 9999 which should cause this to be output AFTER the theme's bad styles. 
add_action('wp_head', 'fix_bad_theme_styles', 9999); 

function fix_bad_theme_styles() { ?> 
    <style type="text/css" data-type="vc_custom-css"> 
      #site-header:not(.shrink) .site-title { padding: 1px 0 !important; } 
    </style> 
<?php } 

如果不工作,甚至hackier方法是把風格的頁腳。它會工作,但它不是最好的做法(如若有此解決方案是!):

add_action('wp_footer', 'fix_bad_theme_styles'); 
+0

你,我的朋友真棒。我已經通過CSS嘗試了本書中的所有內容。 – user3088202

+0

我很高興能幫到你! –

0

嘗試增加更多的特異性您的規則,如:

體.anotherParentClass#網站標題:不是(.shrink).site標題{填充:1px的0重要; }

Example: https://jsfiddle.net/robsilva/wx113Lxo/ 
+0

我嘗試了幾個不同的是,但沒有運氣。我剛剛將模板中的更多代碼添加到了我的問題中。 – user3088202

0

你忘了.site-title:not部分之間的空間。試試這個:

#site-header:not(.shrink) .site-title { padding: 1px 0 !important; } 
+0

試過。不工作。標題中的內聯樣式具有重要的意義。 – user3088202

1

如果您正在使用一個子主題可以覆蓋一個特定的文件如footer.php

所以,你會在同一目錄下創建同名的文件,並複製代碼,你需要