gpt4 book ai didi

html - 为每个元素平均划分一个空间

转载 作者:太空狗 更新时间:2023-10-29 14:38:35 27 4
gpt4 key购买 nike

有什么方法可以为每个元素平均划分一个空间(或 div),而无需为 width 指定绝对值。只是为了使 CSS 代码灵活。

例如,如果您将这些元素放入一个 div 中:

<div id="parent">
<div class="child"></div>
<div class="child"></div>
</div>

CSS会自动给每个.child元素width=50%

在这个例子中:

<div id="parent">
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
</div>

CSS也会自动给每个.child元素width=25%

这可能吗?

最佳答案

恐怕你必须使用表格并为子 div 添加一个包装,你可以这样做:

#parent{
width: 1000px; /* Example width */
height: 100px; /* Example height */
display: table;
table-layout: fixed;
}
.childwrap {
display:table-row;
}
.child{
display: table-cell;
}

示例:http://cssdesk.com/rZKRW

关于html - 为每个元素平均划分一个空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16285331/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com