If you want to set a percentage width or height, you must sure the parent nood have set a fix width or height, min-width and min-height are not the kind of fix. normally, you can set a min-width and width to make a responsive website. This approach like flex-grow flex-shrink flex-base, flex-grow can automatically adjust, flex-base is set a base size.
flex-basis is a CSS property used in a flex container to define the initial size of a flex item before any extra space is distributed based on flex-grow or flex-shrink properties. Think of flex-basis as a starting point for the width (in a row layout) or height (in a column layout) of the flex item.
PS: If father flex-direction is row, the children can’t set width. Conversely, If the flex-direction is column, the height parameter of children will invalid. You only can set the flex-base to modify your main-axis sizing.
And the cross-axis sizing is default 100% without setting align-items.
GPT said
Your color-bar div isn’t taking up the full 60% height as expected due to a few potential issues. Here’s how to troubleshoot and fix this:
section-oneheight constraints: Sincesection-oneis defined to have a minimum height (min-height: 90vh), thecolor-bardiv’s height of 60% is relative to the.section-onecontainer, which can make the layout behave unexpectedly based on screen height.Parent container height: Because
.section-oneonly has amin-height, its height can change if the content inside it grows, makingcolor-bar‘s height unpredictable.Testing with
heightdirectly: To see the desired effect ofcolor-bartaking up 60% of the viewport height, try setting its height explicitly asheight: 60vh;(viewport height). Alternatively, ensure.section-onehas a fixed height rather than justmin-height.
Here’s the modified code with 60vh applied to color-bar:
1 | <div class="color-bar" style="height: 60vh;"> |
Or set the height of .section-one to a fixed height, for example, 90vh, to make the 60% height work as intended:
1 | .section-one { |
This should help you see the color-bar at the expected height. Let me know if this works for you!