From 6e90e520d60dc7dad28f6e3976c4c386746bad1a Mon Sep 17 00:00:00 2001 From: Shane Nelson Date: Sun, 17 Dec 2017 22:53:25 -0500 Subject: [PATCH 1/4] Avoid resizing page/content on sidebar toggle --- src/theme/book.css | 28 +++++++++++++--------------- src/theme/stylus/general.styl | 1 + src/theme/stylus/page.styl | 22 ++++++++++------------ src/theme/stylus/variables.styl | 3 ++- 4 files changed, 26 insertions(+), 28 deletions(-) diff --git a/src/theme/book.css b/src/theme/book.css index 4699400d..6417c67b 100644 --- a/src/theme/book.css +++ b/src/theme/book.css @@ -6,6 +6,7 @@ body { body { margin: 0; font-size: 1rem; + overflow-x: hidden; } code { font-family: "Source Code Pro", Consolas, "Ubuntu Mono", Menlo, "DejaVu Sans Mono", monospace, monospace; @@ -109,28 +110,25 @@ table thead td { white-space: nowrap; } .page-wrapper { - padding-left: 300px; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; min-height: 100%; - -webkit-transition: padding-left 0.5s, margin-right 0.5s; - -moz-transition: padding-left 0.5s, margin-right 0.5s; - -o-transition: padding-left 0.5s, margin-right 0.5s; - -ms-transition: padding-left 0.5s, margin-right 0.5s; - transition: padding-left 0.5s, margin-right 0.5s; -} -@media only screen and (max-width: 1060px) { - .page-wrapper { - padding-left: 0; - } -} -.sidebar-hidden .page-wrapper { - padding-left: 0; + width: 100%; + -webkit-transition: padding-left 0.5s, margin-left 0.5s; + -moz-transition: padding-left 0.5s, margin-left 0.5s; + -o-transition: padding-left 0.5s, margin-left 0.5s; + -ms-transition: padding-left 0.5s, margin-left 0.5s; + transition: padding-left 0.5s, margin-left 0.5s; } .sidebar-visible .page-wrapper { padding-left: 300px; - margin-right: -300px; +} +@media only screen and (max-width: 1079px) { + .sidebar-visible .page-wrapper { + padding-left: 0; + margin-left: 300px; + } } .page { outline: 0; diff --git a/src/theme/stylus/general.styl b/src/theme/stylus/general.styl index 9a5cc974..9d2ff94c 100644 --- a/src/theme/stylus/general.styl +++ b/src/theme/stylus/general.styl @@ -6,6 +6,7 @@ html, body { body { margin: 0; font-size: 1rem; + overflow-x: hidden } code { diff --git a/src/theme/stylus/page.styl b/src/theme/stylus/page.styl index 447444a5..8ba72245 100644 --- a/src/theme/stylus/page.styl +++ b/src/theme/stylus/page.styl @@ -1,26 +1,24 @@ @require 'variables' .page-wrapper { - padding-left: $sidebar-width box-sizing: border-box min-height: 100% + width: 100% // Animation: slide away - transition: padding-left 0.5s, margin-right 0.5s - - @media only screen and (max-width: $max-page-width-with-hidden-sidebar) { - padding-left: 0 - } -} - -.sidebar-hidden .page-wrapper { - padding-left: 0 + transition: padding-left 0.5s, margin-left 0.5s } .sidebar-visible .page-wrapper { padding-left: $sidebar-width - margin-right: - $sidebar-width +} + +@media only screen and (max-width: $page-plus-sidebar-width - 1) { + .sidebar-visible .page-wrapper { + padding-left: 0 + margin-left: $sidebar-width + } } .page { @@ -30,7 +28,7 @@ .content { margin-left: auto - margin-right:auto + margin-right: auto max-width: $content-max-width padding-bottom: 50px diff --git a/src/theme/stylus/variables.styl b/src/theme/stylus/variables.styl index db1609bd..c02af07b 100644 --- a/src/theme/stylus/variables.styl +++ b/src/theme/stylus/variables.styl @@ -1,4 +1,5 @@ $sidebar-width = 300px $page-padding = 15px -$max-page-width-with-hidden-sidebar = 1060px $content-max-width = 750px +$max-page-width-with-hidden-sidebar = 1060px +$page-plus-sidebar-width = $content-max-width + $sidebar-width + $page-padding * 2 From 71689da6b151c922f0bb69c54f0bc6545d585652 Mon Sep 17 00:00:00 2001 From: Shane Nelson Date: Fri, 13 Oct 2017 18:25:12 -0400 Subject: [PATCH 2/4] Force hidden sidebar on load for screen widths smaller than sidebar plus content and simplify styles --- src/theme/book.css | 24 +++++------------------- src/theme/book.js | 8 -------- src/theme/index.hbs | 7 ++++--- src/theme/stylus/nav-icons.styl | 16 +++++----------- src/theme/stylus/sidebar.styl | 8 -------- 5 files changed, 14 insertions(+), 49 deletions(-) diff --git a/src/theme/book.css b/src/theme/book.css index 6417c67b..cce56a22 100644 --- a/src/theme/book.css +++ b/src/theme/book.css @@ -67,20 +67,12 @@ table thead td { -ms-transition: left 0.5s; transition: left 0.5s; } -@media only screen and (max-width: 1060px) { - .sidebar { - left: -300px; - } -} .sidebar code { line-height: 2em; } .sidebar-hidden .sidebar { left: -300px; } -.sidebar-visible .sidebar { - left: 0; -} .chapter { list-style: none outside none; padding-left: 0; @@ -243,26 +235,20 @@ table thead td { text-decoration: none; } .previous { - left: 315px; + left: 15px; -webkit-transition: left 0.5s; -moz-transition: left 0.5s; -o-transition: left 0.5s; -ms-transition: left 0.5s; transition: left 0.5s; } -@media only screen and (max-width: 1060px) { - .previous { - left: 15px; - } -} .next { right: 15px; } -.sidebar-hidden .previous { - left: 15px; -} -.sidebar-visible .previous { - left: 315px; +@media only screen and (min-width: 1251px) { + .sidebar-visible .previous { + left: 315px; + } } @media only screen and (max-width: 1060px) { .nav-wrapper { diff --git a/src/theme/book.js b/src/theme/book.js index 0f147a22..c85e7be1 100644 --- a/src/theme/book.js +++ b/src/theme/book.js @@ -68,14 +68,6 @@ $( document ).ready(function() { // Toggle sidebar $("#sidebar-toggle").click(sidebarToggle); - // Hide sidebar on section link click if it occupies large space - // in relation to the whole screen (phone in portrait) - $("#sidebar a").click(function(event){ - if (sidebar.width() > window.screen.width * 0.4) { - sidebarToggle(); - } - }); - // Scroll sidebar to current active section var activeSection = sidebar.find(".active"); if(activeSection.length) { diff --git a/src/theme/index.hbs b/src/theme/index.hbs index bc5855f4..9df89a7e 100644 --- a/src/theme/index.hbs +++ b/src/theme/index.hbs @@ -62,9 +62,10 @@ {{#previous}} diff --git a/src/theme/stylus/nav-icons.styl b/src/theme/stylus/nav-icons.styl index 222cf444..d756a8f8 100644 --- a/src/theme/stylus/nav-icons.styl +++ b/src/theme/stylus/nav-icons.styl @@ -9,6 +9,7 @@ margin: 0 max-width: 150px min-width: 90px + display: flex justify-content: center align-content: center @@ -17,23 +18,38 @@ transition: color 0.5s } -.mobile-nav-chapters { display: none } .nav-chapters:hover { text-decoration: none } -.previous { - left: $page-padding - transition: left 0.5s -} -.next { right: $page-padding } - -@media only screen and (min-width: 1251px) { - .sidebar-visible .previous { - left: $sidebar-width + $page-padding - } -} .nav-wrapper { - @media only screen and (max-width: $max-page-width-with-hidden-sidebar) { - max-width: $content-max-width - margin: 0 auto - } + margin-top: 50px + display: none +} + +.mobile-nav-chapters { + font-size: 2.5em + text-align: center + text-decoration: none + width: 90px + border-radius: 5px +} + +.previous { + float: left +} + +.next { + float: right + right: $page-padding +} + +@media only screen and (max-width: $page-plus-sidebar-width) { + .nav-chapters { display: none } + .nav-wrapper { display: block } +} + +@media only screen and (max-width: $page-plus-sidebar-width + $sidebar-width) { + .sidebar-visible { + .nav-chapters { display: none } + .nav-wrapper { display: block } + } } diff --git a/src/theme/stylus/theme-popup.styl b/src/theme/stylus/theme-popup.styl index 2a0a87b0..fc51bc35 100644 --- a/src/theme/stylus/theme-popup.styl +++ b/src/theme/stylus/theme-popup.styl @@ -21,37 +21,4 @@ } } -} - -@media only screen and (max-width: $max-page-width-with-hidden-sidebar) { - - .nav-chapters { - display: none - } - - .mobile-nav-chapters { - font-size: 2.5em - text-align: center - text-decoration: none - - max-width: 150px - min-width: 90px - - justify-content: center - align-content: center - - position: relative - display: inline-block - margin-bottom: 50px - - border-radius: 5px - } - - .next { - float: right - } - - .previous { - float: left - } -} +} \ No newline at end of file diff --git a/src/theme/stylus/variables.styl b/src/theme/stylus/variables.styl index c02af07b..3d2c95b2 100644 --- a/src/theme/stylus/variables.styl +++ b/src/theme/stylus/variables.styl @@ -1,5 +1,4 @@ $sidebar-width = 300px $page-padding = 15px $content-max-width = 750px -$max-page-width-with-hidden-sidebar = 1060px $page-plus-sidebar-width = $content-max-width + $sidebar-width + $page-padding * 2