Comment faire en-tête fixe de table à l'intérieur de défilement div?

Je veux faire de l'en-tête de mon tableau fixe. Le tableau est présent à l'intérieur de la div scrollable. Ci-dessous mon code.

<div id="table-wrapper">
    <div id="table-scroll">
        <table bgcolor="white" border="0" cellpadding="0" cellspacing="0" id="header-fixed" width="100%" overflow="scroll" class="scrollTable">
            <thead>
                <tr>
                    <th>Order ID</th>
                    <th>Order Date</th>
                    <th>Status</th>
                    <th>Vol Number</th>
                    <th>Bonus Paid</th>
                    <th>Reason for no Bonus</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td><%=snd.getOrderId()%></td>
                    <td><%=snd.getDateCaptured()%></td>
                    <td><%=snd.getOrderStatus()%></td>
                    <td>Data Not Available</td>
                    <td>Data Not Available</td>
                    <td>Data Not Available</td>
                </tr>
            </tbody>
        </table>
    </div>
</div>

Ci-dessous est mon CSS, que je suis à l'aide de la ci-dessus div:

#table-wrapper {
    position:relative;
}

#table-scroll {
    height:250px;
    overflow:auto;  
    margin-top:20px;
}

#table-wrapper table {
    width:100%;
}

#table-wrapper table * {
    background:white;
    color:black;
}

#table-wrapper table thead th .text {
    position:absolute;   
    top:-20px;
    z-index:2;
    height:20px;
    width:35%;
    border:1px solid red;
}
  • Qu'entendez-vous par "faire de l'en-tête de ma table fixe"? Est-il censé être toujours visible malgré le défilement vers le bas?
  • exactement la ligne du haut de tableau doit toujours visible
  • Ive juste ajouté une réponse à une question similaire, qui peuvent aider stackoverflow.com/questions/31433833/...
InformationsquelleAutor Rohan | 2013-07-24