I have what I think is a strange problem. I have one div, inside the parent div, and I give the child div a width of 100%, but it does not grow to the size of the parent div.
The parent div does not have a given width of any type. So my question is: does the percent width work only if the parent has the specified width or should it grow anyway?
UPDATE:
Some may be wondering how the parent div has a width to grow at all if it itself does not have the width of the set. The reason is because I have other siblings of the child inside the parent div with a set width for them, so the parent div has grown until they correspond to these sibs. Width
SAMPLE CODE:
<div id="parent-div"> <div id="child-element" style="width: 100%">Content</div> <div id="sibling" style="width: 250px"></div> </div>
The child element does not grow to satisfy the parent div. A width of 100% essentially does nothing I can say. This is in IE7.
Thanks.
FOLLOW-UP . Thanks to everyone for the answers. I'm busy testing at my end. Initially, I thought that the parent div only grows as wide as their children, but it turns out that I was mistaken, given my example above, which I encoded only to demonstrate my problem that I am experiencing. In my case, my parent div has position: fixed and bottom: 1px and right: 1px . From my tests, this seems to alter the behavior of the parent div. It no longer stretches to the full width of the page, but assumes that the behavior that I thought was somehow the case is the parent div, which expands to fit its widest child. So the behavior that I see now, but only because my parent div has a fixed position.
css width parent
Matt powell
source share