So I have a navigation menu that is generated by my CMS:
The menu's HTML is straightforward (edited for clarity):
<ul>
<li><a href="...">Journal</a></li>
<li><a href="...">Art</a></li>
<li><a href="...">Work</a></li>
</ul>
I want the items to show up as hand-written text, in keeping with the general theme of the site, using separate PNG files for each menu item.
To do that, I used the CSS content
property like so:
#headerNav .nav li a[href="/_site/en/journal/"]
{ content: url(/path/to/image.png); }
And it worked great! The HTML text of each item was replaced by the correct image:
However, alas, then I learned not every browser supports the content
property on selectors other than :before
and :after
! Chrome and Safari do it, but Firefox doesn. However when I use :before
, the HTML node isn't replaced, but the image is added:
How do I work around this?
What didn't work:
- Making the
<a>
elementdisplay: none
removed the:before
part as well. - Making the
<a>
elementposition: absolute
and moving it elsewhere won't work either. - Making the
<a>
elementwidth: 0px
screws up the layout because the images added throughcontent
aren't in the document flow.
What I don't want to do:
Of course I can output the images by hand but I want to work with the HTML the CMS is giving me, which is
<li>
s with text in them.Any solution involving
background-image
would require me to specify each item's width and height in the style sheet, which I would like to avoid for the purposes of this question.Turning the handwriting into a font is not an option.
Using JavaScript to replace the items on the fly is not an option. This needs to work using pure HTML and CSS.
content
in the first place. (It's a fair compromise, though, if nothing else comes up, thanks for the reminder.) – Pekka 웃 Jan 17 at 15:34:before
or:after
. – Blazemonger Jan 17 at 15:35