0

My Objective is to have both:

  • Two (or more) boxes adjust responsively, keeping aspect ratio (using padding-top: x %)
  • Have those boxes be contained in a flexbox, so they can have flex flow, wrap, and justify (& any flexbox stuff)

What Works:

Here is what that looks like:

    .prevdisplay {
     display:block;
    }
    .prevspread {
      height:0;
      max-width:540px;
      padding-top:33.33%;
      position:relative;
      background:red;
      margin:0 0 10px;
    }
    .previnfopage {
      background:hsla(1, 50%, 60%, .6);
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
    }
      <section class="prevdisplay"> 
     <div class="prevspread">
      <div class="previnfopage">
              <div>title1</div>
      </div>
     </div>
     <div class="prevspread">
      <div class="previnfopage">
              <div>title2</div>
      </div>
     </div>
      </section>

Here's the jsfiddle: https://jsfiddle.net/gmw4kn7t/3/

CONUNDRUM:

I want the ".prevdisplay" to be this:

.prevdisplay {
    display:flex;
    flex-flow:row;
    flex-wrap:wrap;
    justify-content:center
}

Here's that jsfiddle: https://jsfiddle.net/gmw4kn7t/4/

UPDATE:

I added flex-grow:1 to the child, which works... But, then does not again if the parent of everything is also display:flex ?! Here is what that looks like:

.higherblock {
    display:flex;
    width:100%;
    justify-content:center;
    align-items:center;
    flex-flow:column;
    flex-wrap:wrap;
 }
.prevdisplay {
    display:flex;
  flex-flow:row;
    flex-wrap:wrap;
    justify-content:center;
}
.prevspread {
    height:0;
  max-width:540px;
    padding-top:33.33%;
    position:relative;
  background:red;
  margin:0 10px 10px;
  flex-grow:1;
}
.previnfopage {
    background:hsla(1, 50%, 60%, .6);
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

That's: https://jsfiddle.net/gmw4kn7t/8/

That way, I can do all the Flexbox stuff, like wrapping and justify/align, etc. I couldn't seem to find solutions to this, that isn't related to images. Still, it feels like something incredibly simple I'm missing... am I crazy?

PLCcory
  • 153
  • 3
  • 12
  • 1
    probably need to simply add `flex-grow:1`? – Temani Afif Mar 07 '19 at 22:18
  • That's helpful! But it gets negated again because everything listed above is within another parent that is display:flex: https://jsfiddle.net/gmw4kn7t/7/ ?? – PLCcory Mar 07 '19 at 22:57
  • 1
    it's not good to use automactically flexbox like this ... the one applied to parent seems useless to me, it's doing nothing (only creating issues) – Temani Afif Mar 07 '19 at 23:00
  • 1
    I thought this issue was resolved in newer versions of Firefox, but (assuming it's the same issue) maybe not: https://stackoverflow.com/q/36783190/3597276 – Michael Benjamin Mar 07 '19 at 23:34
  • Thank you for your help. I moved away from the flex container, now I'm trying to figure out why it's so long if it's supposed to be 150% it's width https://jsfiddle.net/gc61vf9p/1/ Anyway, thanks, I have to rethink things. – PLCcory Mar 08 '19 at 00:35

0 Answers0