Skip to content

Commit e579ab4

Browse files
authored
Improving tooltip for mobile (#27)
1 parent 402f13e commit e579ab4

File tree

2 files changed

+130
-31
lines changed

2 files changed

+130
-31
lines changed

_layouts/bin.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ <h2 id="{{function_name}}" class="function-name">
8181
<dl class="row"><dt class="property">Privileges required</dt><dd>{{item.Privileges}}</dd></dl>
8282
<dl class="row"><dt class="property">Operating systems</dt><dd>{{item.OperatingSystem}}</dd></dl>
8383
<dl class="row"><dt class="property">ATT&CK&reg; technique</dt><dd><span data-attack-tid="{{item.MitreID}}">{{item.MitreID}}</span></dd></dl>
84-
{%- if item.Tags %}<dl class="tags row"><dt class="property">Tags</dt><dd>{% for tag_items in item.Tags %}{% for tag_item in tag_items %}{%assign key=tag_item[0]%}{%assign value=tag_item[1]%}{%assign tag=key | append:': ' | append:value %}{% assign default_text = 'This function was tagged with "' | append: tag | append:'".' %}<div class="tag">{{tag}}<div class="tag-tooltip">{{site.data.tags[key][value] | default:default_text}}</div></div>{%endfor%}{%endfor%}</dd></dl>{%endif%}
84+
{%- if item.Tags %}<dl class="tags row"><dt class="property">Tags</dt><dd>{% for tag_items in item.Tags %}{% for tag_item in tag_items %}{%assign key=tag_item[0]%}{%assign value=tag_item[1]%}{%assign tag=key | append:': ' | append:value %}{% assign default_text = 'This function was tagged with "' | append: tag | append:'".' %}<div class="tag tooltip-top tooltip-mobile" data-tooltip="{{site.data.tags[key][value] | default:default_text}}">{{tag}}</div>{%endfor%}{%endfor%}</dd></dl>{%endif%}
8585
</div>
8686
</li>
8787
{%- endfor %}

assets/style.scss

Lines changed: 129 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ $layout-break: "(min-width: #{$column-width + $grace-space})";
3737
display:none;
3838
}
3939

40-
.tag .tag-tooltip {
41-
width: max-content;
42-
max-width: 60vw !important;
43-
transform: translate(-60%, calc(-100% - 2em));
44-
}
45-
4640
ol:has(> :nth-child(2)) {
4741
padding-left: 1em !important;
4842
}
@@ -294,34 +288,13 @@ ul {
294288
.tag {
295289
background-color: $accent;
296290
color: white;
297-
padding: 5px;
291+
cursor: pointer;
298292
display: inline-block;
293+
font-size: 85%;
294+
padding: 5px;
299295
position: relative;
300-
cursor: pointer;
301-
}
302-
303-
.tag .tag-tooltip {
304-
cursor: text;
305-
display: none;
306-
position: absolute;
307-
top: 1.9em;
308-
left: 0;
309-
z-index: 99999;
310-
border: 2px solid $accent;
311-
border-radius: 5px;
312-
background-color: white;
313-
color: black;
314-
padding: 3px;
315-
width: max-content;
316-
max-width: 500px;
317296
}
318297

319-
.tag:hover .tag-tooltip,
320-
.tag-tooltip:hover {
321-
display: inline-table;
322-
}
323-
324-
325298
.properties {
326299
display: flex;
327300
flex-direction: column;
@@ -376,3 +349,129 @@ section + section {
376349
.path-highlight {
377350
color: #888;
378351
}
352+
353+
354+
$xy-border: (
355+
top: t,
356+
bottom: b,
357+
left: l,
358+
right: r
359+
);
360+
361+
362+
[data-tooltip] {
363+
$triangle: .3rem;
364+
$background-color: rgba(51,51,51,.9);
365+
366+
cursor: pointer;
367+
display: inline-block;
368+
line-height: 1;
369+
position: relative;
370+
371+
&::after {
372+
background-color: $background-color;
373+
border-radius: $triangle;
374+
color: #fff;
375+
content: attr(data-tooltip);
376+
font-size: 1rem;
377+
font-size: 100%;
378+
font-weight: normal;
379+
line-height: 1.15rem;
380+
opacity: 0;
381+
padding: .25rem .5rem;
382+
position: absolute;
383+
text-align: center;
384+
text-transform: none;
385+
transition: opacity .2s;
386+
visibility: hidden;
387+
z-index: 1;
388+
max-width: 300px;
389+
width: 300px;
390+
}
391+
392+
@each $direction, $d in $xy-border {
393+
&.tooltip-#{$direction} {
394+
// arrows
395+
&::before {
396+
border-style: solid;
397+
border-width: $triangle;
398+
content: "";
399+
opacity: 0;
400+
position: absolute;
401+
transition: opacity .2s;
402+
visibility: hidden;
403+
@if $direction == top {
404+
border-color: $background-color transparent transparent transparent;
405+
top: -20%;
406+
left: 50%;
407+
margin-left: -$triangle;
408+
} @else
409+
if $direction == bottom {
410+
border-color: transparent transparent $background-color transparent;
411+
bottom: 0;
412+
left: 50%;
413+
margin-left: -$triangle;
414+
} @else
415+
if $direction == left {
416+
border-color: transparent transparent transparent $background-color;
417+
top: $triangle;
418+
right: calc(110% - #{$triangle});
419+
margin-top: -$triangle;
420+
} @else
421+
if $direction == right {
422+
border-color: transparent $background-color transparent transparent;
423+
top: 50%;
424+
top: $triangle;
425+
left: calc(110% - #{$triangle});
426+
margin-top: -$triangle;
427+
}
428+
}
429+
430+
&::after {
431+
@if $direction == top {
432+
bottom: 120%;
433+
left: 50%;
434+
transform: translate(-50%);
435+
} @else
436+
if $direction == bottom {
437+
top: 100%;
438+
left: 50%;
439+
transform: translate(-50%);
440+
} @else
441+
if $direction == left {
442+
top: -$triangle;
443+
right: calc(110% + #{$triangle});
444+
} @else
445+
if $direction == right {
446+
top: -$triangle;
447+
left: calc(110% + #{$triangle});
448+
}
449+
}
450+
}
451+
}
452+
453+
&.tooltip-mobile {
454+
@media (max-width: 767px) {
455+
&::before {
456+
display: none;
457+
}
458+
459+
&:after {
460+
font-size: 1rem;
461+
max-width: 20rem;
462+
position: fixed;
463+
bottom: 1%;
464+
left: 50%;
465+
text-align: left;
466+
transform: translate(-50%);
467+
white-space: normal;
468+
}
469+
}
470+
}
471+
472+
&:hover::after,
473+
&[class*=tooltip-]:hover::before {
474+
visibility: visible;
475+
opacity: 1;
476+
}
477+
}

0 commit comments

Comments
 (0)