CSS Keeping aspect ratio of div with padding, but it's disabled by Flexbox on parentWhy doesn't percentage padding / margin work on flex items in Firefox and Edge?Maintain the aspect ratio of a div with CSSHow to set the margin or padding as percentage of height of parent container?CSS force image resize and keep aspect ratioFill remaining vertical space with CSS using display:flexcenter div in flex div while mantaining aspect ratioPadding trick aspect ratio element - Vertical centeringFlexbox in Chrome doesn't seem to respect 'aspect ratio' padding; fine in FirefoxScale video to fit inside flexbox item while keeping aspect ratioIs there a height derived version of the CSS aspect ratio hackery?Maintain portrait aspect ratio on div using css

Can you identify this lizard-like creature I observed in the UK?

What is the meaning of "You've never met a graph you didn't like?"

Is there anyway, I can have two passwords for my wi-fi

Why is the principal energy of an electron lower for excited electrons in a higher energy state?

Why would five hundred and five be same as one?

How to make money from a browser who sees 5 seconds into the future of any web page?

How do I tell my boss that I'm quitting in 15 days (a colleague left this week)

Can I run 125kHz RF circuit on a breadboard?

Air travel with refrigerated insulin

What the heck is gets(stdin) on site coderbyte?

Is it feasible to let a newcomer play the "Gandalf"-like figure I created for my campaign?

What should be the ideal length of sentences in a blog post for ease of reading?

Does the Crossbow Expert feat's extra crossbow attack work with the reaction attack from a Hunter ranger's Giant Killer feature?

Why can't the Brexit deadlock in the UK parliament be solved with a plurality vote?

Pre-Employment Background Check With Consent For Future Checks

How to test the sharpness of a knife?

Personal or impersonal in a technical resume

I'm just a whisper. Who am I?

Do I have to know the General Relativity theory to understand the concept of inertial frame?

How to get directions in deep space?

How much do grades matter for a future academia position?

Overlapping circles covering polygon

Make a Bowl of Alphabet Soup

Quoting Keynes in a lecture



CSS Keeping aspect ratio of div with padding, but it's disabled by Flexbox on parent


Why doesn't percentage padding / margin work on flex items in Firefox and Edge?Maintain the aspect ratio of a div with CSSHow to set the margin or padding as percentage of height of parent container?CSS force image resize and keep aspect ratioFill remaining vertical space with CSS using display:flexcenter div in flex div while mantaining aspect ratioPadding trick aspect ratio element - Vertical centeringFlexbox in Chrome doesn't seem to respect 'aspect ratio' padding; fine in FirefoxScale video to fit inside flexbox item while keeping aspect ratioIs there a height derived version of the CSS aspect ratio hackery?Maintain portrait aspect ratio on div using css













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:



  • When the parent is NOT flexbox (so, display:block).

  • Using the padding method to keep aspect ratio ( https://www.w3schools.com/howto/howto_css_aspect_ratio.asp )

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?










share|improve this question



















  • 1





    probably need to simply add flex-grow:1?

    – Temani Afif
    Mar 7 at 22:18












  • That's helpful! But it gets negated again because everything listed above is within another parent that is display:flex: jsfiddle.net/gmw4kn7t/7 ??

    – PLCcory
    Mar 7 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 7 at 23:00






  • 1





    I thought this issue was resolved in newer versions of Firefox, but (assuming it's the same issue) maybe not: stackoverflow.com/q/36783190/3597276

    – Michael_B
    Mar 7 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 jsfiddle.net/gc61vf9p/1 Anyway, thanks, I have to rethink things.

    – PLCcory
    Mar 8 at 0:35















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:



  • When the parent is NOT flexbox (so, display:block).

  • Using the padding method to keep aspect ratio ( https://www.w3schools.com/howto/howto_css_aspect_ratio.asp )

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?










share|improve this question



















  • 1





    probably need to simply add flex-grow:1?

    – Temani Afif
    Mar 7 at 22:18












  • That's helpful! But it gets negated again because everything listed above is within another parent that is display:flex: jsfiddle.net/gmw4kn7t/7 ??

    – PLCcory
    Mar 7 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 7 at 23:00






  • 1





    I thought this issue was resolved in newer versions of Firefox, but (assuming it's the same issue) maybe not: stackoverflow.com/q/36783190/3597276

    – Michael_B
    Mar 7 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 jsfiddle.net/gc61vf9p/1 Anyway, thanks, I have to rethink things.

    – PLCcory
    Mar 8 at 0:35













0












0








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:



  • When the parent is NOT flexbox (so, display:block).

  • Using the padding method to keep aspect ratio ( https://www.w3schools.com/howto/howto_css_aspect_ratio.asp )

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?










share|improve this question
















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:



  • When the parent is NOT flexbox (so, display:block).

  • Using the padding method to keep aspect ratio ( https://www.w3schools.com/howto/howto_css_aspect_ratio.asp )

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?






 .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>





 .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>






html css flexbox display aspect-ratio






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 7 at 23:05







PLCcory

















asked Mar 7 at 22:11









PLCcoryPLCcory

83211




83211







  • 1





    probably need to simply add flex-grow:1?

    – Temani Afif
    Mar 7 at 22:18












  • That's helpful! But it gets negated again because everything listed above is within another parent that is display:flex: jsfiddle.net/gmw4kn7t/7 ??

    – PLCcory
    Mar 7 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 7 at 23:00






  • 1





    I thought this issue was resolved in newer versions of Firefox, but (assuming it's the same issue) maybe not: stackoverflow.com/q/36783190/3597276

    – Michael_B
    Mar 7 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 jsfiddle.net/gc61vf9p/1 Anyway, thanks, I have to rethink things.

    – PLCcory
    Mar 8 at 0:35












  • 1





    probably need to simply add flex-grow:1?

    – Temani Afif
    Mar 7 at 22:18












  • That's helpful! But it gets negated again because everything listed above is within another parent that is display:flex: jsfiddle.net/gmw4kn7t/7 ??

    – PLCcory
    Mar 7 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 7 at 23:00






  • 1





    I thought this issue was resolved in newer versions of Firefox, but (assuming it's the same issue) maybe not: stackoverflow.com/q/36783190/3597276

    – Michael_B
    Mar 7 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 jsfiddle.net/gc61vf9p/1 Anyway, thanks, I have to rethink things.

    – PLCcory
    Mar 8 at 0:35







1




1





probably need to simply add flex-grow:1?

– Temani Afif
Mar 7 at 22:18






probably need to simply add flex-grow:1?

– Temani Afif
Mar 7 at 22:18














That's helpful! But it gets negated again because everything listed above is within another parent that is display:flex: jsfiddle.net/gmw4kn7t/7 ??

– PLCcory
Mar 7 at 22:57





That's helpful! But it gets negated again because everything listed above is within another parent that is display:flex: jsfiddle.net/gmw4kn7t/7 ??

– PLCcory
Mar 7 at 22:57




1




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 7 at 23:00





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 7 at 23:00




1




1





I thought this issue was resolved in newer versions of Firefox, but (assuming it's the same issue) maybe not: stackoverflow.com/q/36783190/3597276

– Michael_B
Mar 7 at 23:34





I thought this issue was resolved in newer versions of Firefox, but (assuming it's the same issue) maybe not: stackoverflow.com/q/36783190/3597276

– Michael_B
Mar 7 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 jsfiddle.net/gc61vf9p/1 Anyway, thanks, I have to rethink things.

– PLCcory
Mar 8 at 0:35





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 jsfiddle.net/gc61vf9p/1 Anyway, thanks, I have to rethink things.

– PLCcory
Mar 8 at 0:35












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55053636%2fcss-keeping-aspect-ratio-of-div-with-padding-but-its-disabled-by-flexbox-on-pa%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55053636%2fcss-keeping-aspect-ratio-of-div-with-padding-but-its-disabled-by-flexbox-on-pa%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

Understanding generators in Python2019 Community Moderator ElectionGenerator function not working pythonFor loop not executing two timesGenerators - Printing generated valuesWhy can a python generator only be used once?What exactly do generators do?What does the “yield” keyword do?What does “list comprehension” mean? How does it work and how can I use it?sklearn Kfold acces single fold instead of for loopIs a generator the callable? Which is the generator?Apply Border To Range Of Cells Using OpenpyxlCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Understanding slice notationUnderstanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page