Skip to content

Commit ba78582

Browse files
To1nedscho
authored andcommitted
css: make the header responsive
The icon to toggle between dark and light mode was added recently and this made laying out the elements in the header hard. A lot of items in the header have been using `position: absolute`. This was probably caused by the absolute positioning of the search result dropdown. Transition most elements in the header to use flexbox to make positioning more fluid and require less manual pixel pushing. Signed-off-by: Toon Claes <[email protected]>
1 parent d91a0f8 commit ba78582

File tree

7 files changed

+76
-53
lines changed

7 files changed

+76
-53
lines changed

assets/js/application.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ var DarkMode = {
567567
|| (!prefersDarkScheme && currentTheme === "dark")) {
568568
button.attr("src", `${baseURLPrefix}images/light-mode.svg`);
569569
}
570-
button.show();
570+
button.css("display", "block");
571571

572572
button.click(function(e) {
573573
e.preventDefault();

assets/sass/application.scss

+3-5
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,11 @@ pre {
5454

5555
#dark-mode-button {
5656
display: none;
57-
z-index: 10;
58-
position: absolute;
59-
top: 6px;
60-
right: -50px;
61-
width: 35px;
57+
width: 28px;
6258
background-color: transparent;
6359
text-decoration: none;
60+
align-self: center;
61+
margin: 5px;
6462
}
6563

6664
@media (max-width: $default + 100) {

assets/sass/forms.scss

+2-9
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,10 @@ input, textarea {
3131
}
3232

3333
form#search {
34-
position: absolute;
35-
top: 10px;
36-
right: 0;
3734
z-index: 1000;
38-
width: 262px;
35+
width: 100%;
3936
padding-left: 32px;
37+
margin: 9px;
4038
@include background-image-2x($baseurl + "images/icons/search", 17px, 17px, 10px 50%);
4139
background-color: var(--main-bg) !important;
4240
border: solid 1px var(--search-border);
@@ -63,17 +61,12 @@ form#search {
6361
// Breakpoint ----------------
6462
@media (max-width: $default) {
6563
form#search{
66-
@include center-transformX;
67-
margin-top: 7px;
68-
top: unset;
69-
width: 92%;
7064
}
7165
}
7266

7367
// Mobile
7468
@media (max-width: $mobile-m) {
7569
form#search{
76-
width: 84%;
7770
#search-text {
7871
padding: 0.3rem 0.1rem;
7972
}

assets/sass/layout.scss

+18-7
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,28 @@ aside {
110110

111111
// Header
112112
header {
113-
position: relative;
114113
padding-bottom: 26px;
115114
margin-top: 14px;
116115

116+
display: flex;
117+
flex-direction: row;
118+
119+
div {
120+
display: flex;
121+
flex-direction: row;
122+
align-items: center;
123+
124+
&:first-child {
125+
flex-grow: 4;
126+
}
127+
}
128+
#logo {
129+
display: flex;
130+
}
131+
117132
#tagline {
118-
position: absolute;
119-
top: 11px;
120-
left: 120px;
121133
display: block;
122-
margin-top: 1px;
134+
margin-left: 8px;
123135
font-size: 24px;
124136
line-height: 24px;
125137
color: var(--light-font-color);
@@ -439,13 +451,11 @@ table.benchmarks {
439451
.responsive-table { overflow-x: auto; }
440452
.center img { height: 100%; }
441453
header{
442-
padding-bottom: 2.5rem;
443454
a, span {
444455
padding-left: 1rem;
445456
margin-bottom: 10px ;
446457
}
447458
}
448-
#home { .inner { > header { padding-bottom: 2rem; } } }
449459
#content { width: 100%; }
450460
.inner { width: 100%; }
451461
#content-wrapper { padding: 0.8rem; }
@@ -485,6 +495,7 @@ table.benchmarks {
485495
top: 0;
486496
padding-right: 1rem;
487497
}
498+
flex-direction: column;
488499
}
489500
#home { .inner { > header { padding-bottom: 2.5rem; } } }
490501
#masthead {

assets/sass/search.scss

+25-8
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,32 @@
11
@import "variables";
22
@import "mixins";
33

4+
#search-container {
5+
position: relative;
6+
width: 300px;
7+
padding-left: 60px;
8+
9+
* {
10+
box-sizing: border-box;
11+
}
12+
}
13+
414
#search-results {
515
position: absolute;
6-
top: 2px;
7-
right: -8px;
16+
left: 0;
817
z-index: 900;
918
display: none;
10-
width: 384px;
1119
background: #398a94 url($baseurl + "images/bg/search-header.jpg") 0 1px repeat-x;
1220
@include border-radius(3px);
1321
@include box-shadow(0 0 7px rgba(0, 0, 0, 0.25));
1422
border-bottom: solid 1px var(--base-border-color);
1523

24+
width: calc(100% - 1px);
25+
height: 100%;
26+
1627
header {
17-
height: 44px;
28+
width: 100%;
29+
height: 100%;
1830
padding: 0;
1931
margin: 0;
2032
text-indent: -9999px;
@@ -36,7 +48,7 @@
3648

3749
td.category {
3850
width: 67px;
39-
padding: 10px 12px 0 0;
51+
padding-top: 10px;
4052
font-size: 11px;
4153
color: var(--blue);
4254
text-align: right;
@@ -130,14 +142,19 @@ ol.full-search-results {
130142

131143
// Breakpoint ---
132144
@media (max-width: $default) {
145+
#search-container {
146+
padding-left: 0;
147+
}
133148
#search-results{
134-
@include center-transformX;
135-
top: unset;
136-
width: 98%;
149+
width: 100%;
137150
}
138151
}
139152
// Mobile
140153
@media (max-width: $mobile-m) {
154+
#search-container {
155+
width: inherit;
156+
margin-left: 15px;
157+
}
141158
#search-results{
142159
margin-top: 4px;
143160
}

assets/sass/variables.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ $base-font-size: 14px;
1212
$base-line-height: 22px;
1313

1414
$fixed-width-font-family: Courier, monospace;
15-
$fixed-width-line-height: 18px;
15+
$fixed-width-line-height: 18px;

layouts/partials/header.html

+26-22
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
<header>
2+
<div id="brand">
3+
<a id="logo" href="{{ relURL "" }}"><img src="{{ relURL "images/[email protected]" }}" width="110" height="46" alt="Git" class="no-filter" /></a>
4+
<span id="tagline"></span>
5+
<script type="text/javascript">
6+
const taglines = [
7+
"fast-version-control",
8+
"everything-is-local",
9+
"distributed-even-if-your-workflow-isnt",
10+
"local-branching-on-the-cheap",
11+
"distributed-is-the-new-centralized"
12+
];
13+
var tagline = taglines[Math.floor(Math.random() * taglines.length)];
14+
document.getElementById('tagline').innerHTML = '--' + tagline;
15+
</script>
16+
</div>
217

3-
<a href="{{ relURL "" }}"><img src="{{ relURL "images/[email protected]" }}" width="110" height="46" alt="Git" class="no-filter" /></a>
4-
<span id="tagline"></span>
5-
<script type="text/javascript">
6-
const taglines = [
7-
"fast-version-control",
8-
"everything-is-local",
9-
"distributed-even-if-your-workflow-isnt",
10-
"local-branching-on-the-cheap",
11-
"distributed-is-the-new-centralized"
12-
];
13-
var tagline = taglines[Math.floor(Math.random() * taglines.length)];
14-
document.getElementById('tagline').innerHTML = '--' + tagline;
15-
</script>
16-
17-
<img src="{{ relURL "images/dark-mode.svg" }}" id="dark-mode-button" />
18-
{{ if ne (.Scratch.Get "section") "search" }}
19-
<form id="search" action="{{ relURL "search/results" }}">
20-
<input id="search-text" name="search" placeholder="Type / to search entire site…" autocomplete="off" type="text" />
21-
</form>
22-
<div id="search-results"></div>
23-
{{ end }}
24-
18+
<div>
19+
{{ if ne (.Scratch.Get "section") "search" }}
20+
<div id="search-container">
21+
<form id="search" action="{{ relURL "search/results" }}">
22+
<input id="search-text" name="search" placeholder="Type / to search entire site…" autocomplete="off" type="text" />
23+
</form>
24+
<div id="search-results"></div>
25+
</div>
26+
{{ end }}
27+
<img src="{{ relURL "images/dark-mode.svg" }}" id="dark-mode-button" />
28+
</div>
2529
</header>

0 commit comments

Comments
 (0)