Skip to content

Commit fb7df28

Browse files
committed
Prevent SVG shrinking (go-gitea#25652)
This will prevent the most common cases of SVG shrinking because lack of space. I evaluated multiple options and this seems to be the one with the least impact in size and processing cost, so I went with it. Unfortunately, CSS can not dynamically convert `16` obtained from `attr()` to `16px`, or else a generic solution for all sizes would have been possible. But a solution is [in sight](https://developer.mozilla.org/en-US/docs/Web/CSS/attr#type-or-unit) with `attr(width px)` but no browser supports it currently.
1 parent 69bdcf4 commit fb7df28

File tree

3 files changed

+42
-10
lines changed

3 files changed

+42
-10
lines changed

web_src/css/base.css

-10
Original file line numberDiff line numberDiff line change
@@ -358,16 +358,6 @@ progress::-moz-progress-bar {
358358
opacity: 1 !important;
359359
}
360360

361-
.svg {
362-
display: inline-block;
363-
vertical-align: text-top;
364-
fill: currentcolor;
365-
}
366-
367-
.middle .svg {
368-
vertical-align: middle;
369-
}
370-
371361
.unselectable,
372362
.button,
373363
.lines-num,

web_src/css/index.css

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
@import "./modules/breadcrumb.css";
88
@import "./modules/card.css";
99
@import "./modules/comment.css";
10+
@import "./modules/svg.css";
1011

1112
@import "./shared/issuelist.css";
1213
@import "./shared/milestone.css";

web_src/css/modules/svg.css

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
.svg {
2+
display: inline-block;
3+
vertical-align: text-top;
4+
fill: currentcolor;
5+
}
6+
7+
.middle .svg {
8+
vertical-align: middle;
9+
}
10+
11+
/* prevent SVGs from shrinking, like in space-starved flexboxes. the sizes
12+
here are cherry-picked for our use cases, feel free to add more. after
13+
https://developer.mozilla.org/en-US/docs/Web/CSS/attr#type-or-unit is
14+
supported in browsers, use `attr(width px)` instead for a generic
15+
solution. */
16+
17+
.svg[height="12"] { min-height: 12px; }
18+
.svg[height="13"] { min-height: 13px; }
19+
.svg[height="14"] { min-height: 14px; }
20+
.svg[height="15"] { min-height: 15px; }
21+
.svg[height="16"] { min-height: 16px; }
22+
.svg[height="18"] { min-height: 18px; }
23+
.svg[height="20"] { min-height: 20px; }
24+
.svg[height="22"] { min-height: 22px; }
25+
.svg[height="24"] { min-height: 24px; }
26+
.svg[height="36"] { min-height: 36px; }
27+
.svg[height="48"] { min-height: 48px; }
28+
.svg[height="56"] { min-height: 56px; }
29+
30+
.svg[width="12"] { min-width: 12px; }
31+
.svg[width="13"] { min-width: 13px; }
32+
.svg[width="14"] { min-width: 14px; }
33+
.svg[width="15"] { min-width: 15px; }
34+
.svg[width="16"] { min-width: 16px; }
35+
.svg[width="18"] { min-width: 18px; }
36+
.svg[width="20"] { min-width: 20px; }
37+
.svg[width="22"] { min-width: 22px; }
38+
.svg[width="24"] { min-width: 24px; }
39+
.svg[width="36"] { min-width: 36px; }
40+
.svg[width="48"] { min-width: 48px; }
41+
.svg[width="56"] { min-width: 56px; }

0 commit comments

Comments
 (0)