I have a fieldset
with a legend
that may be loaded with a very long string.
I want the legend
to respect the width of the fieldset
and use up only 50% of the space.
Currently, if the legend
is too long it will still only take up 50% of the fieldset
but it will force the fieldset
to be as wide as if the entire string was being displayed.
fieldset {
box-sizing: border-box;
display: inline-block;
width: 100%;
}
legend {
max-width: 50%;
}
/* Oversized SPAN content forces the FIELDSET to exceed the 100% width and breaks the layout. */
legend span {
display: inline-block;
width: calc(100% - 100px);
overflow: hidden;
text-overflow: ellipsis;
vertical-align: middle;
}
<div>
<fieldset>
<legend>Product (<span>WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW</span>)</legend>
</fieldset>
</div>