我不知道 .parent
元素将包含多少个 .child
元素,但我知道它们各自的宽度。
我想将 .parent
的宽度设置为 (每个 .child
的宽度) * (总共有多少个 .child
)
我不想使用 floats
和 width: auto
。
我能否使用 calc()
做些什么而不使用Javascript?
.parent {
height: 100%;
width: calc({number of children} * {width of each child = 100px});
}
.child {
height: 100px;
width: 100px;
}
<div class="parent">
<div class="child">a</div>
<div class="child">b</div>
<div class="child">c</div>
</div>
display:flex
是一个选项吗? - Taha Paksudisplay:inline-block
可以实现这个效果。 - Paulie_D