调整未知数量的元素以填充父容器的宽度 [英] Resize unknown number of elements to fill width of parent container

查看:74
本文介绍了调整未知数量的元素以填充父容器的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将未知数量的div(可能是大约5个限制)放入父容器中,并始终确保它们保持均等状态.我不确定这是否可以仅使用CSS来完成,但是我想我最好问一下.因此,如果我们知道使用了3个div:

I need to put an unknown number of divs (likely a limit of about 5) into a parent container and always make sure they remain equally divided. I'm not sure if this can be done with CSS alone but I figured I better ask. So if we know that 3 divs are used:

<style>
  .menu-button { 
    float: left;
    width: 33%;
  }
</style>
<div>
   <div class="menu-button">Button X</div>
   <div class="menu-button">Button Y</div>
   <div class="menu-button">Button Z</div>
</div>

似乎可以使用,但是.menu-button div的数目未知怎么办?有没有更好的方法可以做到水平自动调整?

Seems to work, but what if the number of .menu-button divs is unknown? Is there a better way to do it so it automatically adjusts horizontally?

推荐答案

不幸的是,我认为您必须使用表来执行此操作.当<td>调整其大小以适合整个宽度时.

Unfortunatly I think you'll have to use tables to do this. As <td>'s resize itslef to fit into the full width.

HTH

这篇关于调整未知数量的元素以填充父容器的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆