1

I'm trying to create an effect: I have several links with pseudo elements. When these link's :before are hovered over, the text of the link is shown. Here is a mockup:

No hover:

      [ ] [ ] [ ] [ ]

Hover, designated by asterisk:

 [ ] [*]About [ ] [ ]

They must remain aligned right.

Uncceptable:

[ ] [ ] [ ] [ ]
[ ] [ ] [ ] [*]Contact Us

Acceptable:

          [ ] [ ] [ ] [ ]
[ ] [ ] [ ] [*]Contact Us

I have tried several methods using several techniques, each have their own problems:

Option 1:

*{margin:0; padding:0;}
ul{float:right; background:red;}
li{list-style-type:none; display:inline-block; width:20px; height:20px;}
a {display:block; position:relative; margin:10px; text-indent:-9999px;}
a:before{content:''; display:block; width:20px; height:20px; background:black; position:absolute; left:-30px; margin:0 5px;}
a:hover{text-indent:0;}
li:hover,ul:hover{width:auto;}

This allows the list to be expanded while hovering li, and expands without displaying link text:

ghost expanding

Option 2:

*{margin:0; padding:0;}
ul{background:salmon; float:right;}
li{background:lightblue; display:inline-block; list-style-type:none; }
a{background:gray; display:block; position:relative; padding-right:25px; text-indent:-9999px;}
a:before{content:'a'; position:absolute; top:0; left:-20px; height:20px; width:20px; background:black; text-align:center; text-indent:0;}
a:hover{text-indent:0;}

This method does not align un-expanded links right.

Option 3:

*{margin:0; padding:0;}
ul{background:salmon; text-align:right;}
li{background:lightblue;  display:inline; height:20px;}
a{background:gray; display:inline-block; width:20px; height:20px; overflow:hidden; text-align:center;}
a:before{content:'a'; display:inline-block; width:20px; height:20px;}
a:hover{width:auto;}

This method leads to inexplicable shifts in vertical spacing.

Community
  • 1
  • 1
bookcasey
  • 39,223
  • 13
  • 77
  • 94

1 Answers1

1

Option 3 looks good to me, except for the problem you mentioned.

This method leads to inexplicable shifts in vertical spacing.

To fix this, you need to add vertical-align: top to wherever you have display: inline-block.

Take a look: http://dabblet.com/gist/1872722

Here's an older answer containing an explanation for the bizarre alignment: Why aren't these elements with display:inline-block properly aligned?.

Also worth reading: http://blog.mozilla.com/webdev/2009/02/20/cross-browser-inline-block/

Community
  • 1
  • 1
thirtydot
  • 224,678
  • 48
  • 389
  • 349