Make 2 DIV's side by side same height and mobile responsive

admin

Administrator
Staff member
I have a Shopify product page where I want to display an image next to a description "box" of the product. The description box contains the product name, description, buy now button etc. The image is on the left, the description box to the right on a desktop.

The image and the description box need to be side by side, as well as mobile responsive obviously with the description box moving below the image on mobile.

Some products may have longer descriptions than others so the DIV description box will have to grow/shrink with the content.

I have this setup in a fashion using <strong><em>flexbox</em></strong>. When the description is very short, the description box is the same size as the image with a background color fill. But when the description is longer, the description box grows to fit the content, but the image doesn't scale with it. See images below.
How do I get the image to scale with the content? I dont mind if the image is cropped at the edges if it grows.

Image with a short description - image fits.

<a href=" " rel="nofollow noreferrer"><img src=" " alt="enter image description here"></a>

Image with a longer description - the image doesn't fit.

<a href=" " rel="nofollow noreferrer"><img src=" " alt="enter image description here"></a>

<strong>HTML</strong> - irrelivant code removed for brevity

Code:
&lt;div class="product-details-row"&gt;
&lt;div class="product-details-column"&gt;&lt;!-- Image here --&gt;
    &lt;img class="product-details-image" src="https://pmcvariety.files.wordpress.com/2018/01/carey-mulligan1.jpg?w=700" /&gt;
&lt;/div&gt;

&lt;div class="product-details-column product-details-right"&gt;&lt;!-- Product details here --&gt;
    &lt;h3 class="product-name"&gt;{{ product.title }}&lt;/h3&gt;

    &lt;div class="product-gallery-heading"&gt;
        {{ ImagsGallaryheading[imagesgallaryheading] }}
    &lt;/div&gt;

    &lt;section class="price-and-reviews-row"&gt;
        &lt;div style="width: 50%; height: auto;float: left;"&gt;
            &lt;span&gt;
                &lt;p class="product-content-box-price"&gt;
                    &lt;span&gt;{{ current_variant.price | money }}&lt;/span&gt;              
                &lt;/p&gt;
            &lt;/span&gt;
        &lt;/div&gt;

        &lt;section&gt;
            &lt;p class="product-hero-image-content-box"&gt;{{ product.description }}&lt;/p&gt;&lt;!-- Product details grows/shrinks here --&gt;
        &lt;/section&gt;
    &lt;/section&gt;

    &lt;hr style="display: block; height: 1px; border: 0; border-top: 1px solid rgba(215,215,215,0.5); margin: 1em 0; padding: 0;"&gt;

    &lt;p class="color-box available-from"&gt;Available colours:&lt;/p&gt;
    &lt;div class="color-square-container green-color-square"&gt;&lt;/div&gt;
    &lt;div class="color-square-container blue-color-square"&gt;&lt;/div&gt;

    &lt;div class="btn_banner"&gt;
        &lt;div class="button-buy"&gt;
            &lt;!-- N/A content removed --&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;



<strong>CSS</strong>

Code:
.product-details-row {
display:-ms-flexbox;
display:-webkit-flex;
display:flex;
margin-bottom:2.5em;
}
.product-details-column {
-webkit-flex:1;
-ms-flex:1;
flex:1;
}
img.product-details-image {
display:block;
max-width:100%;
height:auto;
width:auto;
}
.product-details-right {
background-color:#C15031;
padding:2em;
-webkit-box-shadow: 0px 0px 20px 0px rgba(0,0,0,0.35);
-moz-box-shadow: 0px 0px 20px 0px rgba(0,0,0,0.35);
box-shadow: 0px 0px 20px 0px rgba(0,0,0,0.35);
color:#ffffff;
}
.product-gallery-heading {
font-family:Comfortaa;
color:#d7d7d7;
}
.price-and-reviews-row {
margin-top: 4em;
margin-bottom: 2em;
}
p.product-content-box-price {
color: #ffffff;
font-size: 2em;
font-weight: 400;
}
p.product-hero-image-content-box {
color:#333333;
font-family:Arial;
font-weight:300;
}
.available-from {
color:#ffffff;
font-family:Comfortaa;
font-weight:400;
font-size:0.8em;
}
.color-square-container {
float: left;
width: 20px;
height: 20px;
margin: 5px;
border: 1px solid #ffffff;
}
.green-color-square {
background: #009966;
}
.blue-color-square {
background: #ab3fdd;
}

Secondly, the flex boxes aren't responsive.
How do I set it so that when the page is viewed on mobile, the description box moves below the image? I have tried setting the media query to <em>display: relative</em> for <em>.product-details-row</em>, but this didn't work.

How the mobile view currently looks.

<a href=" " rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9ud3m.png" alt="enter image description here"></a>