简体   繁体   中英

Make one flex item fixed width and its siblings all equal size

I have four list items and I want three of them to stay the same size and the other one to be at with of 300px.

My HTML:

   <ul class="test">
      <li class="desc">Test description</li>
      <li class="test">Test</li>
      <li class="test">Test</li>
      <li class="test">Test</li>
    </ul>

My SASS:

      ul.test {
        flex: 1 0 auto;
        flex-direction: row;
        display: flex;
      }

      li.desc{
        width: 300px;
      }

      li.test{
        background: green;
        flex: 1 0 auto
      }

I want the first li to be 300px in width and then the other three to be the same size.

 ul.test { display: flex; padding: 0; list-style: none; } li.desc { width: 300px; flex-shrink: 0; /* disable default shrinking behavior */ background-color: orange; } li.test { flex: 1; /* distribute free space evenly among items */ background: lightgreen; } li{ border-right: 1px solid black; } 
 <ul class="test"> <li class="desc">Test description</li> <li class="test">Test</li> <li class="test">Test</li> <li class="test">Test</li> </ul> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM