Skip to content

Needs h-0 class on the wrapping div regardless? #12

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
exalted opened this issue Mar 16, 2021 · 3 comments
Closed

Needs h-0 class on the wrapping div regardless? #12

exalted opened this issue Mar 16, 2021 · 3 comments

Comments

@exalted
Copy link

exalted commented Mar 16, 2021

Watching https://www.youtube.com/watch?v=NX_NW6bt6_s it seemed we could remove also h-0 from the parent element, however, if I do that, then the aspect ratio is not always respected.

In short, I have a grid of 3 columns, where the 2nd column spans to 2:

<div class="grid grid-cols-3">
  <div class="aspect-w-1 aspect-h-1">
    <img
      class="object-cover rounded-lg shadow-lg"
      src="/assets/img/freud.jpeg"
      alt=""
    />
  </div>
  <p class="col-span-2 font-light">
    <span class="italic font-serif"
      >Some text</p>
</div>

So, ideally, I'd expect the image to appear as a square no matter what the viewport size is, however, check out this screen recording as the screen size gets narrower and narrower:

Screenshot 2021-03-16 at 14 46 33

As you can see, Freud's photo, at some point isn't square anymore!

If I add h-0 to the parent div however, so that the code above becomes:

<div class="grid grid-cols-3">
  <div class="h-0 aspect-w-1 aspect-h-1">
    <img
      class="object-cover rounded-lg shadow-lg"
      src="/assets/img/freud.jpeg"
      alt=""
    />
  </div>
  <p class="col-span-2 font-light">
    <span class="italic font-serif"
      >Some text</p>
</div>

Then it works as advertised:

Screenshot 2021-03-16 at 14 49 59

So, I wonder, is this a bug or am I missing something?

Thanks!

@hubionmac
Copy link

I had the same issue in a grid (and flex while testing) with a table element but just in Safari. (https://play.tailwindcss.com/Z4HgPoie2d)
h-0 just seems to force the browser to calculate the height of an object inside when the browser just isn't smart enough to do so

@adamwathan
Copy link
Member

Hey! This is just a flexbox quirk as mentioned, have to deal with the same stuff when writing vanilla CSS 👍 Nothing for us to really change in the library I don't think so going to close but hopefully that's helpful.

@exalted
Copy link
Author

exalted commented Sep 13, 2021

@adamwathan no strong opinions here however, I would like to argue that, although not a tailwind bug per se, IMO tailwind should opt into maintaining the aspect ratio by default (i.e. added h-0 behavior).

After all, that's how this plugin is "advertised" in https://www.youtube.com/watch?v=NX_NW6bt6_s: it does remove h-0 from the parent element and replaces it with aspect-*.

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

3 participants