Luuk Krijnen
Luuk Krijnen

Reputation: 1192

css :before content spacing

Using CSS to create a horizontal navigation I want to use a divider between the elements.

using:

li:before
{
  content: " | ";
}

I get a divider. But i wanna use a margin between the text and the divider

item(margin-right) |(?)item(margin-right)

how can I set a margin to the above question mark? With a margin-left (or padding-left) the margin will exist in front of the divider, not between the divider and the content.

Upvotes: 6

Views: 17957

Answers (2)

kremalicious
kremalicious

Reputation: 1371

As a quick hack, you can add a non-breaking space by using the escaped unicode for it:

li:before {
  content: "\00a0 | \00a0";
}​

See this fiddle.

But the better solution is to set a margin-left AND margin-right (or padding) for the pseudo element:

li:before {
  content: "|";
  margin-left: 20px;
  margin-right: 20px
}

See this fiddle.

Upvotes: 28

Manish Sharma
Manish Sharma

Reputation: 1720

try this one

li:before {
          content: "|";
          padding:0 5px;
        }

Upvotes: 0

Related Questions