如果我在框中包含一个元素:
+-------- box --------+
| *------------* |
| | small text | |
| *------------* |
+---------------------+
Run Code Online (Sandbox Code Playgroud)
display: inline-block收缩包装它的诀窍就好了.但是,如果内容由于受约束的宽度而跨越多行,则无法收缩包装元素.
+-------- box --------+
| *-----------------* |
| | this does not | |
| | shrink | |
| | appropriately | |
| *-----------------* |
+---------------------+
Run Code Online (Sandbox Code Playgroud)
有没有办法产生下面看到的预期结果?
+-------- box --------+
| *---------------* |
| | this does not | |
| | shrink | |
| | appropriately | |
| *---------------* |
+---------------------+
Run Code Online (Sandbox Code Playgroud)
这是一个显示两个案例的小提琴:http://jsfiddle.net/urLa8jvc/2/和一个解决方案,我在正确的位置手动打破线来显示所需的结果.首选CSS解决方案,但javascript也可以接受.