Skip to content

Commit 99bcd17

Browse files
authored
Merge pull request #999 from EmileTrotignon/sidebar-middle
Move the sidebar to be stuck to left of the content
2 parents 653bec9 + c027a90 commit 99bcd17

File tree

3 files changed

+84
-42
lines changed

3 files changed

+84
-42
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ Tags:
2929

3030
### Changed
3131
- Style: Remove font fallback to Helvetica, Arial (@Julow, #1028)
32+
- Style : Sidebar is now stuck to the left of the content instead of the left
33+
of the viewport (@EmileTrotignon, #999)
3234

3335
### Changed
3436
- Style: Adjusted line height in the TOC to improve readability (@sorawee, #1045)

src/html_support_files/odoc.css

Lines changed: 67 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -263,28 +263,52 @@ body {
263263
}
264264

265265
body {
266-
margin-left: calc(10vw + 20ex);
267-
margin-right: 4ex;
268-
margin-top: 30px;
269-
margin-bottom: 50px;
266+
margin-left: auto;
267+
margin-right: auto;
268+
padding: 0 4ex;
270269
}
271270

272271
body.odoc {
273-
max-width: 100ex;
272+
max-width: 132ex;
273+
display: grid;
274+
grid-template-columns: min-content 1fr;
275+
column-gap: 4ex;
276+
row-gap: 2ex;
274277
}
275278

276279
body.odoc-src {
277280
margin-right: calc(10vw + 20ex);
278281
}
279282

283+
.odoc-content {
284+
grid-row: 4;
285+
grid-column: 2;
286+
}
287+
288+
.odoc-preamble > *:first-child {
289+
/* This make the first thing in the preamble align with the sidebar */
290+
padding-top: 0;
291+
margin-top: 0;
292+
}
293+
280294
header {
281295
margin-bottom: 30px;
282296
}
283297

298+
header.odoc-preamble {
299+
grid-column: 2;
300+
grid-row: 3;
301+
}
302+
284303
nav {
285304
font-family: "Fira Sans", sans-serif;
286305
}
287306

307+
nav.odoc-nav {
308+
grid-column: 2;
309+
grid-row: 2;
310+
}
311+
288312
/* Basic markup elements */
289313

290314
b, strong {
@@ -480,7 +504,7 @@ h4 {
480504
font-size: 1.12em;
481505
}
482506

483-
/* Comment delimiters, hidden but accessible to screen readers and
507+
/* Comment delimiters, hidden but accessible to screen readers and
484508
selected for copy/pasting */
485509

486510
/* Taken from bootstrap */
@@ -759,19 +783,32 @@ td.def-doc *:first-child {
759783
line-height: 1.2;
760784
}
761785

786+
/* When a search bar is present, we need the sticky sidebar to be a bit lower,
787+
so `top` is higher */
788+
789+
.odoc-search + * + .odoc-toc {
790+
--toc-top: calc(var(--search-bar-height) + var(--search-padding-top) + 20px);
791+
max-height: calc(100vh - 2 * var(--toc-top));
792+
top: var(--toc-top)
793+
}
794+
762795
.odoc-toc {
763-
position: fixed;
764-
top: 0px;
765-
bottom: 0px;
766-
left: 0px;
767-
max-width: 30ex;
768-
min-width: 26ex;
769-
width: 20%;
796+
--toc-top: 20px;
797+
width: 28ex;
770798
background: var(--toc-background);
771799
overflow: auto;
772800
color: var(--toc-color);
773801
padding-left: 2ex;
774802
padding-right: 2ex;
803+
grid-row-start: 3;
804+
grid-row-end: 5;
805+
grid-column: 1;
806+
height: fit-content;
807+
border: solid 1px var(--border);
808+
border-radius: 5px;
809+
position:sticky;
810+
max-height: calc(100vh - 2 * var(--toc-top));
811+
top: var(--toc-top)
775812
}
776813

777814
.odoc-toc ul li a {
@@ -789,26 +826,31 @@ td.def-doc *:first-child {
789826
}
790827

791828
:root {
792-
--search-bar-height: 20px;
829+
--search-bar-height: 25px;
830+
--search-padding-top: 1rem;
793831
}
794832

795833
.odoc-search {
796-
--padding-top: 1rem;
797834
position: sticky;
798835
top: 0;
799836
background: var(--main-background);
800-
height: calc(var(--search-bar-height) + var(--padding-top));
837+
/* This amounts to fit-content when the search is not active, but when you
838+
have the search results displayed, you do not want the height of the search
839+
container to change. */
840+
height: calc(var(--search-bar-height) + var(--search-padding-top));
801841
width: 100%;
802-
padding-top: var(--padding-top);
842+
padding-top: var(--search-padding-top);
803843
z-index: 1;
844+
grid-row: 1;
845+
grid-column-start: 1;
846+
grid-column-end: 3;
804847
}
805848

806849

807850
.odoc-search .search-inner {
808851
width: 100%;
809852
position: relative;
810853
left: 0;
811-
transition: left 0.3s, transform 0.3s, width 0.3s;
812854
display: grid;
813855
/* The second column is for the search snake, which has 0 width */
814856
grid-template-columns: 1fr 0fr;
@@ -818,20 +860,13 @@ td.def-doc *:first-child {
818860
background: transparent;
819861
}
820862

821-
.odoc-search:focus-within .search-inner {
822-
/* Search inner is bigger than its parent, but the overflow needs to be
823-
centered. */
824-
left: 50%;
825-
transform: translateX(-50%);
826-
width: 110%;
827-
}
828-
829863
.odoc-search .search-bar {
830864
position: relative;
831865
z-index: 2;
832866
font-size: 1em;
833867
transition: font-size 0.3s;
834868
box-shadow: 0px 0px 0.2rem 0.3em var(--main-background);
869+
height: var(--search-bar-height);
835870
}
836871

837872
.odoc-search:focus-within .search-bar {
@@ -934,7 +969,7 @@ td.def-doc *:first-child {
934969
.odoc-search .search-entry {
935970
color: var(--color);
936971
display: grid;
937-
/* Possible kinds are the following :
972+
/* Possible kinds are the following :
938973
"doc" "type" "mod" "exn" "class" "meth" "cons" "sig" "cons" "field" "val"
939974
and "ext".
940975
As the longest is 5 characters (and the font monospace), we give 5
@@ -1113,6 +1148,11 @@ td.def-doc *:first-child {
11131148
@media only screen and (max-width: 110ex) {
11141149
body {
11151150
margin: 2em;
1151+
padding: 0;
1152+
}
1153+
1154+
body.odoc {
1155+
display: block;
11161156
}
11171157

11181158
.odoc-toc {

0 commit comments

Comments
 (0)