Canapin
(Coin-coin le Canapin)
December 6, 2022, 10:47pm
1
<kbd>:blue_square: any text</kbd>
Will render the same as:
<kbd>:blue_square:any text</kbd>
any text
There is no visible space between the emoji and the text, though the space is present in the HTML code.
Is that a limitation of the <kbd>
tag? Is there an elegant way to fix it or should we rely on hacky stuff like
or ㅤ
etc?
<kbd>:blue_square: any text</kbd>
any text
<kbd>:blue_square:ㅤany text</kbd>
ㅤany text
sam
(Sam Saffron)
December 7, 2022, 2:44am
2
It’s probably the display: inline-flex;
that is applied to KBD tags, forcing stuff closer together.
There may be a CSS workaround here, not sure.
1 Like
Canapin
(Coin-coin le Canapin)
December 7, 2022, 12:53pm
3
One solution is to add some values for the white-space property, like pre-wrap , but it will cause issues if we have one more multiple line breaks inside <kbd>
.
Would become:
An alternative would be to automatically add left and/or right margins on the emoji if it’s not the first or last element.
In the current state:
With this added CSS:
kbd {
// current rules
img {
margin: 0 .5em;
&:first-child {
margin-left: 0;
}
&:last-child {
margin-right: 0;
}
}
}
Would these forced margins be acceptable? It’s prettier and increases readability, but it will be impossible for the user to not have a margin between the emoji and some text (as for me, I’d be happy since I see the forced margin as a benefit).
2 Likes
sam
(Sam Saffron)
December 8, 2022, 5:40am
4
Not sure about this, let’s see what @Designers thing. Ideally we can just teach inline-flex
to be more … flexible
3 Likes
I think we can use the gap
property for this? the problem is that changing kbd
to use flexbox removed any natural space between elements within:
kbd {
gap: 0.5em;
}
produces:
This would add space between any HTML elements within the KBD tag, and wouldn’t require any exceptions for first/last-child.
3 Likes
I’ve just merged this in:
discourse:main
← discourse:kbd-gap
opened 06:34PM - 12 Dec 22 UTC
This ensures that there's always horizontal space between elements (like text an… d emoji) within a KBD tag. Flexbox ignores the whitespace that would be present otherwise.
Before:

After:

Discussion here: https://meta.discourse.org/t/cant-insert-space-next-to-an-emoji-inside-kbd-tags/248059
4 Likes
Canapin
(Coin-coin le Canapin)
December 12, 2022, 7:20pm
9
Awesome, thanks!
Didn’t know the gap property by the way, always good to learn something.
3 Likes