_components.textbook.scss 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /**
  2. * The website contains two main components: the sidebar and the textbook page.
  3. * This file specifies the layout and includes classes to show/hide the sidebar
  4. * on small screens.
  5. *
  6. * The actual styling for the sidebar and page are located in their respective
  7. * component SCSS files. This file manages the layout and width only.
  8. *
  9. * By default, the sidebar is not visible.
  10. *
  11. * [1]: The entire page is positioned relative so that when the page overflows
  12. * (e.g. sidebar open on small screens) the user can't scroll left/right.
  13. * [2]: The sidebar and the textbook page are positioned absolute so that we
  14. * can use translate() on the textbook page to reveal the sidebar.
  15. * [3]: Setting the background color hides the sidebar when it's behind the
  16. * page (otherwise the page is transparent).
  17. *
  18. * When the sidebar is visible:
  19. *
  20. * [4]: Shift the textbook page over to the left. On small screens, the page
  21. * will overflow since the sidebar takes up most of the screen.
  22. * [5]: On larger screens, the page and sidebar have enough room to read them
  23. * simultaneously, so make sure that the page doesn't overflow.
  24. */
  25. $left-sidebar-width: 300px;
  26. $textbook-page-max-width: 950px;
  27. $right-sidebar-width: 220px;
  28. $topbar-height: 60px;
  29. .c-textbook {
  30. /* [1] */
  31. position: relative;
  32. height: 100vh;
  33. overflow: hidden;
  34. margin: 0 0 0 auto;
  35. }
  36. .c-topbar {
  37. background-color: $book-background-color;
  38. position: fixed;
  39. top: 0;
  40. height: $topbar-height;
  41. width: 100%;
  42. left: 0;
  43. padding: $spacing-unit-small $spacing-unit-small 0 $spacing-unit-med * 2;
  44. z-index: 1;
  45. transition: top 250ms, transform 250ms ease; // For animations
  46. }
  47. @include mq($until: tablet) {
  48. .c-topbar.hidetop {
  49. // At desktop, we stop hiding the navbar
  50. top: -250px;
  51. }
  52. }
  53. .c-textbook__sidebar,
  54. .c-textbook__page {
  55. /* [2] */
  56. height: 100vh;
  57. overflow: auto;
  58. position: fixed;
  59. background-color: $book-background-color;; /* [3] */
  60. }
  61. .c-textbook__sidebar {
  62. width: $left-sidebar-width;
  63. top: 0;
  64. left: 0;
  65. }
  66. .c-textbook__page {
  67. width: $textbook-page-width;
  68. transition: transform 250ms ease;
  69. left: 0;
  70. padding: 0 $spacing-unit $spacing-unit-small $spacing-unit-small * 3;
  71. overflow-x: visible;
  72. @include mq($from: laptop) {
  73. // At desktop, we show the right TOC
  74. padding-right: calc(100% - #{$left-sidebar-width} - #{$textbook-page-max-width});
  75. }
  76. &:focus {
  77. /* [2] */
  78. outline: none;
  79. }
  80. }
  81. .sidebar__right {
  82. // By default we hide the sidebar
  83. display: none;
  84. // Spacing for the sidebar
  85. width: $right-sidebar-width - $spacing-unit-small; // To account for the small margin on the right
  86. position: relative;
  87. float: right;
  88. z-index: 1; // Keep sidebar under page content
  89. @include mq($from: tablet) {
  90. // Show right TOC at laptop size
  91. display: block;
  92. }
  93. }
  94. .js-show-sidebar {
  95. .c-textbook__page, .c-topbar {
  96. /* [4] */
  97. transform: translate($left-sidebar-width, 0);
  98. @include mq($from: tablet) {
  99. /* [5] */
  100. width: calc(100% - #{$left-sidebar-width});
  101. }
  102. }
  103. }
  104. .c-textbook__content {
  105. clear: both;
  106. padding-top: $topbar-height * 1.5;
  107. width: 95%;
  108. }
  109. .c-page__nav {
  110. display: flex;
  111. justify-content: space-between;
  112. align-items: center;
  113. padding-top: 30px;
  114. }
  115. // Make sure that the bottom content has the same width as non-sidebar content
  116. .footer, .c-page__nav {
  117. @include mq($from: laptop) {
  118. width: $textbook-page-with-sidebar-width;
  119. }
  120. }
  121. // Scrollbar width
  122. ::-webkit-scrollbar {
  123. width: 5px;
  124. background: #f1f1f1;
  125. }
  126. ::-webkit-scrollbar-thumb {
  127. background: #c1c1c1;
  128. }
  129. main, nav {
  130. scrollbar-width: thin;
  131. }