I have a navigation menu with some icons using @font-face
.
Each item in this menu has:
- the icon (with
::before
); - text, explaining the function of that link.
. It turns out that when the page loads on a smaller device, I want the text to "disappear" and only the icon will be shown. I have the following structure:
<nav>
<ul>
<li><a class='ico-foo' href='#'>Visitar Foo</a></li>
<li><a class='ico-bar' href='#'>Visitar Bar</a></li>
<li><a class='ico-foobar' href='#'>Visitar FooBar</a></li>
</ul>
</nav>
Normal, like most structures. It turns out that if I try to hide the contents of the <a>
tag the icon in ::before
will not appear. For example, I tried to use text-indent: -999px;
and it did not work because the icon accompanies this rule and "some".
Well, the solution I found to hide the text was to put it inside a <span>
, so when the page is opened on a smaller device I give display:none
to this <span>
tag and so it is shown only the icons as I would like. The structure then:
<nav>
<ul>
<li><a class='ico-foo' href='#'><span>Visitar Foo</span></a></li>
<li><a class='ico-bar' href='#'><span>Visitar Bar</span></a></li>
<li><a class='ico-foobar' href='#'><span>Visitar FooBar</span></a></li>
</ul>
</nav>
Beauty. My question is: Is this the best tag to do this? Am I worrying about little?
Some sites (especially those created using bootstrap) use the tag for icons, but according to this question the use is only for saving characters.
Any suggestions to do this in a better way?