CSS table right margin in scrollable div

后端 未结 4 1207
隐瞒了意图╮
隐瞒了意图╮ 2021-01-20 04:08

I have div with \"overflow: scroll\" and fixed-size table inside.
I need to add empty space below and on the right of the table.
I\'m using following code, however i

相关标签:
4条回答
  • 2021-01-20 04:25

    Remove the width attribute for the div. Everything will work fine as expected.

    div{
        display: inline-block;
        height: 100px;
        background: blue;
        overflow: scroll;
      }
    
    0 讨论(0)
  • 2021-01-20 04:30

    The div, haven't the correct width. Adding 120px (20px to margin), and resizing the table to 100px this work.

    CSS:

      div{
        display: inline-block;
        width: 120px; /* Updated*/
        height: 120px; /* Updated*/
        background: blue;
        overflow: scroll;
      }
      table{
        table-layout: fixed;
        background: red;
        margin-bottom: 20px; 
        margin-right: 20px; 
        width: 100px; /* added */
      }
      td{
        min-width: 150px;
        max-width: 150px;
    
      }
    

    Demo

    0 讨论(0)
  • 2021-01-20 04:37

    You could reset the default display:table to inline-table.

    table {
      display: inline-table;
    }
    

    div {
        display: inline-block;
        width: 100px;
        height: 100px;
        background: blue;
        overflow: scroll;
    }
    table {
        display: inline-table;
        table-layout: fixed;
        background: red;
        margin-bottom: 20px;
        margin-right: 20px;
    }
    td {
        min-width: 150px;
        max-width: 150px;
    }
    <div>
        <table>
            <tr><td>a</td></tr>
            <tr><td>b</td></tr>
            <tr><td>c</td></tr>
            <tr><td>d</td></tr>
        </table>
    </div>

    0 讨论(0)
  • 2021-01-20 04:42

    you need to add padding-left in your table style

    replace your table css

     table{
     table-layout: fixed;
     background: red;
     margin-bottom: 20px; /* working */
     margin-right: 20px; /* not working */
     padding-left: 23px;
    }
    

    here jsfiffle demo : http://jsfiddle.net/sL8zxLbn/

    0 讨论(0)
提交回复
热议问题