I have a fieldset
that includes a legend
with potentially long text content.
I need the legend
to only take up 50% of the width of the fieldset
.
Currently, when the legend
is too lengthy, it still occupies 50% of the space but causes the entire fieldset
to stretch in width as if the full string was visible.
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>WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW...</span>)</legend>
</fieldset>
</div>