1

I have a flex layout that puts two fieldsets side-by-side.

I want the fieldsets to equally divide the space, even when one of them has non-wrapping content that is too wide. (It should be hidden.)

All the searches I've performed on this issue indicate that the flex children need to have a max-width applied. This does not work in my case (shown in the snippet below, and echoed on CodePen).

Why is the fieldset growing past 50% width? How do I get the fieldset to hold at 50% wide, and the list of items to be cropped inside the ul?

* { box-sizing:border-box }
#content {
    display:flex;
}
fieldset {
    flex: 1;
    max-width:50%;
}
#items {
    list-style-type:none;
    white-space:nowrap;
    overflow:hidden;
    max-width:100%;
}
#items li {
    display:inline-block;
    width:100px; height:90px;
    background: yellow;
    text-align:center;
    line-height:90px;
}
<div id="content">
    <fieldset id="left"><legend>SECTION 1</legend>
    </fieldset>        
    <fieldset id="right"><legend>SECTION 2</legend>
        <ul id="items">
            <li>AAA</li>
            <li>BBB</li>
            <li>CCC</li>
            <li>DDD</li>
            <li>EEE</li>
            <li>FFF</li>
            <li>GGG</li>
            <li>HHH</li>
            <li>III</li>
            <li>JJJ</li>
            <li>KKK</li>
            <li>LLL</li>
            <li>MMM</li>
            <li>NNN</li>
            <li>OOO</li>
        </ul>
    </fieldset>
</div>
Temani Afif
  • 245,468
  • 26
  • 309
  • 415
Phrogz
  • 296,393
  • 112
  • 651
  • 745
  • 1
    Also - https://stackoverflow.com/questions/19679337/why-are-not-all-flexbox-elements-behaving-like-flexbox-divs – Paulie_D Nov 28 '18 at 17:16
  • @Paulie_D I welcome closing this as a dup if you can find another question that provides an answer to this. I've not been able to. FWIW, `display:block` on the fieldsets does not change the behavior. – Phrogz Nov 28 '18 at 17:16
  • 1
    No..display block wouldn't work because that is overridden by them being flex-items. – Paulie_D Nov 28 '18 at 17:18
  • @Paulie_D I agree that changing from `
    ` to another container (and updating the CSS) fixes this problem. Please feel free to close as a duplicate. And Thanks!
    – Phrogz Nov 28 '18 at 17:19
  • 1
    I think this one has a solution - https://stackoverflow.com/questions/29559739/why-fieldset-inside-flex-act-differently-between-browsers – Paulie_D Nov 28 '18 at 17:20
  • 2
    https://codepen.io/Paulie-D/pen/EOdEby – Paulie_D Nov 28 '18 at 17:20
  • 1
    That is a crazy hack. Great find! – Phrogz Nov 28 '18 at 17:21

0 Answers0