Here is a fiddle.
<p>foo <a class="infolink" href="#">bar</a> baz</p>
and
a.infolink::before { content: '?'; background: blue; color: white; width: 20ex; height: 20ex; }
The '?' appears but clearly does not have 20ex size. Why not? Tested in Firefox and Chrome.
While the display property is inline , height and width will not work. display :inline; By changing the display property from inline to block or inline-block , height and width should be worked properly.
Inline element properties: The height of an inline element is the height of the content. The width of an inline element is the width of the content. The height and width of an inline element cannot be set in CSS.
::before (:before) In CSS, ::before creates a pseudo-element that is the first child of the selected element. It is often used to add cosmetic content to an element with the content property. It is inline by default.
It is important to realize that pseudo-elements are considered descendants of their associated element. You may set a negative z-index for these pseudo-elements, but in order for them to actually appear below their parent element, you must create a new stacking context for the parent.
Note: The ::before
and ::after
pseudo-elements are actually laid display: inline;
by default.
Change the display value to inline-block
for the width & height to take effect while maintaining inline formatting context.
a.infolink::before { content: '?'; display: inline-block; background: blue; color: white; width: 20px; height: 20px; }
http://jsfiddle.net/C7rSa/3/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With