1

My question is very similar to this one. I would like my table to fill its container, but it takes on whatever size it wants to.

The html tags around the table are:

<body>
  <div>
    <section>
      <table id="my_table">

The css for div and section:

div {
    width: 50%;
    margin: 0px auto;
    overflow: hidden;
    padding: 0 0;
}

section {
    float: left;
    margin-bottom: 20px;
}

I am not doing anything fancy with dataTables:

$('#my_table').dataTable()

I tried pretty much everything in the linked post, but I cannot get the dataTables to fill their container. I removed autoWidth and set the 4 columns to be 25% each. This changed their relative sizes but the total width was still too small.

Could this have anything to do with the section tag?

When I enter anything in the search field, the table becomes the appropriate size.

A jsFiddle that replicates the problem for me: http://jsfiddle.net/mushroom/GHU4f/1/

Community
  • 1
  • 1
mushroom
  • 6,201
  • 5
  • 36
  • 63

2 Answers2

3

Adding width : 100% to the section css fixed the issue:

section {
    float: left;
    margin-bottom: 20px;
    width:100%;
}
mushroom
  • 6,201
  • 5
  • 36
  • 63
0

Add the code below to "table" element works for me.

style="width: 100%;"
Ellix4u
  • 566
  • 5
  • 9