Skip to content

Flexbox issue #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
zonay opened this issue Mar 11, 2021 · 4 comments
Closed

Flexbox issue #10

zonay opened this issue Mar 11, 2021 · 4 comments

Comments

@zonay
Copy link

zonay commented Mar 11, 2021

Does it work inside of flexbox? I couldn't be successful with this code:

<div className='flex h-screen bg-purple-900 items-center flex-col justify-center w-screen'> <div className='aspect-w-16 aspect-h-9'> <img src='https://picsum.photos/id/237/500/500' className='object-cover object-center' alt='' /> </div> </div>

@adgower
Copy link

adgower commented Mar 28, 2021

I had same problem
works by setting width of a parent
<div class="flex justify-end"> <div class="w-1/2"> <div class="aspect-w-16 aspect-h-9"> <img src="./media/LM_Hero.jpg" class="object-cover object-center" alt="Person typing on a laptop keyboard"> </div> </div> </div>

@RSurya99
Copy link

RSurya99 commented Sep 1, 2021

i had the same problem too, but mine fixed by adding 2 width in parent
first i try @adgower solution but ended up having a very small image (the aspect ratio is already correct)

so I have come to a conclusion that flex doesn't have a fixed width, so you need to define the width on parent tag before using aspect-w aspect-h class

<div class="flex flex-col justify-center items-center mt-10 w-full">
	<div class="w-full">
                <div class="aspect-w-16 aspect-h-9">
                    <img src="img/services/img/conference-room.jpg" class="w-full h-full object-center object-cover" alt="">
                </div>
         </div>
	<a href="#">Read More</a>
</div>

@adamwathan
Copy link
Member

Yeah things like this often behave weirdly as direct children of flex containers, just a CSS thing. Glad you figured out a solution!

@ScreamZ
Copy link

ScreamZ commented Sep 27, 2021

https://stackoverflow.com/questions/44009015/use-flexbox-and-maintain-a-11-aspect-ratio-even-though-content-is-sized-differe

To maintain the aspect ratio of responsive elements, you can use the padding technique.
Note that you shouldn't use percentages on padding bottom/top for flex children, see here for more info.

For more details you can see this post

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants