Refactor the css layout to use grid and flex

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
This commit is contained in:
Morten Rand-Hendriksen 2018-01-02 14:57:02 -08:00 committed by Ismail El Korchi
parent 0fb601bdbe
commit 31df4716c8
25 changed files with 123 additions and 243 deletions

22
404.php
View File

@ -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();
@ -52,11 +51,10 @@ get_header();
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();

View File

@ -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.

View File

@ -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() ) : ?>
@ -45,8 +44,7 @@ get_header();
endif;
?>
</main><!-- #main -->
</div><!-- #primary -->
</main><!-- #main -->
<?php
get_sidebar();

View File

@ -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' ) ); ?>">

View File

@ -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">
@ -57,5 +57,3 @@
?>
</nav><!-- #site-navigation -->
</header><!-- #masthead -->
<div id="content" class="site-content">

View File

@ -118,9 +118,8 @@ if ( ! function_exists( '_s_woocommerce_wrapper_before' ) ) {
*/
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' );
@ -136,7 +135,6 @@ if ( ! function_exists( '_s_woocommerce_wrapper_after' ) ) {
function _s_woocommerce_wrapper_after() {
?>
</main><!-- #main -->
</div><!-- #primary -->
<?php
}
}

View File

@ -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() ) :
@ -51,8 +50,7 @@ get_header();
endif;
?>
</main><!-- #main -->
</div><!-- #primary -->
</main><!-- #main -->
<?php
get_sidebar();

View File

@ -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 {

View File

@ -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 {

View File

@ -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() ) :
@ -32,8 +31,7 @@ get_header();
endwhile; // End of the loop.
?>
</main><!-- #main -->
</div><!-- #primary -->
</main><!-- #main -->
<?php
get_sidebar();

View File

@ -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";

View File

@ -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";

View File

@ -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 );

View File

@ -35,6 +35,6 @@
}
/* Do not show the outline on the skip link target. */
#content[tabindex="-1"]:focus {
#primary[tabindex="-1"]:focus {
outline: 0;
}

View File

@ -1,18 +0,0 @@
.clear,
.entry-content,
.comment-content,
.site-header,
.site-content,
.site-footer {
&::before,
&::after {
@include clearfix;
}
&::after {
@include clearfix-after;
}
}

View File

@ -1,7 +1,5 @@
.main-navigation {
clear: both;
display: block;
float: left;
width: 100%;
ul {
@ -27,7 +25,8 @@
&:hover > ul,
&.focus > ul {
left: 100%;
display: block;
left: auto;
}
}
@ -51,7 +50,6 @@
}
li {
float: left;
position: relative;
&:hover > a,
@ -84,7 +82,7 @@
}
.main-navigation ul {
display: block;
display: flex;
}
}
@ -94,17 +92,18 @@
.site-main & {
margin: 0 0 1.5em;
overflow: hidden;
}
.nav-links {
display: flex;
}
.nav-previous {
float: left;
width: 50%;
flex: 1 0 50%;
}
.nav-next {
float: right;
text-align: right;
width: 50%;
text-align: end;
flex: 1 0 50%;
}
}

View File

@ -6,8 +6,6 @@
margin: 0;
padding: 0;
@include clearfix;
.cart-contents {
text-decoration: none;
}
@ -226,8 +224,6 @@ p.stars {
.woocommerce-error,
.woocommerce-noreviews,
p.no-comments {
@include clearfix;
background-color: $woocommerce__color-success;
clear: both;
}

View File

@ -1,6 +1,4 @@
ul.products {
@include clearfix;
margin: 0;
padding: 0;

View File

@ -1,8 +1,6 @@
.single-product {
div.product {
@include clearfix;
position: relative;
.woocommerce-product-gallery {
@ -22,8 +20,6 @@
}
.flex-control-thumbs {
@include clearfix;
margin: 0;
padding: 0;

View File

@ -32,7 +32,6 @@ Nicolas Gallagher and Jonathan Neal https://necolas.github.io/normalize.css/
## Menus
# Accessibility
# Alignments
# Clearings
# Widgets
# Content
## Posts and pages
@ -80,11 +79,6 @@ Nicolas Gallagher and Jonathan Neal https://necolas.github.io/normalize.css/
--------------------------------------------------------------*/
@import "modules/alignments";
/*--------------------------------------------------------------
# Clearings
--------------------------------------------------------------*/
@import "modules/clearings";
/*--------------------------------------------------------------
# Widgets
--------------------------------------------------------------*/

View File

@ -10,8 +10,7 @@
get_header();
?>
<section id="primary" class="content-area">
<main id="main" class="site-main">
<main id="primary" class="site-main">
<?php if ( have_posts() ) : ?>
@ -47,8 +46,7 @@ get_header();
endif;
?>
</main><!-- #main -->
</section><!-- #primary -->
</main><!-- #main -->
<?php
get_sidebar();

View File

@ -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
while ( have_posts() ) :
@ -34,8 +33,7 @@ get_header();
endwhile; // End of the loop.
?>
</main><!-- #main -->
</div><!-- #primary -->
</main><!-- #main -->
<?php
get_sidebar();

View File

@ -32,7 +32,6 @@ Nicolas Gallagher and Jonathan Neal https://necolas.github.io/normalize.css/
## Menus
# Accessibility
# Alignments
# Clearings
# Widgets
# Content
## Posts and pages
@ -626,9 +625,7 @@ a:active {
## Menus
--------------------------------------------------------------*/
.main-navigation {
clear: both;
display: block;
float: right;
width: 100%;
}
@ -655,7 +652,8 @@ a:active {
.main-navigation ul ul li:hover > ul,
.main-navigation ul ul li.focus > ul {
right: 100%;
display: block;
right: auto;
}
.main-navigation ul ul a {
@ -668,7 +666,6 @@ a:active {
}
.main-navigation li {
float: right;
position: relative;
}
@ -690,7 +687,7 @@ a:active {
}
.main-navigation ul {
display: block;
display: flex;
}
}
@ -700,22 +697,25 @@ a:active {
.site-main
.post-navigation {
margin: 0 0 1.5em;
overflow: hidden;
}
.comment-navigation .nav-links,
.posts-navigation .nav-links,
.post-navigation .nav-links {
display: flex;
}
.comment-navigation .nav-previous,
.posts-navigation .nav-previous,
.post-navigation .nav-previous {
float: right;
width: 50%;
flex: 1 0 50%;
}
.comment-navigation .nav-next,
.posts-navigation .nav-next,
.post-navigation .nav-next {
float: left;
text-align: left;
width: 50%;
text-align: end;
flex: 1 0 50%;
}
/*--------------------------------------------------------------
@ -758,7 +758,7 @@ a:active {
}
/* Do not show the outline on the skip link target. */
#content[tabindex="-1"]:focus {
#primary[tabindex="-1"]:focus {
outline: 0;
}
@ -787,35 +787,6 @@ a:active {
margin-bottom: 1.5em;
}
/*--------------------------------------------------------------
# Clearings
--------------------------------------------------------------*/
.clear::before,
.clear::after,
.entry-content::before,
.entry-content::after,
.comment-content::before,
.comment-content::after,
.site-header::before,
.site-header::after,
.site-content::before,
.site-content::after,
.site-footer::before,
.site-footer::after {
content: "";
display: table;
table-layout: fixed;
}
.clear::after,
.entry-content::after,
.comment-content::after,
.site-header::after,
.site-content::after,
.site-footer::after {
clear: both;
}
/*--------------------------------------------------------------
# Widgets
--------------------------------------------------------------*/

View File

@ -32,7 +32,6 @@ Nicolas Gallagher and Jonathan Neal https://necolas.github.io/normalize.css/
## Menus
# Accessibility
# Alignments
# Clearings
# Widgets
# Content
## Posts and pages
@ -626,9 +625,7 @@ a:active {
## Menus
--------------------------------------------------------------*/
.main-navigation {
clear: both;
display: block;
float: left;
width: 100%;
}
@ -655,7 +652,8 @@ a:active {
.main-navigation ul ul li:hover > ul,
.main-navigation ul ul li.focus > ul {
left: 100%;
display: block;
left: auto;
}
.main-navigation ul ul a {
@ -668,7 +666,6 @@ a:active {
}
.main-navigation li {
float: left;
position: relative;
}
@ -690,7 +687,7 @@ a:active {
}
.main-navigation ul {
display: block;
display: flex;
}
}
@ -700,22 +697,25 @@ a:active {
.site-main
.post-navigation {
margin: 0 0 1.5em;
overflow: hidden;
}
.comment-navigation .nav-links,
.posts-navigation .nav-links,
.post-navigation .nav-links {
display: flex;
}
.comment-navigation .nav-previous,
.posts-navigation .nav-previous,
.post-navigation .nav-previous {
float: left;
width: 50%;
flex: 1 0 50%;
}
.comment-navigation .nav-next,
.posts-navigation .nav-next,
.post-navigation .nav-next {
float: right;
text-align: right;
width: 50%;
text-align: end;
flex: 1 0 50%;
}
/*--------------------------------------------------------------
@ -758,7 +758,7 @@ a:active {
}
/* Do not show the outline on the skip link target. */
#content[tabindex="-1"]:focus {
#primary[tabindex="-1"]:focus {
outline: 0;
}
@ -787,35 +787,6 @@ a:active {
margin-bottom: 1.5em;
}
/*--------------------------------------------------------------
# Clearings
--------------------------------------------------------------*/
.clear::before,
.clear::after,
.entry-content::before,
.entry-content::after,
.comment-content::before,
.comment-content::after,
.site-header::before,
.site-header::after,
.site-content::before,
.site-content::after,
.site-footer::before,
.site-footer::after {
content: "";
display: table;
table-layout: fixed;
}
.clear::after,
.entry-content::after,
.comment-content::after,
.site-header::after,
.site-content::after,
.site-footer::after {
clear: both;
}
/*--------------------------------------------------------------
# Widgets
--------------------------------------------------------------*/

View File

@ -72,9 +72,6 @@ table.shop_table_responsive tr td.download-actions .button {
* Products
*/
ul.products {
content: "";
display: table;
table-layout: fixed;
margin: 0;
padding: 0;
}
@ -143,9 +140,6 @@ ul.products li.product .button {
* Single product
*/
.single-product div.product {
content: "";
display: table;
table-layout: fixed;
position: relative;
}
@ -167,9 +161,6 @@ ul.products li.product .button {
}
.single-product div.product .woocommerce-product-gallery .flex-control-thumbs {
content: "";
display: table;
table-layout: fixed;
margin: 0;
padding: 0;
}
@ -284,9 +275,6 @@ ul.products li.product .button {
position: relative;
margin: 0;
padding: 0;
content: "";
display: table;
table-layout: fixed;
}
.site-header-cart .cart-contents {
@ -469,9 +457,6 @@ p.stars.selected a:not(.active)::before {
.woocommerce-error,
.woocommerce-noreviews,
p.no-comments {
content: "";
display: table;
table-layout: fixed;
background-color: #0f834d;
clear: both;
}