Getting the correct field on a very wide HTML table?
I have a wide table - so wide it can't fit into the width of the screen; therefore the browser is required to display scrollbars. I would like to have 20px space to the left and right of this table; so i tried to style it (full code below) with
table {
margin-left: 20px;
margin-right: 20px;
text-align: left;
border-collapse: collapse;
background-color: #e0e4f5;
}
The left margin is displayed as expected:
but the right margin is not (a bit hard to see - but note the alignment of the right edge of the horizontal scroll bar with the right edge of the table):
Can you get some kind of correct display margin?
Here is my complete test code:
Table {margin-left: 20px; margin-right: 20px; text-align: left; borderline crash: failure; background-color: # e0e4f5; }
<table id="mytable">
<caption>Table caption</caption>
<thead>
<tr>
<th scope='col'>head 1</th>
<th scope='col'>head 2</th>
<th scope='col'>head 3</th>
<th scope='col'>head 4</th>
<th scope='col'>head 5</th>
<th scope='col'>head 6</th>
<th scope='col'>head 7</th>
<th scope='col'>head 8</th>
<th scope='col'>head 9</th>
<th scope='col'>head 10</th>
<th scope='col'>head 11</th>
<th scope='col'>head 12</th>
<th scope='col'>head 13</th>
<th scope='col'>head 14</th>
<th scope='col'>head 15</th>
<th scope='col'>head 16</th>
<th scope='col'>head 17</th>
<th scope='col'>head 18</th>
<th scope='col'>head 19</th>
<th scope='col'>head 20</th>
<th scope='col'>head 21</th>
<th scope='col'>head 22</th>
<th scope='col'>head 23</th>
<th scope='col'>head 24</th>
<th scope='col'>head 25</th>
<th scope='col'>head 26</th>
<th scope='col'>head 27</th>
<th scope='col'>head 28</th>
<th scope='col'>head 29</th>
<th scope='col'>head 30</th>
<th scope='col'>head 31</th>
<th scope='col'>head 32</th>
<th scope='col'>head 33</th>
<th scope='col'>head 34</th>
<th scope='col'>head 35</th>
<th scope='col'>head 36</th>
<th scope='col'>head 37</th>
<th scope='col'>head 38</th>
<th scope='col'>head 39</th>
<th scope='col'>head 40</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="100">Table footer</td>
</tr>
</tfoot>
<tbody>
<tr>
<td>test 1</td>
<td>test 2</td>
<td>test 3</td>
<td>test 4</td>
<td>test 5</td>
<td>test 6</td>
<td>test 7</td>
<td>test 8</td>
<td>test 9</td>
<td>test 10</td>
<td>test 11</td>
<td>test 12</td>
<td>test 13</td>
<td>test 14</td>
<td>test 15</td>
<td>test 16</td>
<td>test 17</td>
<td>test 18</td>
<td>test 19</td>
<td>test 20</td>
<td>test 21</td>
<td>test 22</td>
<td>test 23</td>
<td>test 24</td>
<td>test 25</td>
<td>test 26</td>
<td>test 27</td>
<td>test 28</td>
<td>test 29</td>
<td>test 30</td>
<td>test 31</td>
<td>test 32</td>
<td>test 33</td>
<td>test 34</td>
<td>test 35</td>
<td>test 36</td>
<td>test 37</td>
<td>test 38</td>
<td>test 39</td>
<td>test 40</td>
</tr>
<tr>
<td>test 1</td>
<td>test 2</td>
<td>test 3</td>
<td>test 4</td>
<td>test 5</td>
<td>test 6</td>
<td>test 7</td>
<td>test 8</td>
<td>test 9</td>
<td>test 10</td>
<td>test 11</td>
<td>test 12</td>
<td>test 13</td>
<td>test 14</td>
<td>test 15</td>
<td>test 16</td>
<td>test 17</td>
<td>test 18</td>
<td>test 19</td>
<td>test 20</td>
<td>test 21</td>
<td>test 22</td>
<td>test 23</td>
<td>test 24</td>
<td>test 25</td>
<td>test 26</td>
<td>test 27</td>
<td>test 28</td>
<td>test 29</td>
<td>test 30</td>
<td>test 31</td>
<td>test 32</td>
<td>test 33</td>
<td>test 34</td>
<td>test 35</td>
<td>test 36</td>
<td>test 37</td>
<td>test 38</td>
<td>test 39</td>
<td>test 40</td>
</tr>
<tr>
<td>test 1</td>
<td>test 2</td>
<td>test 3</td>
<td>test 4</td>
<td>test 5</td>
<td>test 6</td>
<td>test 7</td>
<td>test 8</td>
<td>test 9</td>
<td>test 10</td>
<td>test 11</td>
<td>test 12</td>
<td>test 13</td>
<td>test 14</td>
<td>test 15</td>
<td>test 16</td>
<td>test 17</td>
<td>test 18</td>
<td>test 19</td>
<td>test 20</td>
<td>test 21</td>
<td>test 22</td>
<td>test 23</td>
<td>test 24</td>
<td>test 25</td>
<td>test 26</td>
<td>test 27</td>
<td>test 28</td>
<td>test 29</td>
<td>test 30</td>
<td>test 31</td>
<td>test 32</td>
<td>test 33</td>
<td>test 34</td>
<td>test 35</td>
<td>test 36</td>
<td>test 37</td>
<td>test 38</td>
<td>test 39</td>
<td>test 40</td>
</tr>
<tr>
<td>test 1</td>
<td>test 2</td>
<td>test 3</td>
<td>test 4</td>
<td>test 5</td>
<td>test 6</td>
<td>test 7</td>
<td>test 8</td>
<td>test 9</td>
<td>test 10</td>
<td>test 11</td>
<td>test 12</td>
<td>test 13</td>
<td>test 14</td>
<td>test 15</td>
<td>test 16</td>
<td>test 17</td>
<td>test 18</td>
<td>test 19</td>
<td>test 20</td>
<td>test 21</td>
<td>test 22</td>
<td>test 23</td>
<td>test 24</td>
<td>test 25</td>
<td>test 26</td>
<td>test 27</td>
<td>test 28</td>
<td>test 29</td>
<td>test 30</td>
<td>test 31</td>
<td>test 32</td>
<td>test 33</td>
<td>test 34</td>
<td>test 35</td>
<td>test 36</td>
<td>test 37</td>
<td>test 38</td>
<td>test 39</td>
<td>test 40</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
source to share
If you can add div-table-wrapper like in this jsFiddle ( http://jsfiddle.net/nnJ6F/1/ ) you can set that to display inline block
.table-wrapper {
display:inline-block;
}
Here's a jsFiddle running: http://jsfiddle.net/nnJ6F/5/
source to share
You can make the table element set to display:inline-block;
and this will give you the correct fields. Just make sure the inline block meets your browser compatibility requirements .
Demo .
source to share