What is the best way to position a row of divs above their parent div?

Need guidance on placing a row of divs (each with 3 columns of images) on top of a parent div (image) using Bootstrap 5. Previously used position: absolute, but encountering overflow issues. Attempted overflow: visible as well. Provided below is the code snippet and the current result. Appreciate any assistance.

.accomplishments{
  background: url("https://picsum.photos/1000/600");
  width: 100%;
  height: 40rem;
  background-size: cover;
  margin-top: 12rem;
  position: relative;
}

.project-tray{
  position: absolute;
  top: 0%;
  left: 50%;
  transform: translate(-50%, -50%);
  overflow-y:visible ;  
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet"/>
<main>
  <div class="container" >
    <h1 class="">Accomplishments</h1>
  </div>
  <div class="container-fluid  accomplishments mb-5 ">
    <div class="container" >
      <div class="row project-tray ">
        <div class="col " >
          <img src="https://picsum.photos/300/301" class="img-fluid " alt="">
        </div>
        <div class="col">
          <img src="https://picsum.photos/300/302" class="img-fluid" alt="">
        </div>
        <div class="col">
          <img src="https://picsum.photos/300/303" class="img-fluid" alt="">
        </div>
      </div>
    </div>
  </div>
</main>

Links to output images:

Current output

Expected output (figma)

Answer №1

Typically, it is considered best practice to steer clear of using position absolute for a basic layout like this one (as position absolute disrupts the normal flow and can cause the height to collapse). Achieving this overlap effect is much simpler with negative margins (while still maintaining the normal flow).

Here's a snippet showcasing how you can achieve the desired layout with just one line of custom CSS:

.negative-margin{
  margin-top: -150px;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet"/>

<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet"/>
<main>
  <div class="container">
    <h1 class="">Accomplishments</h1>
  </div>
  <div class="container-fluid accomplishments mb-5 ">
    <div class="container" >
      <div class="row project-tray ">
        <div class="col " >
          <img src="https://picsum.photos/201/300" class="img-fluid " alt="">
        </div>
        <div class="col">
          <img src="https://picsum.photos/202/300" class="img-fluid" alt="">
        </div>
        <div class="col">
          <img src="https://picsum.photos/203/300" class="img-fluid" alt="">
        </div>
      </div>
    </div>
  </div>
  <div>
    <img class="img-fluid negative-margin" alt="Responsive image" src="https://picsum.photos/1920/1080">
  </div>
</main>

Answer №2

After making some minor adjustments to the bootstrap layout, I moved the accomplishments class from the container-fluid to the col-12 class. I also included margin-top: 200px !important;, which was previously missing in your stylesheet.css under .accomplishments

.accomplishments {
  background: url(https://picsum.photos/1000/600);
  width: 100%;
  height: 36rem !important;
  margin-top: 200px !important;
  background-size: cover;
  position: relative;
}

.project-tray {
  position: absolute;
  top: 0%;
  left: 50%;
  transform: translate(-50%, -50%);
  overflow-y: visible;
}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7d1f1212090e090f1c0d3d48534d534f">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<main>
  <div class="container heading">
    <h1 class="text-center pt-5">Accomplishments</h1>
  </div>
  <div class="container-fluid">
    <div class="row">
      <div class="col-12 accomplishments">
        <div class="row project-tray ">
          <div class="col ">
            <img src="https://picsum.photos/300/301" class="img-fluid " alt="">
          </div>
          <div class="col">
            <img src="https://picsum.photos/300/302" class="img-fluid" alt="">
          </div>
          <div class="col">
            <img src="https://picsum.photos/300/303" class="img-fluid" alt="">
          </div>
        </div>
      </div>
    </div>
  </div>
</main>

Answer №3

As a beginner in web development, my suggestion would be to consider removing the top: 0%; property and observe if it has any effect on the layout.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How to specifically exclude a checkbox from the "select all" function in J

One way to select all checkboxes with HTML code: Select All <input type="checkbox" name='select_all' id='select_all' value='1'/> To achieve this with Javascript code: <script type="text/javascript> $(&apos ...

I am looking to incorporate a rounds div into the backdrop

My attempt to use border-radius did not solve my issue. I am trying to create a circular background for a specific section of the page, as shown in the image. For my first inquiry: I only want the circular background at the top of the page, not the botto ...

The echo function is repeating something that is not text

I have set up a basic bottle server using Python: from bottle import route, run, static_file @route('/') def home(): return static_file("home.html", root='.') @route("/<fileName>") def respond(fileName): return static_f ...

Storing HTML table data in a MySQL database will help you

Operating a website focused on financial planning where users can input various values and cell colors into an HTML table. It is crucial to uphold the integrity of these HTML tables. How can I store the complete HTML table (including values and colors) i ...

Fixing a div at the top post scroll - bug on iOS mobile device

I am looking to achieve a similar effect as demonstrated in the example below: https://css-tricks.com/scroll-fix-content/ Essentially, the goal is to have a div become fixed at the top of the page after scrolling to a certain point. Initially, the div wil ...

Manipulate DIV elements with jQuery by selecting them based on their class names and then

Is there a way to use jQuery to eliminate all DIVs on a webpage while preserving their content that have the following specific pattern? <div class="ExternalClass85AC900AB26A481DBDC8ADAE7A02F039">....</div> Please note that these DIVs adhere ...

How can I display the output from Geocoder in a text box using the ArcGIS JavaScript API?

I am trying to customize the Geocoder text box in the ArcGIS JavaScript API by overriding the default search result. Although I have written some code for this purpose, I am not satisfied with the results. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 ...

Tips for shutting down an open section within a jQuery Accordion?

I am having trouble closing the active panel using jQuery. The rest of my code is functioning perfectly, but for some reason, I can't get the active panel to close. Currently, the code is working correctly in that only one panel can be open at a time ...

The requested style from ' was denied due to its MIME type ('text/html') not being compatible with supported stylesheet MIME types, and strict MIME checking is enforced

It's strange because my style.css file in the public folder works on one page but gives me an error on another. I'm not sure why it would work on one page and not on the other. The CSS is imported in index.html so it should work on all pages of t ...

There is an ample amount of blank space located at the bottom of the page

There seems to be an excess of white space at the bottom of my webpage, despite my efforts to adjust margins and padding. I've inspected the elements using browser developer tools but have been unable to pinpoint the issue. var chatResponseBox = do ...

choose multiple elements from an array simultaneously

Looking for help with a basic Array question and seeking the most effective solution. The scenario involves having an array: var pathArr = [element1, element2, element3, element4, element5, element6] If I want to select multiple elements from this array ...

How come WhatsApp is not recognizing my og:tags correctly?

I'm having an issue with my webpage where the og:tags generated for link previews on Facebook work fine, but they can't seem to be scraped by WhatsApp. Even though the tags are correct in the source code of the site, WhatsApp shows an error messa ...

Ensure that the child div remains at the bottom of the parent div

I'm trying to make sure that the subfooter div stays at the bottom of the childbox div like a footer. You can see the code on this jsfiddle link <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8> <title ...

Creating square images in CSS without specifying their dimensions can easily be done by centering

Is there a way to create square images from rectangular ones in CSS, while ensuring they remain centered on the page? I have come across numerous solutions that use fixed pixel sizes, but I need my images to be responsive and set in percentages. Essential ...

When the page loads in the React platform, a section of the footer unexpectedly overlaps with another component

After working on this section some time ago, I returned to find a strange behavior that I couldn't fix by changing the CSS or wrapping components in divs. If you want to see the issue, check out this screenshot: issueReact To view the code where the ...

Equal Sized <li> elements within Bootstrap Cards

I've been working with the following "template", and there are multiple cards like this on the settings page I'm currently developing. <!-- Card template --> <div class="card mt-3 shadow-sm"> <div class="card-hea ...

Simple: What is causing the error message "TypeError: 'int' object is not callable" to appear? (refer to line 24 in the code)

I'm struggling with a coding issue and can't seem to find a solution. Would appreciate it if someone could provide some guidance on what's going wrong. Essentially, this script is designed to fetch the HTML content of a URL, extract specific ...

Alteration of Content Height Input

I have designed a layout that I am excited to experiment with more in the future. Here is the current structure of my HTML: <!DOCTYPE html> <html> <head> <title>Title</title> <link rel="stylesheet" type="text/css" hre ...

What is the process for incorporating CSS, JavaScript, and images into a Django project?

Within the static folder, I have created a CSS file called resume.css with the following structure: static css resume.css In my settings.py file, I did not make any changes to the static code. I have referenced the index.html file in my vie ...

Guide on aligning a series of divs in a single row within a parent div

Within the confines of a 400px wide div called "container", there are six left-floated "box" divs, each 100px wide. The combined width of the "box" divs exceeds 400px, resulting in the divs wrapping onto two lines, with 4 on the first and 2 on the second ...