Skip to content

Commit f5f3a0a

Browse files
Merge pull request #1173 from benoitchantre/no-sidebar-class
no-sidebar class
2 parents c4ad625 + 100081f commit f5f3a0a

File tree

8 files changed

+40
-0
lines changed

8 files changed

+40
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ My ultra-minimal CSS might make me look like theme tartare but that means less s
1414
* Some small tweaks in `inc/template-functions.php` that can improve your theming experience.
1515
* A script at `js/navigation.js` that makes your menu a toggled dropdown on small screens (like your phone), ready for CSS artistry. It's enqueued in `functions.php`.
1616
* 2 sample CSS layouts in `layouts/` for a sidebar on either side of your content.
17+
Note: `.no-sidebar` styles are not automatically loaded.
1718
* Smartly organized starter CSS in `style.css` that will help you to quickly get your design off the ground.
1819
* Licensed under GPLv2 or later. :) Use it to make something cool.
1920

inc/template-functions.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ function _s_body_classes( $classes ) {
1717
$classes[] = 'hfeed';
1818
}
1919

20+
// Adds a class of no-sidebar when there is no sidebar present.
21+
if ( ! is_active_sidebar( 'sidebar-1' ) ) {
22+
$classes[] = 'no-sidebar';
23+
}
24+
2025
return $classes;
2126
}
2227
add_filter( 'body_class', '_s_body_classes' );

layouts/content-sidebar.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,12 @@
2323
clear: both;
2424
width: 100%;
2525
}
26+
27+
.no-sidebar .content-area {
28+
float: none;
29+
margin-left: auto;
30+
margin-right: auto;
31+
}
32+
.no-sidebar .site-main {
33+
margin-right: 0;
34+
}

layouts/sidebar-content.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,12 @@
2323
clear: both;
2424
width: 100%;
2525
}
26+
27+
.no-sidebar .content-area {
28+
float: none;
29+
margin-left: auto;
30+
margin-right: auto;
31+
}
32+
.no-sidebar .site-main {
33+
margin-right: 0;
34+
}

sass/layout/_content-sidebar.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@
1818
clear: both;
1919
width: $size__site-main;
2020
}
21+
22+
@import "no-sidebar";

sass/layout/_no-sidebar.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.no-sidebar {
2+
.content-area {
3+
float: none;
4+
margin-left: auto;
5+
margin-right: auto;
6+
}
7+
8+
.site-main {
9+
margin-right: 0;
10+
}
11+
}

sass/layout/_sidebar-content.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@
1818
clear: both;
1919
width: $size__site-main;
2020
}
21+
22+
@import "no-sidebar";

sass/site/_site.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @import "../layout/content-sidebar";
22
// @import "../layout/sidebar-content";
3+
34
/*--------------------------------------------------------------
45
## Posts and pages
56
--------------------------------------------------------------*/

0 commit comments

Comments
 (0)