7

Currently I have something similar to the code below. I'm trying to make the red column irresponsive with set width of 300px but keep the responsiveness of the blue column.

.specific-image-container {
    display: flex;
    position: relative;
    width: 100%;
}
.specific-image-column {
    flex: 4;
    background-color: blue;
}
.more-images-column {
    flex: 1;
    background-color: red;
}
.content {
  height: 300px;
}
<div class="specific-image-container">

    <div class="specific-image-column">
        <div class='content'></div>
    </div>
    
    <div class="more-images-column">
        <div class='content'></div>
    </div>
    
</div>
Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701
Onyx
  • 5,186
  • 8
  • 39
  • 86

3 Answers3

9

Yes, set the fixed column to flex-grow: 0 (so it doesn't grow), flex-shrink: 0 (so it doesn't shrink), and flex-basis: 300px (so it stays fixed at 300px).

jsFiddle demo

.specific-image-container {
    display: flex;
}
.specific-image-column {
    flex: 1;
    background-color: blue;
}
.more-images-column {
    flex: 0 0 300px; /* new */
    background-color: red;
}
.content {
  height: 300px;
}
<div class="specific-image-container">

  <div class="specific-image-column">
    <div class='content'></div>
  </div>

  <div class="more-images-column">
    <div class='content'></div>
  </div>

</div>
Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701
2

Set flex-shrink: 0; width: 300px; on the irresponsive element, and flex-grow: 1; on the flexible element. You can get rid of the flex property once you’ve done that.

Ben Steward
  • 2,338
  • 1
  • 13
  • 23
1

Try using the flex-basis rule. You can use this rule in place of width in flexbox elements. You can also use calc to set the first column to 100% - 300px to make sure 300px takes priority.

.specific-image-container {
    display: flex;
    position: relative;
    width: 100%;
}
.specific-image-column {
    flex-basis: calc(100% - 300px);
    background-color: blue;
}
.more-images-column {
    flex-basis: 300px;
    background-color: red;
}
.content {
  height: 300px;
}
<div class="specific-image-container">

    <div class="specific-image-column">
        <div class='content'></div>
    </div>
    
    <div class="more-images-column">
        <div class='content'></div>
    </div>
    
</div>
Daniel Bernardi
  • 487
  • 2
  • 7