6

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?

4
  • Could it be added as a margin right? Commented Jun 5, 2016 at 5:00
  • That's weird... If I add 1 more space, or replace the icon itself with another character, it works... Commented Jun 5, 2016 at 5:00
  • ^ This seemingly strange behavior is addressed over there. The first space after an escape sequence is the delimiter to define it has ended. Commented Jun 5, 2016 at 5:14
  • @AlexanderO'Mara Thank you for the reference. That's what I really want to learn about :) Commented Jun 5, 2016 at 5:18

2 Answers 2

3

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 :)

Sign up to request clarification or add additional context in comments.

6 Comments

Can you explain the significance of this code?
@AlexanderO'Mara Edited the answer man :)
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.
Thank you! It works like a charm :)
As i mentioned in the answer, \00a0 is the hex code for non-breaking space used in the content property. We cant directy use &nbsp; in content property. So for that reason we are using the hex code. More Info in evotech.net/blog/2007/04/named-html-entities-in-numeric-order
|
1

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>

1 Comment

I think the intention is to add spacing after the icon.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.