水平滚动表格中的某些列?

在表格中,我需要将一列“固定”到位,并使其他列水平滚动。下面是一个可视化示例:

http://img3.mukewang.com/632475d500018a7a12320984.jpg

我尝试使用溢出滚动,但它似乎什么也不做:


.horizontal-scrolling {

  display: flex;

  width: 500px;

  overflow: scroll;

}


.horizontal-scrolling th {

  width: 250px;

}


<table>

    <thead>

        <tr>

            <th>First</th>

            <span class="horizontal-scrolling">

                <th>Second</th>

                <th>Third</th>

                <th>Fourth</th>

            </span>

        </tr>

    <thead>

</table>


幕布斯7119047
浏览 73回答 1
1回答

神不在的星期二

我修改了 w3schools 标准表,将一列粘贴到左侧的位置。这种样式可以通过javascript应用于表格的特定列table {&nbsp; font-family: arial, sans-serif;&nbsp; border-collapse: collapse;&nbsp; width: 1000px;}td, th {&nbsp; border: 1px solid #dddddd;&nbsp; text-align: left;&nbsp; padding: 8px;}tr:nth-child(even) {&nbsp; background-color: #dddddd;}tr th:nth-of-type(1),/*this is where the table column gets its*/tr td:nth-of-type(1){/*styling to stick to the left and stay ontop of the rest*/position:sticky;left: 0;z-index: 1;background: white;width: 150px}div {width: 600px;overflow: auto;}<body><h2>HTML Table</h2><div><table>&nbsp; <tr>&nbsp; &nbsp; <th>Company</th>&nbsp; &nbsp; <th>Contact</th>&nbsp; &nbsp; <th>Country</th>&nbsp; </tr>&nbsp; <tr>&nbsp; &nbsp; <td>Alfreds Futterkiste</td>&nbsp; &nbsp; <td>Maria Anders</td>&nbsp; &nbsp; <td>Germany</td>&nbsp; </tr>&nbsp; <tr>&nbsp; &nbsp; <td>Centro comercial Moctezuma</td>&nbsp; &nbsp; <td>Francisco Chang</td>&nbsp; &nbsp; <td>Mexico</td>&nbsp; </tr>&nbsp; <tr>&nbsp; &nbsp; <td>Ernst Handel</td>&nbsp; &nbsp; <td>Roland Mendel</td>&nbsp; &nbsp; <td>Austria</td>&nbsp; </tr>&nbsp; <tr>&nbsp; &nbsp; <td>Island Trading</td>&nbsp; &nbsp; <td>Helen Bennett</td>&nbsp; &nbsp; <td>UK</td>&nbsp; </tr>&nbsp; <tr>&nbsp; &nbsp; <td>Laughing Bacchus Winecellars</td>&nbsp; &nbsp; <td>Yoshi Tannamuri</td>&nbsp; &nbsp; <td>Canada</td>&nbsp; </tr>&nbsp; <tr>&nbsp; &nbsp; <td>Magazzini Alimentari Riuniti</td>&nbsp; &nbsp; <td>Giovanni Rovelli</td>&nbsp; &nbsp; <td>Italy</td>&nbsp; </tr></table></div></body>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript