How can I make the child elements resize along the parent elements fluidly while maintaining ratio?
As you can see on the attached video file aspect-ratio: 1/0
works but when you hover the HTML element, it becomes smaller than the rest of the elements. I want my Hero component to stay within the HTML element with the same effect .How can I fix this?
Video: (The sudden change of the carousel you see is when I changed width: 1250px
to max-width: 1250px
)
https://drive.google.com/file/d/14l7UzzRDMfd9AVykaF5gvza68HLycfSH/view?usp=sharing
Hero.js (main)
<div className="Hero" id="Hero">
<Accordion />
<div className="border"></div>
<Carousel />
</div>
Hero.css
.Hero {
width: 1250px;
padding-left: 2rem;
padding-right: 3rem;
display: flex;
justify-content: center;
margin: 0 auto;
}
.Hero .border {
width: 1px;
background-color: #b3b3b3;
margin-left: 1rem;
margin-right: 2rem;
}
/* Responsiveness */
@media only screen and (max-width: 1250px) {
.Hero {
aspect-ratio: 1/0;
}
}
I tried changing width: 1250px
to max-width: 1250px
and the Hero component stays inside the HTML element. However, resizing it even more smaller makes the Carousel resize instead of the entire Hero component.
2
Answers
you can use a combination of flex-grow and flex-shrink properties to control the behavior of the child elements within the flex container.
you can try: