1

How come the :before doesn't show anything when the content is empty, even though I set the height and width but when I enter some text in the content it shows that text?

CSS:

.a { background-color: cyan; height: 300px; width: 200px; margin-left: 50px; } .a:before { /* This is the one that I change */ content: "test"; margin-left: -10px; background-color: red; height: 10px; width: 10px; } 

HTML:

<div class="a"></div> 
0

3 Answers 3

5

Because the :before pseudo element is displayed inline by default. Change that, and you'll see your square:

.a:before { display:block; } 

http://jsfiddle.net/oGeez/Va67f/

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

Comments

0

You have to set the display property to block to display element

jsFiddle here

Comments

0

https://developer.mozilla.org/en-US/docs/Web/CSS/content

Have a look at the values and results for the content property.

"none: The pseudo-element is not generated"

Else the psudo elements display is inline. In your case I would use. Content: " " and display block.

Sorry. Formatting on my phone.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.