Skip to content

Commit c314067

Browse files
authored
Merge pull request #716 from OmkarSonawane1230/master
Enhanced Side Navbar Functionality
2 parents 22f5b95 + 3b7d9d0 commit c314067

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

_layouts/default.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<meta name="viewport" content="width=device-width">
88
<link rel="icon" type="image/x-icon" href="/images/logo.png"/>
99
<link rel="stylesheet" href="/css/main.css">
10+
<script src="/script/script.js" defer></script>
1011
<link rel="alternate" type="application/rss+xml" title="RSS" href="/feed.xml">
1112
</head>
1213

css/main.css

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,33 @@ body {
3535
-webkit-box-flex: 1;
3636
-webkit-flex: 1;
3737
-ms-flex: 1;
38-
flex: 1;
3938
max-width: 700px;
4039
}
4140

4241
.navbar {
4342
float: left;
43+
position: -webkit-sticky;
44+
position: sticky;
45+
top: 0;
4446
text-align: left;
47+
height: fit-content;
4548
width: 15em;
4649
padding: 2em;
47-
padding-right: 0;
50+
}
51+
52+
.navbar > ul {
53+
margin: 0;
54+
list-style: none;
55+
position: relative;
56+
line-height: 0;
57+
}
58+
59+
.navbar > ul > li {
60+
margin: .5rem 0;
61+
}
62+
63+
.navbar > ul > li.active {
64+
font-weight: bold;
4865
}
4966

5067
#menuLinkBar {
@@ -64,6 +81,7 @@ body {
6481
display: -ms-flexbox;
6582
display: flex;
6683
margin: 0 auto;
84+
width: 100%;
6785
justify-content: center;
6886
}
6987

@@ -80,13 +98,15 @@ body {
8098
-webkit-order: 2;
8199
-ms-flex-order: 2;
82100
order: 2;
101+
padding: 1em;
83102
}
84103
.navbar {
85104
width: auto;
86105
-webkit-box-ordinal-group:4;
87106
-webkit-order:3;
88107
-ms-flex-order:3;
89108
order:3;
109+
padding: 1em;
90110
}
91111
#menuLinkBar {
92112
display: block;
@@ -795,10 +815,10 @@ pre {
795815
-moz-border-radius: 3px;
796816
-ms-border-radius: 3px;
797817
-o-border-radius: 3px;
818+
white-space: pre-wrap;
798819
border-radius: 3px;
799820
display: block;
800821
padding: 10px 15px 13px 15px;
801-
margin: 0 3em 1em 3em;
802822
background-color: #fff;
803823
border: solid 1px #efeee6;
804824
line-height: 18px;
@@ -2015,7 +2035,7 @@ th, td {
20152035
}
20162036

20172037
img {
2018-
max-width: 100%;
2038+
max-width: 50%;
20192039
}
20202040

20212041
/* Table of contents */

script/script.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const NAVBAR_LI_ELEMENTS = document.getElementById('navbar').firstElementChild.children; // Access all the <li> in side navigation
2+
3+
// check for a match with the <li> element and SITE_URL, then make it active
4+
Array.from(NAVBAR_LI_ELEMENTS).forEach((liElement) => {
5+
if (liElement.firstElementChild.href == location.href) {
6+
liElement.classList.add('active');
7+
return;
8+
}
9+
})

0 commit comments

Comments
 (0)