0

Info: I have a cropped image used as a background image for the top of my webpage. In CSS I've defined in px the size of a div containing the image - which is cropping the image. (I'm doing this in Squarespace). So when you enter the page you see the background image (and some text) filling the screen and you then scroll down past the image.

The problem: when I reduce the size of the web browser window the div, of course, maintains the same px height. This means the image ends up being background for most of the page - I just want it to be on the top when you enter the page.

The question: how do I make the cropping div responsive in height? As far as I have researched I can only set the value in px which isn't responsive-friendly... The following code is based on my external screen size. So I need that height px for large screens.

My code:


.header-background {
   position: absolute;
   top: -160px;
   left: -335px;
   right: -335px;
   height: 850px;  
   z-index: -1;
   overflow: hidden;
   background-size: cover;
   background-position: center;
   background-image: img src('/s/Sams-sort.png')
2
  • Do you want it to maintain an aspect ratio? Commented Apr 17, 2020 at 12:23
  • I only want the image to be not distorted. But it doesn't matter how much or how little you see of the image. Commented Apr 20, 2020 at 6:15

1 Answer 1

0

Give it to a free height that takes up the higher space only height:auto

Sign up to request clarification or add additional context in comments.

1 Comment

Can you write more explicitly what my code then would be?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.