Adjustable box widths based on content

丶灬走出姿态 提交于 2019-12-12 05:05:56

问题


I'm new to flexbox, but I'm assuming it's the best tool for what I'm trying to do. (If not, I'm open to other ideas.) I have a set of features of a "product" - something like this:

<div class="flexbox-container">
  <div class="borderbox flexbox">A paragraph of content about the first feature...</div>
  <div class="borderbox flexbox">Another paragraph of content about the second feature...</div>
  <div class="borderbox flexbox">The third feature...</div>
</div>

...with 12 boxes in all. See http://codepen.io/OsakaWebbie/pen/kkyYOp to see my real content with a klugey way of getting something close to what I want. What I really want is to define a common height for the boxes and then let flexbox adjust the widths based on the content (minimizing dead space after shorter paragraphs), but I can't figure out how. flex-basis:auto sounds relevant, but it didn't have any effect on the layout. I tried this CSS:

.flexbox {
  height: 8em;
  min-width: 8em;
  max-width: 20em;
}

But it ignored the min-width and made everything the max. Currently I'm having to tweak the markup and specify a width (or a class equating to a width) for each box based on its content, but I'm hoping to get the power of flexbox to do that automatically. Is it possible?

来源:https://stackoverflow.com/questions/39706445/adjustable-box-widths-based-on-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!