It seems that this should be a duplicate - I found a lot of similar questions, but no one answered my work. If I missed one, point it to me and I will delete this one.
I have an absolutely positioned div containing several child divs. I want the container to expand to the width of the widest child, and all other children to expand to the same width. The container must have a minimum width and maximum height; if there are too many children, it should scroll.
Thus, this is similar to the behavior of a drop-down list, but it is used in a different context.
In the solution, I started working on Chrome, Firefox, and IE8, but not in IE7 (standard mode), where children do not expand to the width of the container. I tried a number of changes, some of which made the children expand, but all this led to additional problems. What is the right way to do this?
I created the following example to illustrate the problem:
<html>
<head>
<style>
.container {
display: block;
position: absolute;
top: 50px;
left: 50px;
min-width: 100px;
max-height: 100px;
border: 1px solid #999;
overflow-x: hidden;
overflow-y: auto;
}
.entry {
display: block;
width: auto;
height: 20px;
padding: 3px 20px 3px 5px;
white-space: nowrap;
background: #eee;
}
</style>
</head>
<body>
<div class='container'>
<div class='entry'><input type="checkbox"/>ABCDEFGHIJKLMNOPQRSTUVW</div>
<div class='entry'><input type="checkbox"/>ABCDEFGHIJKLMNOPQRSTUVWXYZ</div>
<div class='entry'><input type="checkbox"/>ABCDEFGHIJKLMNOPQRST</div>
<div class='entry'><input type="checkbox"/>ABCDEFGHIJKLMNOPQ</div>
<div class='entry'><input type="checkbox"/>ABCDEFGHIJKLMNOPQRST</div>
<div class='entry'><input type="checkbox"/>ABCDEFGHIJKLMNOPQRSTUVW</div>
</div>
</body>
source
share