Invisible anchor with fixed width

  • Thread starter Christoph Burschka
  • Start date
C

Christoph Burschka

I need to generate an invisible anchor element (JS widget) to overlay
the list style icon in a nested list.

I'm currently doing this with the following markup:

<ul class="tree">
<li class="item">
<a class="menu-icon" href="#">&nbsp;&nbsp;</a>
<a class="menu-link" href="/menu/link">Menu Link</a>
<ul class="tree">
...
</ul>
</li>
</ul>

And the following CSS:

a.menu-icon {
position: relative;
left: -2em;
margin-right: -1em;
}

Needless to say, the &nbsp; is extremely ugly, and very likely to break
with different text sizes and different fonts (this mechanism is part of
a module that will be used with many different layouts)

Unfortunately, forcing the link width with a.menu-icon { width: 16px; }
didn't work, and if I use a "display:block", the menu link will be
broken to the next line.

Is there a way to set a fixed width on this invisible anchor?

Thanks,
 
C

Christoph Burschka

Christoph said:
Unfortunately, forcing the link width with a.menu-icon { width: 16px; }
didn't work, and if I use a "display:block", the menu link will be
broken to the next line.

Is there a way to set a fixed width on this invisible anchor?

Yay! I'd forgotten about good old float.

By setting display:block and float:left on the anchor element, I was
able to both set its width and keep it on the same line as the link.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top