5

I have tried this but it didn't work:

.stackoverflow::before {
    font-family: 'FontAwesome';
    content: "\f16c ";
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css">
<a class="stack-link stackoverflow" href="http://stackoverflow.com">StackOverflow</a>

Can we add whitespace(s) with ::before selector and content property like that?

dan9vu
  • 2,403
  • 3
  • 12
  • 30

2 Answers2

2

Yes, You can add whitespace like this content: "\f16c \00a0";

Jsfiddle

\00a0 is hex code for a non-breaking space,used in content property. More Info

Hope it helps :)

Thinker
  • 4,028
  • 1
  • 14
  • 44
  • Can you explain the significance of this code? – Alexander O'Mara Jun 05 '16 at 05:01
  • @AlexanderO'Mara Edited the answer man :) – Thinker Jun 05 '16 at 05:05
  • 1
    Better. You wouldn't happen to know why 2 regular spaces and `"A "` with just 1 space works, but `"\f16c ";` doesn't would you? I'm finding this rather bizarre. – Alexander O'Mara Jun 05 '16 at 05:07
  • Thank you! It works like a charm :) – dan9vu Jun 05 '16 at 05:07
  • As i mentioned in the answer, \00a0 is the hex code for non-breaking space used in the content property. We cant directy use   in content property. So for that reason we are using the hex code. More Info in http://www.evotech.net/blog/2007/04/named-html-entities-in-numeric-order/ – Thinker Jun 05 '16 at 05:08
  • Ah, I've located the root cause for this seeming strange behavior. http://stackoverflow.com/questions/190396/adding-html-entities-using-css-content – Alexander O'Mara Jun 05 '16 at 05:14
0

Yep, use \a0 it's &nbsp; or non-breaking space.

.stackoverflow::before {
    font-family: 'FontAwesome';
    content: "\f16c\a0\a0\a0\a0\a0\a0";
}
<html>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css">
  <a class="stack-link stackoverflow" href="http://stackoverflow.com">StackOverflow</a>
</html>
zer00ne
  • 36,692
  • 5
  • 39
  • 58