user1830984
user1830984

Reputation: 859

scroll bar is currently clipped underneath final table column

What is causing scroll bar to not be clipped on side of table in this fiddle: http://jsfiddle.net/m4HB3/8/ At the moment it is underneath the last column, meaning it is taking up some of that columns space and thus causing alignment issues with the table.

The table headers are fixed as I want a scrolling table with fixed headers.

Could the problem be the width set for the table and individual columns?

Can somebody please also text their answer on a script outside jsfiddle and put it straight on a browser because I have seen examples where something is working in jsifddle but then not working in main application on browser.

HTML:

   <table id="tableqanda" cellpadding="0" cellspacing="0">
    <thead>
    <tr>
        <th width="5%" class="questionno">Question No.</th>
        <th width="27%" class="question">Question</th>
        <th width="7%" class="option">Option Type</th>
        <th width="11%" class="image">Image</th>

    </tr>
    </thead>
    </table>
    <div id="tableqanda_onthefly_container">
    <table id="tableqanda_onthefly" cellpadding="0" cellspacing="0">
    <tbody>
        <tr class="tableqandarow">
<td width="5%" class="questionno">1</td>
<td width="27%" class="question">What is a RAM?</td>
<td width="7%" class="option">A-E</td>
<td width="11%" class="imagetd"><ul class="qandaul"><li>Lighthouse_4.jpg</li></ul></td>
</tr>
<tr class="tableqandarow">
<td width="5%" class="questionno">2</td>
<td width="27%" class="question">Name 3 car maneuvers you may do in a test?</td>
<td width="7%" class="option">A-F</td>
<td width="11%" class="imagetd"><ul class="qandaul"><li>Tulips_3.jpg</li></ul></td>
</tr>
    </tbody>
    </table>
    </div>

CSS:

#tableqanda_onthefly_container
{
    width:100%;
    overflow-y: auto;
    overflow-x: hidden;
    max-height:25px;
}

#tableqanda_onthefly
{
    width:100%;
    overflow-y: auto;
    overflow-x: hidden;
    clear:both;
}

#tableqanda_onthefly td
{
    border:1px black solid;
    border-collapse:collapse;
}

#tableqanda, #tableqanda_onthefly{
    border:1px black solid;
    border-collapse:collapse;
    table-layout:fixed;
    word-wrap:break-word;
}       

#tableqanda{
    width:100%;
    margin-left:0;
    float:left;
}

#tableqanda td { 
    vertical-align: middle;
    border:1px black solid;
    border-collapse:collapse;
}

#tableqanda th{
    border:1px black solid;
    border-collapse:collapse;
    text-align:center;
}

.tableqandarow{
    border:1px black solid;
    border-collapse:collapse;
}

UPDATE:

http://jsfiddle.net/m4HB3/37/

I have a js fiddle which works perfectly. But if you copy code into a standard html, the columns are not aligned. If you can get the columns aligned correctly with their headings with the scroll bar on the side of the table, then that will be perfect answer

Upvotes: 7

Views: 775

Answers (2)

Webapper
Webapper

Reputation: 305

Is that something what could work for you?

Using here script/jQuery within your div to scroll, slightly modified css to give side scrolling.

Please see: http://jsfiddle.net/m4HB3/177

Here's standalone version: http://webapper.pl/demo.html

I didn't spend much time on css but i'm sure you could make it look pretty.

var ele = $('.scroll');
var scroll = 25;

$('.up').on('click',function() {
        ele.scrollTop( ele.scrollTop() - scroll );
});

$('.down').on('click',function() {
        ele.scrollTop( ele.scrollTop() + scroll );
});

Or you can use static table width (that would also fix your problem):

http://jsfiddle.net/m4HB3/178/

Upvotes: 1

Alp
Alp

Reputation: 29739

Here is a fiddle based on the linked question by Sara:

DEMO

html

<div id="tableContainer" class="tableContainer">
<table width="100%" cellspacing="0" cellpadding="0" border="0" class="scrollTable">
    <col width="10%" />
    <col width="54%" />
    <col width="14%" />
    <col width="22%" />
    <thead class="fixedHeader">
        <tr>
            <th class="questionno">Question No.</th>
            <th class="question">Question</th>
            <th class="option">Option Type</th>
            <th class="image">Image</th>
        </tr>
    </thead>
    <tbody class="scrollContent">
        <tr>
            <td class="questionno">1</td>
            <td class="question">What is a RAM?</td>
            <td class="option">A-E</td>
            <td class="imagetd"><ul class="qandaul"><li>Lighthouse_4.jpg</li></ul></td>
        </tr>
        <tr>
            <td class="questionno">2</td>
            <td class="question">Name 3 car maneuvers you may do in a test?</td>
            <td class="option">A-F</td>
            <td class="imagetd"><ul class="qandaul"><li>Tulips_3.jpg</li></ul></td>
        </tr>
        <tr>
            <td class="questionno">3</td>
            <td class="question">What is a RAM?</td>
            <td class="option">A-E</td>
            <td class="imagetd"><ul class="qandaul"><li>Lighthouse_4.jpg</li></ul></td>
        </tr>
        <tr>
            <td class="questionno">4</td>
            <td class="question">Name 3 car maneuvers you may do in a test?</td>
            <td class="option">A-F</td>
            <td class="imagetd"><ul class="qandaul"><li>Tulips_3.jpg</li></ul></td>
        </tr>
        <tr>
            <td class="questionno">5</td>
            <td class="question">What is a RAM?</td>
            <td class="option">A-E</td>
            <td class="imagetd"><ul class="qandaul"><li>Lighthouse_4.jpg</li></ul></td>
        </tr>
        <tr>
            <td class="questionno">6</td>
            <td class="question">Name 3 car maneuvers you may do in a test?</td>
            <td class="option">A-F</td>
            <td class="imagetd"><ul class="qandaul"><li>Tulips_3.jpg</li></ul></td>
        </tr>
        <tr>
            <td class="questionno">7</td>
            <td class="question">What is a RAM?</td>
            <td class="option">A-E</td>
            <td class="imagetd"><ul class="qandaul"><li>Lighthouse_4.jpg</li></ul></td>
        </tr>
        <tr>
            <td class="questionno">8</td>
            <td class="question">Name 3 car maneuvers you may do in a test?</td>
            <td class="option">A-F</td>
            <td class="imagetd"><ul class="qandaul"><li>Tulips_3.jpg</li></ul></td>
        </tr>
    </tbody>
</table>
</div>

css

div.tableContainer {
    clear: both;
    border: 1px solid #963;
    overflow: auto;
}

html>body tbody.scrollContent {
    display: block;
    height: 100px;
    overflow: auto;
    width: 100%
}


html>body thead.fixedHeader tr {
    display: block
}

html>body td {
    box-sizing: border-box;
    border: 1px solid grey;
}

table .questionno {
    width: 10%;
}
table .question {
    width: 54%;
}
table .option {
    width: 14%;
}
table .image {
    width: 22%;
}

Upvotes: 0

Related Questions