Equal height for two divs

I have 2 divs (6 columns each). In the div on the left is the image, in the div on the right is some kind of quote. I want my right div height to be the same as the image height.

enter image description here

Here is my code: http://codepen.io/matysflance/pen/PZXdBK

<div id="testimonials" class="container-fluid testimonials">
    <div class="row">
        <div class="col-lg-6 image">
                <img src="http://placehold.it/1100x700/f3e42a" alt="">
        </div>
        <div class="col-lg-6 quote">
            <blockquote>
                <p>"Integer posuere erat a ante venenatis dapibus posuere veit al..." </p>
                <cite>Susan Sims, Interaction Designer at XYZ</cite>
            </blockquote>
        </div>
    </div>
</div>
+4
source share
5 answers

You can make a container of both divs flexbox that will automatically apply equal heights to child elements.

Try the following:

.row { display: flex; }

Revised Codepen

.row flex, (.image .quote) . . : fooobar.com/questions/5651/...

+4

, jQuery

same-height DIV,

JQuery

jQuery(document).ready(function($) { //noconflict wrapper
    var heights = $(".same-height").map(function() {
        return $(this).height();
    }).get(),
    maxHeight = Math.max.apply(null, heights);
    $(".same-height").height(maxHeight);
});
+3

jQuery Java Script. , . $( ".col-lg-6 quote" ).height($( ".col-lg-6 image" ).height())

, .

+2

:

    var heightImgDiv = $('.ImgDiv').height();
    $('.Div').height(heightImgDiv );
div {
    background: red;
    float: left;
    width: 250px;
    margin: 0 10px 0 10px;
}

img {
  display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="ImgDiv"><img src="https://fallbacks.carbonads.com/nosvn/fallbacks/4cd1acdff7348a672d30bb3326800d80.jpeg"/></div>
<div class="Div"></div>
+1

.

Flexbox

flexbox :

.row {
  display: flex; /* equal height of the children */
}

.col {
  flex: 1; /* additionally, equal width */
  
  padding: 1em;
  border: solid;
}
<div class="row">
  <div class="col">Lorem ipsum dolor sit amet, consectetur adipisicing elit.</div>
  <div class="col">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ad omnis quae expedita ipsum nobis praesentium velit animi minus amet perspiciatis laboriosam similique debitis iste ratione nemo ea at corporis aliquam.</div>
</div>

If you still need to support IE 8 or 9, you need to use a table:

.row {
  display: table;
}

.col {
  display: table-cell;
  width: 50%; /* depends on the number of columns */

  padding: 1em;
  border: solid;
}
<div class="row">
  <div class="col">Lorem ipsum dolor sit amet, consectetur adipisicing elit.</div>
  <div class="col">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ad omnis quae expedita ipsum nobis praesentium velit animi minus amet perspiciatis laboriosam similique debitis iste ratione nemo ea at corporis aliquam.</div>
</div>
Run code
+1
source

Source: https://habr.com/ru/post/1628328/


All Articles