内嵌非包裹元件容器的流体宽度(Fluid width for container of inline, non

编程入门 行业动态 更新时间:2024-10-27 08:24:55
内嵌非包裹元件容器的流体宽度(Fluid width for container of inline, non-wrapping elements)

我有一点CSS麻烦。

我有一些div元素结构如下例所示。 有一个动态数量的class =“block”div,每个div都有一个固定的宽度:

<div class="outer-container"> <div class="inner-container"> <div class="block">text</div> <div class="block">text</div> <div class="block">text</div> <!-- More "block" divs here --> </div> </div>

我的目标是找到一个基于CSS的解决方案。

显示class="block" div内联,而不包括新行。 支持可变数量的class="inner-container" div,如上所示,每个div都显示为自己的行。 让外部容器流畅地"shrink-wrap"以匹配其内容物的宽度。

有什么建议么?

I'm having a little CSS trouble.

I have some div elements structured like the following example. There are a dynamic number of class="block" divs, each with a fixed width:

<div class="outer-container"> <div class="inner-container"> <div class="block">text</div> <div class="block">text</div> <div class="block">text</div> <!-- More "block" divs here --> </div> </div>

My goal is to find a CSS-based solution that will.

Display the class="block" divs inline, without them wrapping to new lines. Support a variable number of class="inner-container" divs like the one above, each displayed as its own line. Have the outer container fluidly "shrink-wrap" to match the width of its contents.

Any suggestions?

最满意答案

不是100%确定这是否是您正在寻找的,但它可能是一个开始:

http://jsfiddle.net/r4dEX/3/

通过将每个block元素设置为display: inline-block和white-space: nowrap ,它应该允许元素彼此并排放置,但如果内容长于可用空间,则不会换行到新行(而是block将转移到新的一行)。

每个inner-container将显示在其自己的行上( display: block是div默认行为)。

将外部容器设置为display: inline-block将使其“收缩包装”以适合其内容。

Not 100% sure if this is what you're looking for, but it might be a start:

http://jsfiddle.net/r4dEX/3/

By setting each block element to display: inline-block and white-space: nowrap, it should allow the elements to sit alongside each other, but not wrap to a new line if the content is longer than the available space (instead the block will move to a new line).

Each inner-container will display on its own line (display: block is default behaviour for a div).

Setting the outer container to display: inline-block will cause it to 'shrink wrap' to fit its content.

更多推荐

本文发布于:2023-08-03 02:21:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1382909.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:流体   宽度   容器   内嵌   包裹

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!