Implementing «Rich CSS Tooltip» in Hugo
Have migrated my blog from Pelican to Hugo, hopefully that I will write more frequently. Hopefully!
During the migration process I couldn’t resist to implement rich css tooltips with html content
ExampleText can contain tags with styles. And even images:
. And again, in the hope, that I will use it later. But I‘m already had fun with this process, that‘s why I will describe how I did it.
html-hint
I have import css library html-hint to my scss build. Something like this (line 1):
|
|
Then, add some css styling to the hint (3-50).
There is no prebuild minificated files, that’s why I have to enable nodejs to build my site. So, before the build, I need to run:
> npm install --save html-hint
Hugo shortcode
Create new file layouts/shortcodes/tooltip.html
, that will contain markup for our hints:
<span class="hint--html hint--bottom">
<span class="hint__element">{{- .Get "element" | safeHTML }}</span>
<span class="hint__content">
{{ with .Get "title" }}<span class="hint__title">{{- . -}}</span>{{ end }}
{{- .Inner | safeHTML -}}
</span>
</span>{{- "" -}}
Insert hint to post content
To create hint in our post content we need to add this shortcode:
{{< tooltip element="element with a hint" title="Title in hint" >}}
Text <b>in a hint</b> using <i style="color:red">HTML tags</i>.
{{< /tooltip >}}
Here is result:
element with a hint Title in hint Text in a hint using HTML tags.Hover this element and the hint with HTML content will be displayed.