私は親のdivタグを持っており、彼は複数の子のdivタグである必要があります。子のタグを水平に配置する必要があります。子供のdivタグを数える、高度なことは知られていない、これについては、cssで幅の親divタグを設定することはできません。このためにjsを使用します
var cnt = $("#parent div").length; // obtain children tags total count
var parent_width = cnt * 102 ; // 100 is children tag width and 2 is left and right border sum : 100 + 1 + 1
$("#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>
これは機能しますが、これはjsなしで、cssのみで作成する必要があると思います。方法を教えてください。