SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am editing the following master page which my current SharePoint site is using (I am using SharePoint 2007 + Windows Server 2008),

Currently, I am using the hard-coded value "120" to set the width of the left navigation bar, here is the related code in the master file. How do I set the width of left navigation bar to be automatically changed according to the max length of items on left navigration bar?

<SharePoint:AspMenu ID="CurrentNav" width="120" runat="server" datasourceID="SiteMapDS" orientation="Vertical" StaticDisplayLevels="2" MaximumDynamicDisplayLevels="0" StaticSubMenuIndent="1" ItemWrap="true" AccessKey="3" CssClass="leftNav" SkipLinkText="<%$Resources:cms,masterpages_skiplinktext%>">
share|improve this question
Thanks for making the title more readable, Alex! – George2 Nov 8 '09 at 9:12

You might want to do this with jQuery on the client side. The trick will be to determine the number of pixels wide required per character given your font family and size choice. Depending on how you are setting your font sizes, you may be able to take advantage of ems, but that would assume that characters are on average as wide as they are tall, which may not be the case with the font family you have chosen.


share|improve this answer
Marc, thanks! jQuery is new to me, any related reference samples? – George2 Nov 8 '09 at 18:16
I don't think I have a jQuery example, but here's a sort of related example in which I dynamically set the width of multi-select boxes on a form with JavaScript:… The logic would be similar, but the jQuery would be simpler. M. – Marc D Anderson Nov 9 '09 at 19:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.