Skip to content

Commit

Permalink
Refactor the css layout to use grid and flex
Browse files Browse the repository at this point in the history
Remove #primary

Remove #primary, take 2

Change primary layout module to CSS grid.

Remove ::before / ::after based clearfixes. When using flex and grid, pseudo-elements are considered flex/grid elements and cause unexpected behavior. Clearfix is a tool to resolve clearing when using float-based layouts. Modern flex/grid-based layouts do not need them.

Main menu: Use flex as layout module.

Main menu cleanup.

Comments, Posts, and Post Navigation: Use flex for layout. Automatic RTL.

Remove errant test data.

- Fixed skip to content link to point to main content (#primary).
- Changed ID for <main> to #primary to preserve original separation between main and sidebar (#secondary).
- Removed superfluous ID reference to #secondary in CSS.
- Cleaned up whitespace triggering Travis errors.

Fix wpcs issues

Cleaning the rebase

Compile CSS

Remove primary div from WooCommerce too

grid-template-columns property doesn't support negative values
  • Loading branch information
mor10 authored and Ismail-elkorchi committed Apr 18, 2020
1 parent 0fb601b commit 31df471
Show file tree
Hide file tree
Showing 25 changed files with 123 additions and 243 deletions.
22 changes: 10 additions & 12 deletions 404.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
get_header();
?>

<div id="primary" class="content-area">
<main id="main" class="site-main">
<main id="primary" class="site-main">

<section class="error-404 not-found">
<header class="page-header">
<h1 class="page-title"><?php esc_html_e( 'Oops! That page can&rsquo;t be found.', '_s' ); ?></h1>
</header><!-- .page-header -->
<section class="error-404 not-found">
<header class="page-header">
<h1 class="page-title"><?php esc_html_e( 'Oops! That page can&rsquo;t be found.', '_s' ); ?></h1>
</header><!-- .page-header -->

<div class="page-content">
<p><?php esc_html_e( 'It looks like nothing was found at this location. Maybe try one of the links below or a search?', '_s' ); ?></p>
<div class="page-content">
<p><?php esc_html_e( 'It looks like nothing was found at this location. Maybe try one of the links below or a search?', '_s' ); ?></p>

<?php
get_search_form();
Expand Down Expand Up @@ -52,11 +51,10 @@
the_widget( 'WP_Widget_Tag_Cloud' );
?>

</div><!-- .page-content -->
</section><!-- .error-404 -->
</div><!-- .page-content -->
</section><!-- .error-404 -->

</main><!-- #main -->
</div><!-- #primary -->
</main><!-- #main -->

<?php
get_footer();
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ My ultra-minimal CSS might make me look like theme tartare but that means less s
* Custom template tags in `inc/template-tags.php` that keep your templates clean and neat and prevent code duplication.
* Some small tweaks in `inc/template-functions.php` that can improve your theming experience.
* 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`.
* 2 sample CSS layouts in `layouts/` for a sidebar on either side of your content.
* 2 sample CSS layouts in `layouts/` made using CSS Grid Layout Module for a sidebar on either side of your content.
Note: `.no-sidebar` styles are not automatically loaded.
* Smartly organized starter CSS in `style.css` that will help you to quickly get your design off the ground.
* Full support for `WooCommerce plugin` integration with hooks in `inc/woocommerce.php`, styling override woocommerce.css with product gallery features (zoom, swipe, lightbox) enabled.
Expand Down
6 changes: 2 additions & 4 deletions archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
get_header();
?>

<div id="primary" class="content-area">
<main id="main" class="site-main">
<main id="primary" class="site-main">

<?php if ( have_posts() ) : ?>

Expand Down Expand Up @@ -45,8 +44,7 @@
endif;
?>

</main><!-- #main -->
</div><!-- #primary -->
</main><!-- #main -->

<?php
get_sidebar();
Expand Down
2 changes: 0 additions & 2 deletions footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

?>

</div><!-- #content -->

<footer id="colophon" class="site-footer">
<div class="site-info">
<a href="<?php echo esc_url( __( 'https://wordpress.org/', '_s' ) ); ?>">
Expand Down
4 changes: 1 addition & 3 deletions header.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<body <?php body_class(); ?>>
<?php wp_body_open(); ?>
<div id="page" class="site">
<a class="skip-link screen-reader-text" href="#content"><?php esc_html_e( 'Skip to content', '_s' ); ?></a>
<a class="skip-link screen-reader-text" href="#primary"><?php esc_html_e( 'Skip to content', '_s' ); ?></a>

<header id="masthead" class="site-header">
<div class="site-branding">
Expand Down Expand Up @@ -57,5 +57,3 @@
?>
</nav><!-- #site-navigation -->
</header><!-- #masthead -->

<div id="content" class="site-content">
6 changes: 2 additions & 4 deletions inc/woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,8 @@ function _s_woocommerce_related_products_args( $args ) {
*/
function _s_woocommerce_wrapper_before() {
?>
<div id="primary" class="content-area">
<main id="main" class="site-main">
<?php
<main id="primary" class="site-main">
<?php
}
}
add_action( 'woocommerce_before_main_content', '_s_woocommerce_wrapper_before' );
Expand All @@ -136,7 +135,6 @@ function _s_woocommerce_wrapper_before() {
function _s_woocommerce_wrapper_after() {
?>
</main><!-- #main -->
</div><!-- #primary -->
<?php
}
}
Expand Down
6 changes: 2 additions & 4 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
get_header();
?>

<div id="primary" class="content-area">
<main id="main" class="site-main">
<main id="primary" class="site-main">

<?php
if ( have_posts() ) :
Expand Down Expand Up @@ -51,8 +50,7 @@
endif;
?>

</main><!-- #main -->
</div><!-- #primary -->
</main><!-- #main -->

<?php
get_sidebar();
Expand Down
26 changes: 15 additions & 11 deletions layouts/content-sidebar.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,26 @@
* Learn more: https://developer.wordpress.org/themes/basics/template-files/
*/

.content-area {
float: left;
margin: 0 -25% 0 0;
width: 100%;
.site {
display: grid;
grid-template-columns: auto 25%;
grid-template-areas:
"header header"
"main sidebar"
"footer footer";
}
.site-header {
grid-area: header;
}
.site-main {
margin: 0 25% 0 0;
grid-area: main;
overflow: hidden; /* Resolves issue with <pre> elements forcing full width. */
}
.site-content .widget-area {
float: right;
overflow: hidden;
width: 25%;
.widget-area {
grid-area: sidebar;
}
.site-footer {
clear: both;
width: 100%;
grid-area: footer;
}

.no-sidebar .content-area {
Expand Down
26 changes: 15 additions & 11 deletions layouts/sidebar-content.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,26 @@
* Learn more: https://developer.wordpress.org/themes/basics/template-files/
*/

.content-area {
float: right;
margin: 0 0 0 -25%;
width: 100%;
.site {
display: grid;
grid-template-columns: 25% auto;
grid-template-areas:
"header header"
"sidebar main"
"footer footer";
}
.site-header {
grid-area: header;
}
.site-main {
margin: 0 0 0 25%;
grid-area: main;
overflow: hidden; /* Resolves issue with <pre> elements forcing full width. */
}
.site-content .widget-area {
float: left;
overflow: hidden;
width: 25%;
.widget-area {
grid-area: sidebar;
}
.site-footer {
clear: both;
width: 100%;
grid-area: footer;
}

.no-sidebar .content-area {
Expand Down
6 changes: 2 additions & 4 deletions page.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
get_header();
?>

<div id="primary" class="content-area">
<main id="main" class="site-main">
<main id="primary" class="site-main">

<?php
while ( have_posts() ) :
Expand All @@ -32,8 +31,7 @@
endwhile; // End of the loop.
?>

</main><!-- #main -->
</div><!-- #primary -->
</main><!-- #main -->

<?php
get_sidebar();
Expand Down
27 changes: 16 additions & 11 deletions sass/layout/_content-sidebar.scss
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
.content-area {
float: left;
margin: 0 (-$size__site-sidebar) 0 0;
width: $size__site-main;
.site {
display: grid;
grid-template-columns: auto ($size__site-sidebar);
grid-template-areas:
"header header"
"main sidebar"
"footer footer";
}

.site-header {
grid-area: header;
}

.site-main {
margin: 0 $size__site-sidebar 0 0;
grid-area: main;
overflow: hidden; /* Resolves issue with <pre> elements forcing full width. */
}

.site-content .widget-area {
float: right;
overflow: hidden;
width: $size__site-sidebar;
.widget-area {
grid-area: sidebar;
}

.site-footer {
clear: both;
width: $size__site-main;
grid-area: footer;
}

@import "no-sidebar";
27 changes: 16 additions & 11 deletions sass/layout/_sidebar-content.scss
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
.content-area {
float: right;
margin: 0 0 0 (-$size__site-sidebar);
width: $size__site-main;
.site {
display: grid;
grid-template-columns: ($size__site-sidebar) auto;
grid-template-areas:
"header header"
"sidebar main"
"footer footer";
}

.site-header {
grid-area: header;
}

.site-main {
margin: 0 0 0 $size__site-sidebar;
grid-area: main;
overflow: hidden; /* Resolves issue with <pre> elements forcing full width. */
}

.site-content .widget-area {
float: left;
overflow: hidden;
width: $size__site-sidebar;
.widget-area {
grid-area: sidebar;
}

.site-footer {
clear: both;
width: $size__site-main;
grid-area: footer;
}

@import "no-sidebar";
12 changes: 0 additions & 12 deletions sass/mixins/_mixins-master.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,6 @@
margin-right: auto;
}

// Clearfix
@mixin clearfix() {
content: "";
display: table;
table-layout: fixed;
}

// Clear after (not all clearfix need this also)
@mixin clearfix-after() {
clear: both;
}

// Column width with margin
@mixin column-width($numberColumns: 3) {
width: map-get($columns, $numberColumns) - ( ( $columns__margin * ( $numberColumns - 1 ) ) / $numberColumns );
Expand Down
2 changes: 1 addition & 1 deletion sass/modules/_accessibility.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@
}

/* Do not show the outline on the skip link target. */
#content[tabindex="-1"]:focus {
#primary[tabindex="-1"]:focus {
outline: 0;
}
18 changes: 0 additions & 18 deletions sass/modules/_clearings.scss

This file was deleted.

Loading

0 comments on commit 31df471

Please sign in to comment.