代码之家  ›  专栏  ›  技术社区  ›  user1134181

自动缩放嵌套表的CSS样式

  •  1
  • user1134181  · 技术社区  · 12 年前

    以下问题。我有一些 div 其呈现父容器。在里面 第二部分 我有一个嵌套 table ,可以滚动。父级 第二部分 是分层的。所以,当我调整我的 第二部分 容器我想调整嵌套的大小 桌子 也下面的代码不支持这一点。我该怎么做?也许我需要所有文档的不同结构?

    重要提示-我需要不使用 JavaScript .

    HTML代码 :

    <div id="main_container">
    <table id="wrapper_table">
    <tbody>
      <tr>
        <td class="cell">
          <div class="wrapper">
            <table>
              <tr>
                <td>test content</td>
                <td>test content</td>
              </tr>
              ...  
            </table>
            </div>
          </td>
        </tr>
        </tbody>
    </table>
    </div>    
    

    CSS代码 :

    #main_container {  
      position:fixed;
      top:0px; 
      height: 200px;
      border:1px solid black;
      top:30px;    
    }
    
    #wrapper_table {
        width:100%;    
    }
    
    .wrapper {
      overflow:scroll;
      height:100%;
    }
    
    .cell {
        height: 200px;   
    }
    

    JavaScript代码:

    $(document).ready(function() {
       $('#main_container').resizable({handles: 'n,e'});
    });
    

    这里的小提琴- http://jsfiddle.net/y4Bk2/

    2 回复  |  直到 7 年前
        1
  •  0
  •   Atal Shrivastava    12 年前

    可以使用Css resize属性。但互联网浏览器和opera不支持这一点。您需要添加

    #main_container {  
     position:fixed;
     top:0px; 
     height: 200px;
     border:1px solid black;
     top:30px;
     overflow:auto;
     resize:both;    
      }
    

    并添加此

    #wrapper_table::-webkit-scrollbar{
    display:none;}
    

    查看演示 here

        2
  •  0
  •   CRABOLO    12 年前

    有一个非常简单的选项,因为您已经在使用jQueryUI可调整大小的小部件。

    使用 alsoResize

    一个或多个要与可调整大小的同步调整大小的元素 要素

    工作示例 http://jsfiddle.net/y4Bk2/2/

    $(document).ready(function() {
       $('#main_container').resizable({handles: 'n,e',  alsoResize: '.wrapper table'});
    });