We are using Markdown (Kramdown) to generate a static website. For infoboxes, we can annotade paragraphs and get the following results:
{:.note .icon-check title="This is a title"}
Lorem, ipsum dolor sit amet consectetur adipisicing elit.
And this is the converted HTML:
<p class="note icon-check" title="This is a title">
Lorem, ipsum dolor sit amet consectetur adipisicing elit.
</p>
The style is (SCSS):
p.note {
&::before {
float: right;
}
position: relative;
&[title]::after {
content: attr(title);
position: relative;
top: 0;
left: 0;
}
}
.icon::before {
content: "@";
}
As we are using Icomoon icon fonts, where the content is set in :before, the title must be in :after.
- we won't change the Iconfont, so the icon must stay in
:before - no additional distracting markup in the markdown, so no HTML wrapper
- no Javascript
It is possible to set an absolute positioning to the title, but this would be too narrow to the paragraph-text itself, as no margin can be set.
Now, how does one style a box with :after as a title on top, that also looks good when no title is set?
main {
width: 50%;
display: block;
place-items: center;
margin: auto;
}
p.note {
border: 3px solid red;
border-radius: 3px;
padding: 1em;
position: relative;
}
p.note::before {
margin: auto 0 0.5em 0.5em;
float: right;
}
p.note[title]::after {
content: attr(title);
position: relative;
font-weight: bold;
top: 0;
left: 1em;
}
.icon::before {
font-size: 2em;
content: "@";
}
<html>
<body>
<main>
<p class="note icon" title="This is a title">
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Dolorem quidem non placeat quibusdam velit, dicta adipisci saepe magnam fuga debitis qui, minima, eius error laboriosam distinctio eos natus et!
</p>
</main>
</body>
</html>

