Recently, I encountered an issue with the navigation menu on my website which is automatically generated by the CMS. The HTML structure of the menu is pretty straightforward:
<ul>
<li><a href="...">Journal</a></li>
<li><a href="...">Art</a></li>
<li><a href="...">Work</a></li>
</ul>
I wanted to customize this menu by replacing the text with handwritten images to match the theme of the website. To achieve this, I used the CSS content
property in the following manner:
#headerNav .nav li a[href="/_site/en/journal/"]
{ content: url(/path/to/image.png); }
Initially, everything seemed to work perfectly as intended with Chrome and Safari supporting the content
property. However, Firefox did not support it for selectors other than :before
and :after
. When I tried using :before
, although the image was displayed, it did not replace the HTML node.
Desperate for a solution, I tried various methods which unfortunately did not yield the desired results:
- Hiding the
<a>
element usingdisplay: none
removed the image added through:before
. - Positioning the
<a>
element absolutely and moving it elsewhere proved ineffective. - Adjusting the width of the
<a>
element to 0px disrupted the layout due to the images not being part of the document flow.
Despite exploring several options, there are certain restrictions that limit potential solutions:
While manual insertion of images is a possible workaround, I prefer utilizing the HTML elements provided by the CMS.
Employing
background-image
would require specifying dimensions for each item individually, which I wish to avoid.Converting the handwriting into a font is not a feasible choice.
Implementing JavaScript for real-time replacement of items is off the table, as I aim to achieve this solely through HTML and CSS.