1

Chrome doesn't seem to honor the .width() setting that I set on a table. IE10 does.

I get the width of the table after the page is done loading: 425px. Then I remove the row with the widest content, which makes the table repaint and the table's width shrinks: 185px.

Then, I set the table's width to the original value, 425px. But if I check the width of the table after the set, it is off (by 2px in my experiments): 423px.

Is this a known bug?

Am I using the wrong get/set?

It seems that it has to do with the table border (1px border X2 = 2px), but do I need to do calculations to account for the border when setting the width?

I have a jsfiddle that replicates the problem:

http://jsfiddle.net/slolife/zLyQ2/

var orgWidth = $('table').width();
alert('Original width = ' + orgWidth);
$('table').width(orgWidth);
alert('Width after setting width to ' + orgWidth + ' = ' + $('table').width());
$('#two').remove();
alert('Width after remove = ' + $('table').width());
0

1 Answer 1

2

It's all about the box model.

add

table{
   box-sizing: border-box;
}

The link is a very interesting read but basically you force calculation including borders and padding which is not compatible with w3c spec.

updated jsFiddle

Sign up to request clarification or add additional context in comments.

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.