How can I ensure that two adjacent divs maintain the same height for their content when resizing using CSS Bootstrap?

I have encountered an issue with a vertical slider that I've been developing. The problem arises when there is a change in the display resolution, causing the thumbnails on the right to have a different height than the image on the left. To better understand the issue, I have created a codepen which can be found here:

https://codepen.io/fmalmeida/pen/ZOOagX

.container2 {
  background-color: grey;
}
.container1 {
  background-color: magenta;
  position: absolute;
  max-height: 609px;
  overflow: hidden;
}
.lSection {
  background-color: blue;
  position: relative;
  max-height: 609px;
}
.rSection {
  background-color: green;
  position: relative;
  max-height: 609px;
}
.lSection>* {
  min-width: 100%;
}
.rSection>ul {
  max-height: 609px;
}
.rSection>ul img {
  max-height: 150px;
}
li {
  padding-bottom: 2px;
  list-style: none;
}
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/2.3.2/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/2.3.2/css/bootstrap.min.css" rel="stylesheet" />


<div class="container2 row-fluid">
  <div class="container1 span10">
    <div class="lSection span9">
      <img class="contain" src="http://mw2.google.com/mw-panoramio/photos/medium/58122377.jpg">
    </div>
    <div class="rSection span3">
      <ul>
        <li>
          <a>
            <img src="http://cdn.olhares.pt/client/files/foto/big/330/3301699.jpg">
          </a>
        </li>
        <li>
          <a>
            <img src="http://cdn.olhares.pt/client/files/foto/big/330/3301699.jpg">
          </a>
        </li>
        <li>
          <a>
            <img src="http://cdn.olhares.pt/client/files/foto/big/330/3301699.jpg">
          </a>
        </li>
        <li>
          <a>
            <img src="http://cdn.olhares.pt/client/files/foto/big/330/3301699.jpg">
          </a>
        </li>
      </ul>
    </div>
  </div>
</div>

One way to test this issue is by resizing the browser window. At higher resolutions, the layout seems fine due to the defined maximum height. However, upon resizing the window to lower resolutions, the problem becomes apparent.

If anyone has any suggestions on how to resize both the main image and thumbnails simultaneously while maintaining the same height, it would be greatly appreciated.

Thank you.

Answer №1

The reason for this behavior is attributed to the utilization of Bootstrap version 2.

If you take a moment to examine the illustrations they offer, you will notice that this is an expected outcome. Resize their webpage and observe how the containers designated as span1-span11 expand to full width.

My suggestion in this scenario would be to either upgrade to a newer version of Bootstrap or craft your individual implementation tailored for mobile sites.

Below is the layout table:

<table class="table table-bordered table-striped">
            <thead>
              <tr>
                <th>Label</th>
                <th>Layout width</th>
                <th>Column width</th>
                <th>Gutter width</th>
              </tr>
            </thead>
            <tbody>
              <tr>
                <td>Large display</td>
                <td>1200px and up</td>
                <td>70px</td>
                <td>30px</td>
              </tr>
              <tr>
                <td>Default</td>
                <td>980px and up</td>
                <td>60px</td>
                <td>20px</td>
              </tr>
              <tr>
                <td>Portrait tablets</td>
                <td>768px and above</td>
                <td>42px</td>
                <td>20px</td>
              </tr>
              <tr>
                <td>Phones to tablets</td>
                <td>767px and below</td>
                <td class="muted" colspan="2">Fluid columns, no fixed widths</td>
              </tr>
              <tr>
                <td>Phones</td>
                <td>480px and below</td>
                <td class="muted" colspan="2">Fluid columns, no fixed widths</td>
              </tr>
            </tbody>
          </table>

Answer №2

In my quest to solve this issue, I took a different approach by utilizing viewport size calculation. In this method, I specified a 2:3 format for images and calculated their height based on this format and the viewport units I desired (adjusted to align with bootstrap2 gridsystem width calculations).

If you're interested, here is the link to the codepen showcasing the implementation:

Check out the codepen here

.imageFormatDiv {
  background-color: black;
  display: block;
  height: calc((2/3)*62.55vw);
  overflow: hidden;
  width: 62.55vw;
}

.imageFormatDiv2 {
  background-color: black;
  display: block;
  height: calc((2/3)*15.4vw);
  overflow: hidden;
  width: 15.4vw;
}

.imageFormatDiv img,
.imageFormatDiv2 img {
  min-height: 100%;
  min-width: 100%;
}

.rSection {
  margin-left: 15px;
}

.rSection ul {
  margin: 0px;
}

/* .rSection li {
  float: left;
  position: relative;
} */

.rSection li:nth-child(1),
.rSection li:nth-child(2),
.rSection li:nth-child(3) {
  padding-bottom: 3px;
  overflow: hidden;
}

/* @media screen and (max-width: 768px) {
  .imageFormatDiv {
    background-color: black;
    display: block;
    height: auto;
    overflow: hidden;
    width: auto;
  }
  .imageFormatDiv2 {
    background-color: black;
    display: block;
    height: auto;
    overflow: hidden;
    width: auto;
  }
} */
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/2.3.2/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/2.3.2/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container2 row-fluid">
  <div class="container1 span10" style="background-color:red">
    <div class="lSection span9" style="background-color:blue">
      <!--       <img class="contain" src="http://mw2.google.com/mw-panoramio/photos/medium/58123177.jpg"> -->
      <div class="imageFormatDiv">
        <img class="singleImage" src="https://placemaker.moredata.pt/documents/22267/23267/1-1-A.jpg">
      </div>
    </div>
    <div class="rSection span3 hidden-phone" style="background-color:orange">
      <ul>
        <li>
          <div class="imageFormatDiv2">
            <a><img src="https://placemaker.moredata.pt/documents/22267/23267/1-1-A.jpg"></a>
            <div class="pWrapper">
              <p>TEST 123</p>
            </div>
          </div>
        </li>
        <li>
          <div class="imageFormatDiv2">
            <a><img src="https://placemaker.moredata.pt/documents/22267/23267/1-2-3.jpg"></a>
            <div class="pWrapper">
              <p>TEST 123</p>
            </div>
          </div>
        </li>
        <li>
          <div class="imageFormatDiv2">
            <a><img src="https://placemaker.moredata.pt/documents/22267/23267/1-4-F.jpg"></a>
            <div class="pWrapper">
              <p>TEST 123</p>
            </div>
          </div>
        </li>
        <li>
          <div class="imageFormatDiv2">
            <a><img src="https://placemaker.moredata.pt/documents/22267/23267/1-3-D.jpg"></a>
            <div class="pWrapper">
              <p>TEST 123</p>
            </div>
          </div>
        </li>
      </ul>
    </div>
  </div>
</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

Achieving a centered layout for a div containing two photos that overlap on a mobile screen resolution

I attempted to center a div containing 2 photos perfectly in the center, but encountered some issues. Despite trying various positioning techniques such as display: flex, align-items, justify-content, and more, I couldn't get the image container to mo ...

What steps do I need to take to ensure that the slideshow is visible upon opening

I am having trouble displaying a slideshow by default on my website. I am aiming for something like this: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_slideshow (but with only 2 photos instead of 3) However, what I currently have is: image ...

Enabling visibility of overflowing text in dynamically inserted divs without using scroll bars

Is there a way to set the text overflow to visible without scroll bars in dynamically added <div>s? Despite what the documentation says, it doesn't seem to be the default behavior and I'm struggling to understand why. Adding text directly t ...

Challenges Faced when Connecting JavaScript to HTML

This is a snippet of my HTML where I link the .js file <!DOCTYPE html> <html> <head> <link rel="stylesheet" type="text/css" href="CSS/Style.css"> <title> Learning JavaScript </title& ...

Concealing the Footer on Mobile Websites in Muse UI When the Keyboard Appears

In this project, I am using vue.js along with muse.ui and only incorporating JavaScript and CSS without the jQuery library. Currently, the footer position always ends up on top of the keyboard whenever an input field is focused. Is there a way to ensure th ...

Optimizing window height to 100% on mobile Chrome

My website is designed to adjust based on the size of the browser window, with the first div filling up the entire height using height: 100%. However, I've encountered an issue with certain mobile browsers like Chrome hiding the address bar on devices ...

Every third item is selected using a JQuery selector

Currently, I am tackling the task of working with PHP loops to generate multiple li elements within a single ul. The issue arises when I attempt to display every fourth li upon clicking one of the preceding three li. My current implementation only toggles ...

What is the reason for requiring a style to be set instead of using a class?

Trying to implement the footer staying at the bottom of my website like in this example. You can view my site here. The method is successful, however, I am required to apply the style style="min-height: 100vh;" directly to the body element inste ...

Adjust the buttons in Html using AngularJs to extend the width of the buttons completely

Currently, I am utilizing AngularJS for the development of an application and my task involves creating various buttons. Here is the coding structure I am using: <div class="btn-group-view col-md-12 col-sm-12" role="group" aria-label="Basic example"> ...

Jumping CSS dropdown menu glitch

I'm facing an issue with a dropdown menu. The main problem is that the "parent" link is moving when hovered over. HTML: <ul id="nav"> <li><span>Page 1</span> <ul> <li><a>Extralong Pag ...

Horizontal representation of data utilizing PHP and MySQL

Hey there, I'm trying to showcase data from a mysql table in an HTML table horizontally. The code I've got below is almost perfect, except it's skipping the first record (starting at the second) in my database. My gut says it's somethin ...

Why is the CSS border not activating on hover in Chrome?

When using the mouseover function in Google Chrome, the border bottom is not disappearing as expected. However, this works fine in Firefox and IE. Interestingly, removing border-collapse: collapse fixes the issue. What could be causing this? Is there a sol ...

Updating the background image of a React app according to each component

After researching extensively and attempting various solutions, I am still struggling to make my app function correctly. My goal is to display a different background image depending on which component is being rendered on the screen. The app is built using ...

Issue with displaying submenu in dropdown menu

I need assistance with a project I am currently working on. You can view the project here Everything seems to be functioning properly, except for when I click on the button Click to expand, the sub-menu (Link 1, Link 2, ...) appears far left of the button ...

What is the best way to turn off the responsive features in Bootstrap 4?

Is there a way to turn off the responsive design in Bootstrap 4 while keeping the styles intact? I prefer users accessing the website on mobile phones to see the same layout as the desktop version and be able to zoom in and out using finger gestures. Any ...

What is the best method for designing a button with both inner and outer shadow effects?

Trying to replicate the CSS effect button exactly as shown in the image provided below (ignoring icons), but struggling to achieve the same results. Is there a way to create an identical CSS button? Below is the code for my button: .my-bt{ display:bloc ...

Tips on minimizing the vertical size of a mat field housing a mat-select dropdown

I need help reducing the height of a mat field that includes a mat-select in Angular v15. The code is directly from the material components documentation, with no alterations. It consists of a default table and default outline formfield. <mat-form-fi ...

Utilizing Media Queries with Dynamic Vue Properties

On one of my website pages, I always have a Div element with a Background Image that changes based on Media Queries (for example, I fetch a smaller resolution from my CDN on mobile phones). However, since I retrieve the Image URL on Page Load, I need to s ...

Arrange divs in a vertical stack while maintaining a layout with two columns

I am trying to create a layout with two stacked `div`s on one side, and then have a single column on the other side that is the same height as the left `div`s. Something similar to this: https://i.stack.imgur.com/ODsEd.png I currently have the two `div` ...

The search form on my website is not functioning correctly as the input field is not taking any

My website can be found at I have noticed that the search field on my website does not allow input in Firefox version 17.01. Interestingly, the search function works perfectly fine on Chrome and Internet Explorer browsers. On my website's header, the ...