开发者

Allow text to wrap in css menu

I have a template that uses an unordered list to create the menu. See here

When I translate the website using Google translate the menu breaks if the translations are too long, causing the floated list items to drop down. Translating it into French seem to cause the problem.

See here

Is there a way I can force t开发者_开发问答he text to wrap if it is too long for the menu?

I don't mind if I have to change the unordered list to something else, but I would prefer not to use a table.


use word-wrap property of css

word-wrap: break-word;


The short version: we're going to use display: table-cell.

The long version is.. long:

  • On .access, remove the padding rule.
  • On .sf-menu, remove float: left and add display: table.
  • On .sf-menu li, remove float: left and add display: table-cell and vertical-align: middle.
  • On #header and #footer, add position: relative.
  • On .access, remove height: 32px and margin-top: -32px and add position: absolute and width: 100%.
  • On #header .access, add bottom: 0.
  • Move the border-left from sf-menu a to sf-menu li.
  • Change the selector .sf-menu a.first to .sf-menu .first.
  • This part isn't great, but to get back that 20px padding on the left (and right), add an extra li at the start: <li class="noHover" style="width: 20px; border-left: 0">&nbsp;</li>; and at the end: <li class="noHover" style="width: 20px; border-left: 0">&nbsp;</li>. You might not need the &nbsp;s. You'll need to do the same thing with #footer.
  • To stop the :hover on the "padding" lis, add something like this:

    .sf-menu li.noHover:hover {
        background: none !important
    }
    
  • On #footer, add padding-top: 48px.

That's everything (unless I screwed up somewhere), except for IE6/7 support. If you want that, you're going to have to put a new version up with my fixes applied (can be in a temporary new folder if you like). It's too much work to attempt to fix IE6/7 when I have to apply all those changes first to test it properly.


@Pranay pointed to the right direction but you need to set the width to the lis not the ul! so for example:

ul.sf-menu li {
   width: 80px; /* make this the maximum width possible! */
   word-wrap: break-word;
}

And insert a clearing div right after the menu ul:

<div class="clear"></div>

Where the clear class is defined as:

.clear {
   clear: both;
   width: 0;
   height: 0;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜