Is there a way to create a layout with three columns of divs, where the middle column is shifted, that automatically collapses into two columns with the second one shifted when the window size is reduced?

For the about page of my website, I have a grid layout consisting of three columns. The challenge is to offset the center column by 50%. When the window size is reduced beyond a certain point, I want the third column to disappear and its images to be distributed across the remaining two columns while maintaining the 50% offset on the center column.

Here is how my current layout appears:

https://i.sstatic.net/Z4R9Q6Bm.png

The second column features pictures with text overlaid for name and job descriptions.

When the window is resized below a specific threshold, I envision the layout transforming into this configuration:

https://i.sstatic.net/pZMsbFfg.png

Unfortunately, at present, when the window shrinks past that particular point, the layout breaks down, causing image overlaps and misalignment.

I am currently utilizing bootstrap 5.3.3

Below is an excerpt of my code:

<!doctype html>
<html>

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script>

.widthSettingImage{
    width: 30%;
    height: fit-content;
    min-width: 180px;
}
 
.bottom-left {
    position: absolute;
    bottom: 16px;
    left: 16px;
}
.bottom-left.fs-6{
    position: absolute;
    bottom: 0px;
    left: 16px;
}
</script>
    <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d3b1bcbca7a0a7a1b2a393e6fde0fde0">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
    <link href="https://getbootstrap.com/docs/5.3/assets/css/docs.css" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="55373a3a21262127342515607b667b66">[email protected]</a>/dist/js/bootstrap.bundle.min.js"
        integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
        crossorigin="anonymous"></script>
</head>

<body>
        <div class="widthSettingImage float-start position-relative text-light m-2" style="box-shadow: 0px 0px 5px 0px;">
            <img src="https://recipe4success.org/workarea/placeholder-image.gif" alt="E"
                class="image-thumnail img-fluid rounded-4" style="opacity: 0.9;">
            <div class="bottom-left fs-5 fw-semibold">Example Name</div>
            <div class="bottom-left fs-6">Software Engineer</div>
        </div>
        <div class="widthSettingImage float-start position-relative text-light m-2" style=" transform:translateY(50%); box-shadow: 0px 0px 5px 0px;">
            <img src="https://recipe4success.org/workarea/placeholder-image.gif" alt="E"
                class="image-thumnail img-fluid rounded-4" style="opacity: 0.9;">
            <div class="bottom-left fs-5 fw-semibold">Example Name</div>
            <div class="bottom-left fs-6">Software Engineer</div>
        </div>
        
        (...rest of the original code...)
        
        <div class="widthSettingImage float-end position-relative text-light m-2" style="box-shadow: 0px 0px 5px 0px;">
            <img src="https://recipe4success.org/workarea/placeholder-image.gif" alt="E"
                class="image-thumnail img-fluid rounded-4" style="opacity: 0.9;">
            <div class="bottom-left fs-5 fw-semibold">Example Name</div>
            <div class="bottom-left fs-6">Software Engineer</div>
</div>
</html>

I'm struggling with implementing this feature as per the desired specifications.

Answer №1

If you're looking to achieve a specific layout that Bootstrap doesn't directly support, consider using custom CSS like CSS Grid for better control.

You can easily create a 2-column grid and then customize it to switch to a 3-column grid at a certain screen width using media queries.

To offset the second column, adjust the margins accordingly within the media queries to avoid conflicting styles being applied simultaneously.

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-gap: 1em;
  img{
    width: 100%;
  }
}

@media only screen and (width <= 500px) {
  img {
    &:nth-child(even) {
      margin-top: 50%;
      margin-bottom: -50%;
    }
  }
}

@media only screen and (width > 500px) {
  .grid {
    grid-template-columns: repeat(3, 1fr);
    img {
    &:nth-child(3n + 2) {
      margin-top: 50%;
      margin-bottom: -50%;
    }
  }
}
<div class="grid">
  <img src="https://placehold.co/400x600">
  <img src="https://placehold.co/400x600">
  <img src="https://placehold.co/400x600">
  <img src="https://placehold.co/400x600">
  <img src="https://placehold.co/400x600">
  <img src="https://placehold.co/400x600">
</div>

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

CSS Grid with dynamically changing number of rows set to "auto", while ensuring one row always has a fixed size of "1fr"

Currently, I am experimenting with a CSS grid-based frontend and have encountered a specific requirement that keeps repeating itself in various parts of the frontend: A grid with a dynamic number of rows. Each row should be of variable size (auto). The f ...

Is there a way to have an image expand to fit the entire screen before scrolling to view another image?

I'm working on a website and I want to have an image that automatically adjusts to fit any screen size. Users should be able to scroll down to see more content or another image. A similar effect can be seen on this site: . Any suggestions would be rea ...

What is the best way to include a drop-right menu within a dropdown menu?

Hey there! I'm working on a page that features a dropdown navbar. My goal is to create a secondary dropdown that appears to the right when hovering over an li element within the initial dropdown. Any tips on how to accomplish this? Thanks in advance! ...

Is it possible to process HTML and JavaScript as a request in JMeter?

After receiving a response, I noticed that the HTML body contains a hidden form along with an internal JavaScript function to submit the form (view snapshot here). Is there a method in JMeter to execute JavaScript code that directly submits a form? I am ...

Utilize the body tag to divide elements in ReactJS

Is there a way to assign different body tags to specific components? For example, I want to apply one body tag to the dashboard component and a different one for the sign up page component. ...

Adjust background image size to fit the dimensions of the foreground content

I have a div where an image and content are inside. I am trying to make the background image adjust its size based on the content within it, rather than showing the full image size with empty space. My current styling uses flexbox: .section { height: ...

Using CSS pseudo elements before and after on an input range

I am looking to create a slider that dynamically displays boundaries. After searching online, I came across some code that I modified to suit my needs. This code uses only HTML and CSS and looks great in Chrome, but not so good in Firefox (I also tried it ...

Maintaining my navigation menu as you scroll through the page

I've been working on creating a website for my business but I'm facing a challenge. My goal is to have a fixed navigation bar that stays in place as people scroll down the page, similar to what you can see on this website: (where the navigat ...

Could anyone provide some insight into the reason behind this occurrence?

I just came across the most peculiar situation I've ever experienced. Check out this unique test page: <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title></title> <script language=javascript> fun ...

Storing information in a database

Need help troubleshooting why my form isn't saving data to the database. <div class="container"> <div class="row" style="margin-top:200px;"> <form ENCTYPE="multipart/form-data" ACTION="upload.php" METHO ...

Stop specific characters from being input into a text field

My goal is to restrict the characters allowed in a text box to the following: A to Z in both upper and lower case, Ñ and ñ, and space. I have a function that runs onkeyup: FieldOnKeyUp(el) { !(/^[A-zÑñ-\s]*$/i).test(el.value)?el.value = el.value ...

Utilizing the onclick event for a div element

I experimented with the div tag and created the following code snippet: <style type="text/css"> #hello{ visibility: visible; cursor: pointer; position: absolute; } #list{ ...

What is the best way to add an element when a checkbox is selected and delete it when it is dese

How can I display the text of selected elements and remove them when unchecked from a list of orders? When an element is checked, its value is added to the sum and its text is displayed. If it is unchecked, its text should be removed. Click here for the co ...

Using CSS to position elements absolutely while also adjusting the width of the div

In one section of my website, I have a specific div structure. This structure consists of two divs stacked on top of each other. The first div is divided into two parts: one part with a width of 63% and another part with a button. Beneath the first div, t ...

Ways to confirm my CSS modifications in Chrome Developer Tools

I find myself tweaking the CSS of various elements using dev tools. After making multiple changes, I often lose track of where I have applied new styles to the elements. Is there a way to easily compare the current styles with the original styles on the ...

Create a new button dynamically within an HTML table row using pure JavaScript programming techniques

Currently, I am retrieving JSON data from an API and then displaying this data in an HTML table using plain JavaScript. My goal is to dynamically add a button at the end of each row for additional functionality, but so far, I have been unable to figure out ...

Restrict the HTML date input to only allow selection of the current date

In my form, I have set an input type date that is restricted to today's date by using the min and max attributes with JavaScript. The issue is that users are still able to manually input a different date instead of selecting it from the calendar popup ...

Looking to reset the default display option in a select dropdown using JavaScript or jQuery?

Here is some HTML code for a select element: <select> <br> <option>1</option><br> <option>2</option><br> </select> This select element will initially display the first option item (display ...

Unable to click on anchor tag in Internet Explorer 11

Hey everyone, I've been searching high and low for a solution to this problem with no luck. Below is the specific line of code I'm referencing: '<a id="auto_refinance_loan_documents_save_link" ' + ((scope.styleAsBtn) ? 'class=" ...

What is the best way to create a border of white space around the background color of a table cell using CSS?

Is there a way to create a white space around the background color of a table cell using CSS? My current code has the background color extend all the way to the edge, and padding only affects the content, not the background color. #main-monitor { widt ...