Skip to content
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

How to create a fullscreen image #509

Open
hrvstr opened this issue Mar 1, 2024 · 2 comments
Open

How to create a fullscreen image #509

hrvstr opened this issue Mar 1, 2024 · 2 comments

Comments

@hrvstr
Copy link

hrvstr commented Mar 1, 2024

Hi, I am trying to create a fullscreen hero section. I know I can use the fullWidth layout to fill the width of the container but how about the height? My image comes from a Sanity CMS and I am using the Astro component with Tailwind CSS.

I know I can add the h-screen class but this will stretch the image to fit which seems not ideal. Am I missing something obvious here?

import { Image } from "@unpic/astro";
<Image
  src={image}
  layout="fullWidth"
  class="h-screen"
  priority
/>
@ascorbic
Copy link
Owner

ascorbic commented Mar 1, 2024

Hey. Using CSS is the correct answer. It shouldn't stretch the image, because it sets object-fit: cover by default. If it is strecthing it, could you inspect it and see what the style is?

@hrvstr
Copy link
Author

hrvstr commented Mar 1, 2024

Oh, stretching was the wrong word here, sorry! I meant the image is proportionally scaled up, so it's a bit pixelated. Maybe it would be nice to add a "fullscreen" option as well and generate a srcset with a fitting height as well?

At the moment only the width is considered.

<img 
  class="h-full" 
  loading="lazy" 
  decoding="async" 
  style="object-fit:cover;width:100%" 
  srcset="https://cdn.sanity.io/images/xyz.jpg?w=640&amp;fit=min&amp;auto=format 640w, ..."
>

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

2 participants