Reputation: 11802
my CSS code
.child{
width:100px;
height:100px;
display:inline-block;
}
my HTML code
<div id="parent">
<div class="child">
</div>
<div class="child">
</div>
</div>
the .parent width will be 100%,but i want to make the parent width equals exactly the some of all childs, but i don't know how many child i will have and i don't know the width of each one
what is the easiest way to do that using CSS AND/OR Jquery ?
Upvotes: 0
Views: 2471
Reputation: 532
$(document).ready(function(){
var sumwidth=0;
$("#parent").children().each(function() {
var child = $(this);
sumwidth+=child.width();
});
$("#parent").width(sumwidth);
});
Upvotes: 1