Skip to content

Commit c80251d

Browse files
fix: Center content even if sidenav is present
1 parent 13938b7 commit c80251d

File tree

5 files changed

+51
-21
lines changed

5 files changed

+51
-21
lines changed

src/assets/stylesheets/application.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
@import url('./components/topics.css');
1515
@import url('./components/turbo.css');
1616
@import url('./components/usernames.css');
17+
@import url('./layouts/base.css');
1718
@import url('./layouts/application.css');
1819
@import url('./layouts/authentication.css');
1920
@import url('./layouts/back.css');
2021
@import url('./layouts/banner.css');
21-
@import url('./layouts/base.css');
2222
@import url('./layouts/error.css');
2323
@import url('./layouts/header.css');
2424
@import url('./layouts/modal.css');
Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
.layout__content--application {
2+
--layout-content-gap: var(--space-smaller);
3+
24
display: flex;
3-
max-width: var(--width-larger);
4-
margin-right: auto;
5-
margin-left: auto;
65

7-
gap: var(--space-smaller);
6+
gap: var(--layout-content-gap);
87
}
98

109
@media(max-width: 799px) {
@@ -15,6 +14,23 @@
1514

1615
@media(min-width: 800px) {
1716
.layout__content--application {
18-
gap: var(--space-medium);
17+
--layout-content-gap: var(--space-medium);
1918
}
2019
}
20+
21+
.layout__content--application:has(.sidenav) {
22+
/* Extend the max-width so it can contain the content + 2 sidebars. This
23+
* allows to center the content on the page when the screen is large
24+
* enough.
25+
*/
26+
max-width: calc(
27+
var(--layout-content-width)
28+
+ 2 * var(--layout-content-padding)
29+
+ 2 * (var(--sidenav-width) + var(--layout-content-gap))
30+
);
31+
}
32+
33+
.layout__content--application:has(.sidenav) .layout__body {
34+
margin-right: 0;
35+
margin-left: 0;
36+
}

src/assets/stylesheets/layouts/authentication.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
.layout__content--authentication {
2+
--layout-content-width: 100%;
3+
24
display: flex;
5+
margin-right: 0;
6+
margin-left: 0;
37

48
align-items: stretch;
59
justify-content: stretch;

src/assets/stylesheets/layouts/base.css

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,32 @@
2424
}
2525

2626
.layout__content {
27-
padding: var(--space-smaller);
27+
--layout-content-padding: var(--space-smaller);
28+
--layout-content-width: var(--width-large);
29+
30+
max-width: var(--layout-content-width);
31+
margin-right: auto;
32+
margin-left: auto;
33+
padding: var(--layout-content-padding);
2834

2935
flex: 1;
3036
}
3137

3238
@media (min-width: 800px) {
3339
.layout__content {
34-
padding: var(--space-medium);
40+
--layout-content-padding: var(--space-medium);
3541
}
3642

3743
.layout--connected .layout__content:has(.layout__back),
3844
.layout--connected .layout__content:has(.layout__search) {
39-
margin-top: calc(-1 * var(--space-medium));
45+
margin-top: calc(-1 * var(--layout-content-padding));
4046
}
4147
}
4248

4349
.layout__body {
4450
--layout-body-flow: var(--space-medium);
4551

46-
max-width: var(--width-large);
52+
max-width: var(--layout-content-width);
4753
margin-right: auto;
4854
margin-left: auto;
4955
padding: var(--layout-body-flow) var(--space-smaller);

src/assets/stylesheets/layouts/sidenav.css

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
:root {
2+
--sidenav-width: 17rem;
3+
}
4+
5+
@media (min-width: 800px) and (max-width: 1300px) {
6+
:root {
7+
--sidenav-width: 11rem;
8+
}
9+
}
10+
11+
.sidenav__menu {
12+
width: var(--sidenav-width);
13+
}
14+
115
@media (max-width: 799px) {
216
.sidenav__container {
317
position: fixed;
@@ -55,7 +69,7 @@
5569
}
5670

5771
.sidenav__open-button[aria-expanded="true"] + .sidenav__container .sidenav__menu {
58-
width: 17rem;
72+
width: var(--sidenav-width);
5973
}
6074
}
6175

@@ -64,16 +78,6 @@
6478
.sidenav__close-button {
6579
display: none;
6680
}
67-
68-
.sidenav__menu {
69-
width: 11rem;
70-
}
71-
}
72-
73-
@media (min-width: 1200px) {
74-
.sidenav__menu {
75-
width: 16rem;
76-
}
7781
}
7882

7983
.sidenav__menu-item {

0 commit comments

Comments
 (0)