Skip to content

Commit 443bc26

Browse files
committed
Use sticky layout
1 parent c5fea0f commit 443bc26

File tree

3 files changed

+37
-29
lines changed

3 files changed

+37
-29
lines changed

src/_layouts/default.html

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,41 @@
2121
</script>
2222
</head>
2323
<body>
24-
<nav class="navbar navbar-dark fixed-top bg-dark flex-md-nowrap p-0 shadow">
24+
<header class="navbar navbar-dark bg-dark flex-md-nowrap p-0 shadow sticky-header">
2525
<a class="navbar-brand col-sm-3 col-md-2 mr-0" href="/">{{ site.title }}</a>
26-
<form class="search-form" action="/search" method="get">
27-
<input class="form-control form-control-dark w-100" type="text" placeholder="Search" aria-label="Search" name="q">
26+
<form class="w-100" action="/search" method="get">
27+
<input class="form-control form-control-dark" type="text" placeholder="Search" aria-label="Search" name="q">
2828
</form>
2929
<ul class="navbar-nav px-3">
3030
<li class="nav-item text-nowrap">
3131
<a class="nav-link" href="https://github.com/railsdoc/railsdoc.github.io">GitHub</a>
3232
</li>
3333
</ul>
34-
</nav>
34+
</header>
3535

3636
<div class="container-fluid">
3737
<div class="row">
38-
<nav class="col-md-2 d-none d-md-block bg-light sidebar">
39-
<div class="sidebar-sticky">
38+
<nav class="col-12 col-md-3 col-xl-2 d-none d-md-block bg-light sidebar-sticky">
39+
<div class="sidebar-content">
4040
{%- include navigation.html -%}
4141
</div>
4242
</nav>
4343

44-
<main role="main" class="col-md-9 ml-sm-auto col-lg-10 px-4">
44+
<!-- <div class="col-12 col-md-3 col-xl-2 bg-light toc-content">
45+
<div>toc-content!</div>
46+
</div> -->
4547

48+
<main role="main" class="col-12 col-md-9 col-xl-10 py-md-3 pl-md-5">
4649
{{ content }}
47-
4850
<footer class="site-footer">
4951
<!-- <span class="site-footer-credits">This page was generated by <a href="https://pages.github.com">GitHub Pages</a>.</span> -->
5052
</footer>
5153
</main>
5254
</div>
5355
</div>
56+
5457
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
55-
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/highlight.min.js"></script>
58+
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/highlight.min.js"></script>
5659
<script src="/assets/js/app.js"></script>
5760
</body>
5861
</html>

src/_sass/railsdoc.scss

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ $grey: #aaa;
33
$red: #cc0000;
44
$dark-red: #990000;
55

6+
$navbar-height: 48px;
7+
68
// global
79
a {
810
color: $red;
@@ -17,18 +19,19 @@ code {
1719
}
1820

1921
// Header
20-
.search-form {
21-
width: 100%;
22+
.sticky-header {
23+
position: sticky;
24+
top: 0;
25+
z-index: 1030;
2226
}
2327

2428
// Sidebar
25-
.sidebar {
26-
position: fixed;
27-
top: 0;
28-
bottom: 0;
29-
left: 0;
29+
.sidebar-sticky {
30+
position: sticky;
31+
order: 0;
32+
top: $navbar-height;
33+
height: calc(100vh - #{$navbar-height});
3034
z-index: 100; /* Behind the navbar */
31-
padding: 48px 0 0; /* Height of navbar */
3235
box-shadow: inset -1px 0 0 rgba(0, 0, 0, .1);
3336

3437
ul {
@@ -41,12 +44,20 @@ code {
4144
}
4245
}
4346

44-
.sidebar-sticky {
47+
.toc-content {
48+
position: sticky;
49+
order: 2;
50+
z-index: 100; /* Behind the navbar */
51+
box-shadow: inset -1px 0 0 rgba(0, 0, 0, .1);
52+
}
53+
54+
.sidebar-content {
4555
position: relative;
46-
top: 0;
47-
height: calc(100vh - 48px);
56+
max-height: calc(100vh - #{$navbar-height});
57+
margin-right: -15px;
58+
margin-left: -15px;
4859
padding-top: .5rem;
49-
overflow-x: hidden;
60+
overflow-x: hidden;
5061
overflow-y: auto; /* Scrollable contents if viewport is shorter than content. */
5162

5263
a {
@@ -75,16 +86,10 @@ code {
7586
}
7687
}
7788

78-
@supports ((position: -webkit-sticky) or (position: sticky)) {
79-
.sidebar-sticky {
80-
position: -webkit-sticky;
81-
position: sticky;
82-
}
83-
}
84-
8589
// Content
8690
[role="main"] {
8791
padding-top: 133px; /* Space for fixed navbar */
92+
order: 1;
8893
}
8994

9095
@media (min-width: 768px) {

src/assets/js/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
$(() => {
2-
$(".sidebar .icon").on("click", function (e) {
2+
$(".sidebar-sticky .icon").on("click", function (e) {
33
$(this).siblings("ul").toggle();
44
this.classList.toggle("icon-opened");
55
});

0 commit comments

Comments
 (0)