Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

256
Views
How to create this "image-overlap-div" layout while keeping it responsive with CSS and/or JS? (See Image example)

How would you position the image (dark rectangle) to overlap the background solid-color-full-width div exactly as pictured (at a point of about 60% height), while keeping in the same across different screen sizes (responsive)? desktop and mobile layout with image

I've tried placing the background color div as first HTML element and applying this CSS:

.full-width-hero-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: gray;
}

While the rest of the content is in normal flow in a flex container. This worked for my screen, but resizing the window makes the background resize too. So in large screens the background is larger in height than the top image, making the image appear inside of it.

I guess I could use CSS media queries and adjust the background size manually, but I'm wondering if there's a better way?

I'd appreciate any insight.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

this can help, using "margin-top" I set content on image.

    body {
    margin: 0;
    font-family: sans-serif;
}

.main-hero {
    height: 100%;
    display: table;
    width: 100%;
    padding-bottom: 100px;
}

.main-hero .image-wrapper img {
    width: 100%;
    height: auto;
    object-fit: cover;
    max-height: 800px;
}

.main-hero .content {
    max-width: 800px;
    margin: -150px auto 0 auto;
    display: table;
    width: 100%;
    text-align: center;
    background-color: #fff;
    box-shadow: 0px 5px 10px 0px #0000008a;
    padding: 50px;
    position: relative;
}

.main-hero .content p {
    font-size: 20px;
}

/*//for tablet*/
@media only screen and (max-width: 991px) {
    .main-hero .content {
        max-width: 600px;
    }
}

/*//for mobile*/
@media only screen and (max-width: 600px) {
    .main-hero .content {
       max-width: 210px;
    padding: 25px;
    margin: -80px auto 0 auto;
    }
    .main-hero .content p {
        font-size: 12px;
    }
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <link rel="stylesheet" href="">
</head>
<body>
    <div class="main-hero">
        <div class="image-wrapper">
            <img src="https://images.unsplash.com/photo-1643303808869-ecfbf62fe81e?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1074&q=80">
        </div>

        <div class="content">
            <h2>Main Title</h2>
            <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
            tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
            quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
            consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
            cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
            proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
        </div>
    </div>
</body>
</html>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!