My goal is to have a parent div tag with several children div tags placed horizontally. Since the number of children tags is not known in advance, I cannot set the width of the parent div tag using CSS alone, so I am using JavaScript for this purpose.
var cnt = $("#parent div").length; // Get total count of children tags
var parent_width = cnt * 102 ; // Calculate parent tag width based on children tag width and borders
$("#parent").css({
width: parent_width+"px"
});
<div id="parent" style="height: 100px; background-color: #090">
<div style="height: 100px; width: 100px; background-color: #009; border: 1px solid #ccc; float: left">
</div>
<div style="height: 100px; width: 100px; background-color: #009; border: 1px solid #ccc; float: left">
</div>
</div>
While the current solution works, I believe there might be a way to achieve this layout without using JavaScript, relying solely on CSS. Can someone please guide me on how to do this?