Ideally, the layout style for the HTML fragment, for example:
<div class="main"> <div class="first">first</div> <div class="value">firstvaluevalue</div> <div class="value">second value value</div> <div class="value">third valuevalue</div> <div class="value">valuevalue on the fourth line</div> </div>
achievable using the following CSS:
.main { display: inline-block; background-color: cornflowerblue; position: relative; width: 50px; } .first { width: 50px; height: 50px; background-color: grey; } .value { word-break: break-all; margin: 1.00em 0; }
as shown in the image: http://jsfiddle.net/audetwebdesign/tPjem/
However, I needed to set the .main width as the .first element in order to get the word-break property in order to take effect.
The problem with CSS rendering here is that you want the .value sibling width to be equal to the unknown .first width, which cannot be done with CSS alone.
CSS rendering is essentially a one-pass top-down algorithm, which means that parent elements cannot inherit values ββfrom child elements (tables have a multi-pass algorithm, but this will not help). This may change in future versions of CSS, but for this we need to develop in accordance with these restrictions.
The JavaScript / jQuery solution is to get the width from .first and apply it to .main and bind it to the window resizing action.
In a sense, this problem makes sense if .first contains an image that has an internal height and width. If that were the case, it would be wise to set the .main width to a reasonable value, and then scale the image in .first to fill the width of the .main block.
Without knowing more about the real content, itβs hard to find alternatives.