簡體   English   中英

如果wordpress上沒有側邊欄,則刪除css

[英]remove css if sidebar is not present on wordpress

對於背景顏色應用程序來說有點奇怪,我有這個主要結構

<section class="main-row">
    <div class="container">
        <div class="row">
            <div id="primary" class="col-sm-12 content-area">
</div>
<div id="secondary" class="col-sm-4 sidebar widget-area">
<div>
</div>
</div>
</section>

在主行上,我應用css編輯媒體查詢以調整寬度:

.main-row {
  padding: 70px 0;
/* background: linear-gradient( to right, #ffffff 0%, #ffffff 62%, #f0f0f0 38%, #f0f0f0 100% ); */
}

現在,如果有側邊欄,則可以使用,但是如果要整頁,我想刪除背景,使其僅變成純白色,是否可以在php中使用? 我只希望邊欄具有可擴展整個高度和寬度的純色背景,但是將容器和行設置為將內容調整為僅1170px,但是如果邊欄為,我希望邊欄為全高度,並且顏色在右側如果左側有側邊欄,則向右和向左。

如果模板使用側邊欄,請使用body_class過濾器向主體添加一個類(將my-sidebar-template.php替換my-sidebar-template.php欄模板名稱):

add_filter('body_class', 'sidebar_template_class');
function sidebar_template_class($classes){
  if(get_page_template_slug(get_the_ID()) == 'my-sidebar-template.php')
      $classes[] = 'has-sidebar';

  return $classes;
}

使用CSS刪除body.has-sidebar后代的任何.main-row的背景:

的CSS

.main-row {
    background: linear-gradient( to right, #ffffff 0%, #ffffff 62%, #f0f0f0 38%, #f0f0f0 100% );
}
.has-sidebar .main-row{
    background: none;
}

終於找到了更實用的解決方案:

.sidebar .inner {
 border-left: none;
margin-left: 59px;
padding-left: 30px;
background-color: #f0f0f0;
margin-right: -3000px;
padding-right: 3000px;
padding-bottom: 3000px;
margin-bottom: -3000px;
margin-top: -130px;
padding-top: 50px;

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM