简体   繁体   English

在每个td / box中,如何使它固定在每个box中的标题与下方可滚动的div之间?

[英]Within each td/box, how to make it so the header in each box is fixed with scrollable div beneath?

I have 9 boxes, I want each box to have a "heading", and scrollable content beneath the "Box n" heading. 我有9个框,我希望每个框都有一个“标题”,并在“ Box n”标题下面有可滚动的内容。

Am looking for 1) Ensure the "header" is vertically aligned to the top of each box. 正在寻找1)确保“标题”与每个框的顶部垂直对齐。 2) The scrollable content takes up the max height of each box. 2)可滚动内容占据每个框的最大高度。

How do I do this? 我该怎么做呢? My HTML is the following: 我的HTML如下:

 html, body { width: 100%; height: 100%; } table { border: 1; width: 100%; height: 100%; } td { text-align: center; background: red; } div { overflow: auto; height: 100%; background: yellow; } 
 <table> <tr> <td> <div> Box1<br> Some TExt<br> Some TExt<br> Some TExt<br> Some TExt<br>Some TExt<br> Some TExt<br> Some TExt<br> Some TExt<br> Some TExt<br> Some TExt<br> Some TExt<br> Some TExt<br> </div> </td> <td> <div>Box2</div> <div> Some TExt<br> Some TExt<br> Some TExt<br> Some TExt<br>Some TExt<br> Some TExt<br> Some TExt<br> Some TExt<br> Some TExt<br> Some TExt<br> Some TExt<br> Some TExt<br> </div> </td> <td> <div> Box3<br> Some TExt<br> Some TExt<br> Some TExt<br> Some TExt<br>Some TExt<br> Some TExt<br> Some TExt<br> Some TExt<br> Some TExt<br> Some TExt<br> Some TExt<br> Some TExt<br> </div> </td> </tr> <tr> <td>Box4</td> <td>Box5</td> <td>Box6</td> </tr> <tr> <td>Box7</td> <td>Box8</td> <td>Box9</td> </tr> </table> 

The fiddle I have is here: https://jsfiddle.net/ba5qxzmo/ 我的小提琴在这里: https : //jsfiddle.net/ba5qxzmo/

Box 1 is bad, because the Box1 header text is not "fixed at the top of the box and scrolls with the content. Box 2 is my attempt at creating a fixed header, but it messes up the look of the box entirely. Box 3 and the rest of the boxes also do not have a fixed header. 框1不好,因为框1的标题文本未“固定在框的顶部,并随内容一起滚动。框2是我创建固定标题的尝试,但它完全弄乱了框的外观。框3其余的盒子也没有固定的标题。

How can I make it such that each box has a "fixed" header? 如何使每个框都有一个“固定”标题? (Box1, Box2, Box3), with scrollable content (overflow) beneath each of them? (Box1,Box2,Box3),并在每个滚动条下方都有可滚动的内容(溢出)?

Just add your whole content of a cell except heading in a div and make the div as scrollable using max-height and overflow-y:scroll and set the height of td , heading and content so that everything will align properly. 只需添加除div标题外的单元格的全部内容,然后使用max-heightoverflow-y:scroll使div可overflow-y:scroll并设置td ,标题和内容的height ,以便所有内容都能正确对齐。

 html,body { width:100%; height:100%; } table { border:1; width:100%; height:100%; } td { text-align:center; background:red; padding: 10px 0; } .scroll { overflow-y: auto; height: 100%; background:yellow; } .heading{ height:20px; } 
 <table> <tr> <td> <span class="heading">Box1</span> <div class="scroll"> Some TExt<br> Some TExt<br> Some TExt<br> Some TExt<br>Some TExt<br> Some TExt<br> Some TExt<br> Some TExt<br> Some TExt<br> Some TExt<br> Some TExt<br> Some TExt<br> </div> </td> <td> <span class="heading">Box1</span> <div class="scroll"> Some TExt<br> Some TExt<br> Some TExt<br> Some TExt<br>Some TExt<br> Some TExt<br> Some TExt<br> Some TExt<br> Some TExt<br> Some TExt<br> Some TExt<br> Some TExt<br> </div> </td> <td> <span class="heading">Box1</span> <div class="scroll">Some TExt<br> Some TExt<br> Some TExt<br> Some TExt<br> Some TExt<br> </div> </td> </tr> <tr> <td>Box4</td> <td>Box5</td> <td>Box6</td> </tr> <tr> <td>Box7</td> <td>Box8</td> <td>Box9</td> </tr> </table> 

Take heading on one div and the content in another div, and make the first div position fixed. 以一个div为标题,以内容为另一个div,并固定第一个div的位置。 and give the second div propperty overflow: scroll; 并给第二个div属性溢出:滚动; Some text Some text 一些文字一些文字

     .heading{
        position:fixed;
      }

     .content{
        overflow:scroll;
      }

like this: 像这样:

    <div class="fixed_parent">
        <div class="fixed">
            Some Heading
        </div>
    </div>
    <div class="content">
            Some content
    </div>

 .fixed_parent{
    height:100px; (or if it's depends on height of fixed div and it can changes you can right overflow:hidden; without writhing about height)
  }

 .heading{
    position:fixed;
  }

 .content{
    overflow:scroll;
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM