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/

5
  • Do you have <thead> tags defined? Datatables requires the table have them Commented Nov 20, 2012 at 1:50
  • Yes, I have the thead tags defined. Commented Nov 20, 2012 at 1:54
  • Can you share a link to a working example of them problem in something like jsfiddle.net? Commented Nov 20, 2012 at 2:06
  • Or at least post the HTML so that the problem can be diagnosed Commented Nov 20, 2012 at 2:37
  • Added a link to jsFiddle that replicates the problem for me. I get the behavior I described when using both firefox and chrome. Commented Nov 20, 2012 at 2:50

2 Answers 2

3

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

section {
    float: left;
    margin-bottom: 20px;
    width:100%;
}
Sign up to request clarification or add additional context in comments.

Comments

0

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

style="width: 100%;"

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.