I have a situation where I need to specify that a child's width be 100% of the INNER width of the parent, not the outer width, meaning that the parent scrolls horizontally.
The situation looks similar to this:
http://codepen.io/anon/pen/ygqPZG?editors=1100
HTML
<div id='parent'>
<table id='child1'>
<colgroup>
<col width='400px'></col>
</colgroup>
<tbody>
<tr>
<td>Child1withareallyreallylongtitle</td>
</tr>
</tbody>
</table>
<div id='child2'>
<p>Child 2</p>
</div>
</div>
CSS
#parent {
margin: 16px;
border: 1px solid black;
box-sizing: border-box;
overflow-x: auto;
}
#child1 {
width: 100%;
border: 1px solid red;
}
#child2 {
width: 100%;
border: 1px solid blue;
}
As you shrink the screen small enough that the table (chld 1) stops shrinking and it forces the parent to overflow and thus show the scrollbar, the second child still retains 100% of the OUTER width of the parent, I would like it to be 100% of the INNER width of the parent so that it is the same width as the first child (table).
I would like to keep the answer as pure of CSS as possible, JavaScript would be fine as long as it doesn't rely on window resize events because the #parent may be shrunk for other reasons (a horizontal sibling grows).