0

I have a nested list that lists child nodes when the parent node is expanded. The parent node is expanded by clicking an image to the left of the text.

Unfortunately, it expands right off the page. I would like a scrollbar to appear when the content is off the page.

When I set "overflow: auto", a scrollbar never pops up, it just expands off the page and removes the expansion image on left of the list items.

Here's sample .html:

<body>
  <div id="theDiv" style="clear: left;">
    <ul id="theList">
      <li id="1" class="parent">
       <img class="expanded" align="absmiddle" src="./tree_expanded.gif"/>
        Parent1
         <ul style="display: block;">
           <li id="10">
           .....
         </ul>
      </li>
      ....
    </ul>
  </div>
</body>

Here's sample .js:

function expand() {
  if(this.className == "expand") {
    jQuery(this.parentNode).children("ul").show();
    this.className = "expanded";
    this.src = "/_images/tree_expanded.gif";
  }
 else {
  jQuery("ul", this.parentNode).hide();
  this.className = "expand";
  this.src = "/_images/tree_unexpanded.gif";
 }
} 

Here's sample .css:

#theList {
    margin-top: 0;
}

#theList, #theList ul {
    list-style: none;
    margin: 5px 20px;
    padding: 0;
}

#theList .expand, #theList .expanded {
    margin-left: -20px;
    cursor: pointer;
}

#theList img {
    margin-right: 5px;
}

#theList ul {
    display: none;
}

#theList li {
    white-space: nowrap;
    margin-bottom: 4px;
}
4

2 回答 2

0

First of all, set a definite width of the container div, so it knows when to start scrolling. Next, set it to overflow-x:scroll; or something to that effect. It should work :)

于 2009-08-06T23:22:37.537 回答
0

好吧,我走在正确的轨道上,但不够坚持。CSS 真的让我抓狂。我需要同时设置 div 和列表高度以使其滚动。我正在尝试其中一个,而不是两个。

我真是个n00b。

于 2009-08-07T20:41:21.827 回答