7
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 is loaded on a smaller device, I want the text to "disappear" and only the icon 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, if I try to hide the contents of the tag <a>
the icon in ::before
will not appear. For example, I tried to use text-indent: -999px;
and it didn’t 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 opens on a smaller device I give a display:none
at that tag <span>
and so 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>
All right. My question is: Is that the best tag to do this? I’m worrying about little?
Some websites (mainly those created using bootstrap) use the tag for icons, but according to this question use is only to save characters.
Any suggestions for doing this in a better way?
Renang, my idea doesn’t work as well as I thought. The icon is also caught. I think the
span
is indeed the best option. Let’s see what others say.– Sergio
And a high line-height with overflow Hidden, someone tried?
– bfavaretto