Clean solution
You can use visibility: hidden , but with this solution, hidden content will still take up space. If that doesn't matter to you, here's how you do it:
span { visibility: hidden; } span:before { visibility: visible; }
Hackish Alternative
Another solution would be to set a font-size span to zero * really small value. The advantage of this method: hidden content does not take up space. Disadvantage: you cannot use relative units, such as em or%, for the font size :before .
span:before { content: "Lorem "; font-size: 16px; font-size: 1rem; letter-spacing: normal; color: #000; } span { font-size: 1px; letter-spacing: -1px; color: transparent; }
Jsfiddle example.
Update (May 4, 2015):. With CSS3, you can use the rem (Root EM) block to maintain the relative font sizes in the :before element. (browser support.)
* A previous version of this post suggests setting the font size to zero. However, in some browsers this does not work as desired, because CSS does not determine what behavior is expected when the font size is set to zero . For compatibility with multiple browsers, use a small font size as described above.
anroesti Feb 06 2018-11-11T00: 00Z
source share