0

I want to make my table responsive for the application i am using. I have tried all different approach like making it scroll as the window size decreases. But i want to have a approach where the table squeezes or squishes to fit the size of the window. Please find my code. hope i find an answer soon!

.buttonListContainer {
  position: fixed;
  top: 8.2%;
}

.buttonlistcontext {
  position: fixed;
  border: 0.1px solid #ddd;
  margin-top: 1px;
  background-color: transparent;
  margin: 0;
  padding: 0;
  top: 0;
  left: 0;
}
<div class="buttonListContainer" style="overflow:auto;margin-top:0;">
  <table id="buttonList" class="buttonlistcontext" style="visibility:hidden;">
    <tr>

      <!-- the spike count -->
      <td>
        <font size="2">Eventcount</font>: <input type="text" id="EventCount" style="width:40px;text-align:center;" disabled></td>
      <td><button style="cursor:pointer" onclick="reset()"><font size="2">Reset</font></button></td>

      <!-- the jump to very beginning button -->
      <td><input type="image" id="btn01" style="height:15px;width:15px;" src="images/play_first.png" onclick="jump_firstFrame();" />

        <!-- the play back button -->
        <input type="image" id="btn02" style="height:15px;width:15px;" src="images/play_back2.png" onclick="playBack();" />

        <!-- the go back button -->
        <input type="image" id="btn03" style="height:15px;width:15px;" src="images/play_back.png" onclick="go_back();" />

        <!-- the stop button -->
        <input type="image" id="btn07" style="height:15px;width:15px;" src="images/stop.png" onclick="animationFlag = 0; cancelAnimationFrame(myAnimation);" />

        <!-- the go forward button -->
        <input type="image" id="btn04" style="height:15px;width:15px;" src="images/play_fwd.png" onclick="go_forward();" />

        <!-- the play forward button -->
        <input type="image" id="btn05" style="height:15px;width:15px;" src="images/play_forward2.png" onclick="play();" />

        <!-- the jump to last button -->
        <input type="image" id="btn06" style="height:15px;width:15px;" src="images/play_last.png" onclick="jump_lastFrame();" /></td>

      <!-- the speed buttons -->
      <td>
        <font size="2">Speed</font>: x<select name="PlaySpeed" id="PlaySpeed" onchange="Speed(this.value);">
                    <option value= "1">1</option>
                    <option value= "5">5</option>
                    <option value= "10" selected="selected">10</option>
                    <option value= "50">50</option>
                    <option value= "100">100</option>
                    <option value= "200">200</option>

                </select>
      </td>

      <!-- Wall color drop-down list -->
      <td>
        <font size="2">Wall color</font>: <select id="WallColor" style="background-color: #CCFFCC" onchange="wallColor(this.value);">
                    <option value="1" style="background-color: #F0F0F0">Silver gray</option>
                    <option value="2" style="background-color: #CCFFCC" selected="selected">Mint green</option>
                    <option value="3" style="background-color: #FCFBE3">Vanilla cream</option>
                    <option value="4" style="background-color: #d5e8f4">Water blue</option>
                </select>
      </td>

      <!-- the scale up button -->
      <td>
        <font size="2">Sensitivity</font>: </td>
      <td><input type="image" id="btn08" style="height:15px;width:15px;" src="images/scale_up.png" onclick="sensitivity_Up();" /></td>
      <td><input type="image" id="btn09" style="height:15px;width:15px;" src="images/scale_down.png" onclick="sensitivity_Down();" /></td>

      <!-- the Montage buttons -->
      <td>
        <font size="2">Montage</font>: <select name="MontageSwap" id="MontageSwap" onchange="montageSwap(this.value);">
                    <option value= "1" selected="selected">Common Average</option>
                    <option value= "2">CII</option>
                    <option value= "3">Bipolar</option>
                </select>
      </td>


      <td>
        <!-- <button id="filterBtn" style = "cursor:pointer" onclick="filter()" ><font size="2">Filter</font></button> -->
        <a href="javascript:void(0)" onclick="filter()">
          <font size="2">Filter</font>
        </a>
      </td>

      <!-- the line cursor -->
      <td><input type="checkbox" id="LineCursor" onclick="lineCursorFlag=this.checked;draw_TeeChart()" checked/>
        <font size="2">Line cursor</font>
      </td>

      <!-- the pink bars -->
      <td><input type="checkbox" id="BGbar" onclick="BGbarFlag=this.checked;draw_TeeChart()" checked/>
        <font size="2">Highlights</font>
      </td>

      <!-- the Time interval -->
      <td>
        <font size="2">Time interval</font>: <select name="TimeInterval" id="timeIntervalSelect" onchange="timeInterval=this.value*fs;draw_TeeChart()">
                    <option value= 5>5 sec</option>
                    <option value= 10 selected="selected">10 sec</option>
                    <option value= 20>20 sec</option>
                </select>
      </td>

      <td>
        <button id="modalBtn-pre" style="cursor:pointer" onclick="CGI()"><font size="2">Pre-annotation</font></button>
      </td>
    </tr>

  </table>
</div>
Sreetam Das
  • 3,226
  • 2
  • 22
  • 36
prb_cm
  • 117
  • 1
  • 4
  • 13
  • With a table, you are seriously hindered, so some general tips... 1) Get rid of the table for layout. 2) Get rid of the table for layout. 3) Replace the obsolete `font` tag with something more modern and semantic ... `label` 4) See if `fieldset` fits your needs anywhere. 5) See if grouping your control/label pairs with a `div` makes sense. 6) Look at `flex-box` and other options. 7) Investigate how media queries might improve responsiveness. – Jon P Jun 13 '17 at 05:39

2 Answers2

0

You could take a look at adding bootstrap to your project. This could save you a lot of time and effort. Bootstrap is awesome for writing responsive code.

If you have added bootstrap, just do the following to achieve your table effect on mobile:

<div class="table-responsive">
    <table class="table">
        ....
    <table>
</div>

That will give you a scrollable table on mobile. If you do not want to go the bootstrap route, you could try the following with the HTML above:

<style>

@media screen and (max-width: 767px){
    .table-responsive {
        width: 100%;
        margin-bottom: 15px;
        overflow-y: hidden;
        -ms-overflow-style: -ms-autohiding-scrollbar;
        border: 1px solid #ddd;
    }
}

.table-responsive {
    min-height: .01%;
    overflow-x: auto;
}

.table{
    width: 100%;
    max-width: 100%;
}

</style>

That should do the trick. Check out this plunkr.

But really take a look at adding bootstrap.

manneJan89
  • 1,004
  • 8
  • 27
  • I will consider adding bootstrap. but the above styling didn't do the trick ! – prb_cm Jun 13 '17 at 05:47
  • @prb_123 Seems to work. It scrolls vertically for any screen width smaller than 767px. I added a plunkr. Check it out – manneJan89 Jun 13 '17 at 07:44
  • Hi , i tried your design. it exactly works as shown in the plunkr. But all i want is it to work as squishing the table. as shown in the article below https://css-tricks.com/accessible-simple-responsive-tables/ – prb_cm Jun 13 '17 at 11:24
  • O okay, I understand. It should squish by default. Give your table a width of 100%, and handle your width with percentage instead of pixels. – manneJan89 Jun 13 '17 at 12:06
  • cool, this is working. but i have to crack my head to resize the position. Is there a easy way out to set pixels to percentage without knowing the container width?!! – prb_cm Jun 14 '17 at 03:50
  • I am not 100% sure what you mean. Are you talking about the width of the inside the ?
    – manneJan89 Jun 14 '17 at 04:53
  • yes, the width of elements. I am converting the pixels to percentage from trial and error method. it is kind of working!! – prb_cm Jun 14 '17 at 05:45
  • unfortunately, this is only trial and error. until you reach the desired width. – manneJan89 Jun 14 '17 at 05:56
  • hi, it looks all good now after handling in percentage. However, it all breaks on IE!!!! It works well on Firefox though. – prb_cm Jun 15 '17 at 02:13
  • Nothing ever works in IE. did you give your table a width of 100%? – manneJan89 Jun 15 '17 at 08:59
  • yes i did give width 100% .I am having a second thought on using Bootstrap. can we add more than 12 columns using Bootstrap without wrapping the columns to rows for responsive design? – prb_cm Jun 15 '17 at 09:34
  • No, bootstrap works only in 12 columns. The only way to add more, is to write your own custom css – manneJan89 Jun 15 '17 at 15:51
0

Well, to make it responsive, you need to do major re-design, using bootstrap, or flexbox, or something else.

But you still can have a responsive table. Add the following code to your CSS, should work:

table {
    display: block;
}
tr {
    display: block;
}
td {
    display: inline-block;
}

If you don't like how it looks like and still want to maintain the table layout for desktop and have something responsive for mobile, here's another trick. You have the normal table layout for desktop, and for mobiles and desktops with less than 900 pixels window width it will be stacked vertically:

@media (max-width: 900px) {
    table {
        display: block;
    }
    tr {
        display: block;
    }
    td {
        display: block;
    }
}

EDIT: For "squish" effect, you can do it like this:

@media (max-width: 900px) {
    table {
        display: block;
    }
    tr {
        display: block;
    }
    td {
        display: inline-block;
        width: 32%;/* to have 3 columns */
    }
}

Edit 2: Here's a demo using the last edit. 2 things to notice:

  1. Added box-sizing: border-box; to the "td".
  2. Since we're using "display: inline-block;", for the inline-block to work as desired, all white-spaces between "td"s must be removed. Here's an example:

This:

<td>
    cell1
</td>
<td>
    cell2
</td>

Should be changed to:

<td>
    cell1
</td><td>
    cell2
</td>
evilReiko
  • 19,501
  • 24
  • 86
  • 102
  • can we squish the table according to the screen size as shown in the article here https://css-tricks.com/accessible-simple-responsive-tables/ – prb_cm Jun 13 '17 at 11:26
  • the above design works quite okay but when screen size is decreased all columns tend to come to next line overlapping on other frames on the page. so ideally i want the table to shrink or squish as the width decreases. – prb_cm Jun 13 '17 at 11:35
  • @prb_123 Updated my answer – evilReiko Jun 13 '17 at 11:56
  • yes , thank you. i tried it too. still it does not squish by default. All the column items fall one under each item. The earlier solution looks better.Please refer the article for when i say "squish" css-tricks.com/accessible-simple-responsive-tables – prb_cm Jun 14 '17 at 01:26
  • @prb_cm By "squish" you mean 3 columns, right? updated my answer, look at **Edit 2**. – evilReiko Jun 14 '17 at 08:23
  • I really appreciate your help. But all i want is to see all the columns in the same row. Not only 3 columns. still it should be able to fit to minimized screen sizes only on desktop. – prb_cm Jun 15 '17 at 02:02
  • @prb_cm ok "in same row" Ok now I got you. You can't do that because you have too many columns in the same row, unless you want to have a horizontal scroll bar, [here's a demo](https://jsfiddle.net/evilReiko/k3vrL6nL/). – evilReiko Jun 15 '17 at 07:07
  • cool. Thanks for the clarification. I had similar thought. Do you think we can add more than 12 columns using bootstrap. without wrapping the column to new row? – prb_cm Jun 15 '17 at 09:31
  • @prb_cm I don't think you will like this idea, but If you're using bootstrap, you can have your own customization of bootstrap, [here](http://getbootstrap.com/customize/#grid-system) – evilReiko Jun 15 '17 at 09:46