Issue
I want to add a blank space after some content, however the content: " ";
doesn't seem to work.
This is my code:
h2:after {
content: " ";
}
... which doesn't work, however this does:
h2:after {
content: "-";
}
What am I doing wrong?
Solution
Explanation
It's worth noting that your code does insert a space
h2::after {
content: " ";
}
However, it's immediately removed.
From Anonymous inline boxes,
White space content that would subsequently be collapsed away according to the 'white-space' property does not generate any anonymous inline boxes.
And from The 'white-space' processing model,
If a space (U+0020) at the end of a line has 'white-space' set to 'normal', 'nowrap', or 'pre-line', it is also removed.
Solution
So if you don't want the space to be removed, set white-space
to pre
or pre-wrap
.
h2 {
text-decoration: underline;
}
h2.space::after {
content: " ";
white-space: pre;
}
<h2>I don't have space:</h2>
<h2 class="space">I have space:</h2>
Do not use non-breaking spaces (U+00a0). They are supposed to prevent line breaks between words. They are not supposed to be used as non-collapsible space, that wouldn't be semantic.
Answered By - Oriol
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.