0

I have a table that is in a DIV with overflow: auto :

HTML:

<div id="table">
  <table>
    <tr>
      <th>Heading</th>
    </tr>

    <tr>
      <td>Data</td>
    </tr>
  </table>
</div>

In total there are 6 TH tags and 6 TD tags

CSS:

div#table
{
    overflow: auto;
    padding: 15px;
}

div#table table
{
    border-collapse: collapse;
}

The overflow ensures that there is a horizontal scroll bar on the DIV so that the full table can be viewed.

I also specified padding on the DIV in the hope that the scroll bar and table are not positioned on the edges of the DIV - however this bit isn't working.

So basically what I want is for there to be padding around the DIV and the overflown content should not be touching the right edge of the DIV. I hope this makes sense!

2
  • Can we see the rest of your css (the part that applies to these elements?) Commented Jan 6, 2011 at 20:46
  • how about simply adding a last <td> element in each row that is empty? Commented Jan 6, 2011 at 20:53

3 Answers 3

1

You need something like this? http://jsbin.com/iseda3 if yes you can use the following code:

html

<div id="table">
  <div>
    <table>
      <tr>
        <th>Heading</th>
        <th>Heading</th>
        <th>Heading</th>
        <th>Heading</th>
        <th>Heading</th>
        <th>Heading</th>
      </tr>
      <tr>
        <td>Data</td>
        <td>Data</td>
        <td>Data</td>
        <td>Data</td>
        <td>Data</td>
        <td>Data</td>
      </tr>
    </table>
  </div>
</div>

css

div#table {
    background:#09F;
    width:150px;
}
div#table div {
    overflow: auto;
    margin: 15px;
}
div#table table {
    border-collapse: collapse;
}
Sign up to request clarification or add additional context in comments.

Comments

0

It sounds like you need to wrap your table in one further <div> element that has the required padding within it. Your table would then fit within that element but would still be subject to the parent container's overflow.

<div id="table">
  <div style="padding: 1em;">
  <table>
    <tr>
      <th>Heading</th>
    </tr>

    <tr>
      <td>Data</td>
    </tr>
  </table>
  </div>
</div>

Comments

0

You might want to consider making a container div that has the padding, and then put the div with id table inside of that larger div.

div#tableHolder
{
    padding: 15px;
}
div#table
{
    overflow: auto;
}

div#table table
{
    border-collapse: collapse;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.