Whenever I trim down the images, the captions somehow get lost in the thumbnail

My issue arises when cropping photos, as the captions end up being hidden within the thumbnail images. How can I ensure that the captions are visible and also make all images the same height?

I am striving to achieve a layout similar to this: ![][2]

$( document ).ready(function() {
    var heights = $(".thumnbnail").map(function() {
        return $(this).height();
    }).get(),

    maxHeight = Math.max.apply(null, heights);

    $(".thumnbnail").height(maxHeight);
});
.thumbnail {
 height: 200px;
 width: 300px;
 overflow: hidden;
}
.thumbnail img {
 height: auto;
 width: 600px;
}
<div class="row">
    <div class="col-md-3">
        <a href="#">
        <div class="thumbnail">
                <img src="http://ksassets.timeincuk.net/wp/uploads/sites/55/2017/11/GettyImages-873359588-920x584.jpg" alt="osooabina"  class="img-responsive image thumbnail">
                <div class="caption">
                  Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,.
                </div>                
        </div>
        </a>
    </div>    
    <div class="col-md-3">
        <a href="#">
            <div class="thumbnail">
                <img src="https://i.pinimg.com/736x/22/5e/80/225e80ea57b247c188ac160ed34fe3cf--ariana-grande-tattoos-ariana-grande-no-makeup.jpg" alt="" class="img-responsive">
                <div class="caption">
                  Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,.
                </div>
            </div>  
        </a>
    </div>    
    <div class="col-md-3">
        <a href="#">
            <div class="thumbnail">
                <img src="http://gazettereview.com/wp-content/uploads/2015/12/Eminem-Featured-image.jpg" alt="osooabina"  class="img-responsive image thumbnail">
                <div class="caption">
                  Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,.
                </div>
            </div>
        </a> 
    </div>  
    <div class="col-md-3">
        <a href="#">
            <div class="thumbnail">
                <img src="https://www.biography.com/.image/t_share/MTQ3MzM3MTcxNjA5NTkzNjQ3/ariana_grande_photo_jon_kopaloff_getty_images_465687098.jpg" alt="" class="img-responsive">
                <div class="caption">
                  Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,.
                </div>                
            </div>  
        </a>  
    </div>              
</div>

I would like to know how to modify the code to resemble the design shown in the image above.

Answer №1

It seems like the issue you're experiencing is connected to the frequent use of the .thumbnail class. You've applied it to both the <div> and the <img>, causing your jQuery script to try applying maxHeight to both elements.

If we modify your code as follows:

$( document ).ready(function() {
    var heights = $(".thumbnail").map(function() {
        return $(this).height();
    }).get(),

    maxHeight = Math.max.apply(null, heights);

    $(".thumbnail").height(maxHeight);
});
.thumbnail {
  overflow: hidden;
}

.thumbnail img {
  height: auto;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

<div class="container">
  <div class="row">
    <div class="col-xs-3">
      <a href="#">
        <div class="thumbnail">
          <img src="http://ksassets.timeincuk.net/wp/uploads/sites/55/2017/11/GettyImages-873359588-920x584.jpg" alt="osooabina"  class="img-responsive">
          <div class="caption">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,.</div>                
        </div>
      </a>
    </div>    
    
    <div class="col-xs-3">
      <a href="#">
        <div class="thumbnail">
          <img src="https://i.pinimg.com/736x/22/5e/80/225e80ea57b247c188ac160ed34fe3cf--ariana-grande-tattoos-ariana-grande-no-makeup.jpg" alt="" class="img-responsive">
          <div class="caption">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,.</div>
        </div>  
      </a>
    </div>    

    <div class="col-xs-3">
      <a href="#">
        <div class="thumbnail">
          <img src="http://gazettereview.com/wp-content/uploads/2015/12/Eminem-Featured-image.jpg" alt="osooabina"  class="img-responsive">
          <div class="caption">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,.</div>
        </div>
      </a> 
    </div>  

    <div class="col-xs-3">
      <a href="#">
        <div class="thumbnail">
          <img src="https://www.biography.com/.image/t_share/MTQ3MzM3MTcxNjA5NTkzNjQ3/ariana_grande_photo_jon_kopaloff_getty_images_465687098.jpg" alt="" class="img-responsive">
          <div class="caption">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,.</div>
        </div>
      </a> 
    </div>  
  </div>
</div>

This adjustment will give you a layout more consistent with your original design. Keep in mind that this solution doesn't address ensuring the actual images have identical dimensions; it only guarantees uniform height for your .thumbnail containers.

I suggest transforming this into a function that executes on page load and on window resize events.

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

What is the syntax for creating a zip function in TypeScript?

If I am looking to create a zip function: function zip(arrays){ // assume more than 1 array is given and all arrays // share the same length const len = arrays[0].length; const toReturn = new Array(len); for (let i = 0; i < len; i+ ...

Switch the glyphicon based on the open/closed state of the collapsible element - Bootstrap

Is there a way to update the glyphicon based on whether or not a collapsible element is open? This is the code I currently have: <div class="jumbotron ref" data-toggle="collapse" data-target="#collapse"> <div class="row"> <div class=" ...

Enlarge image when clicked

I need help creating a gallery page where users can click on an image to enlarge it, then navigate through the images using arrows on either side. I am not familiar with JavaScript, so could someone guide me on how to achieve this? Also, I would apprecia ...

Troubleshooting the sidebar pin-unpin problem using Jquery and CSS

I have created a single side panel that allows me to toggle between opening and closing the sidebar by hovering on it. I can also pin and unpin the sidebar by clicking on the pin image. Now, I want to open the sidebar onClick instead of onHover and remove ...

Enhance the efficiency of traversing a lengthy list of comparisons within an array.filter method

I am struggling with finding an efficient method to filter out items from an array of objects based on two specific attributes matching those of the last 6 items of another array. Currently, I have a manual process in place which results in cumbersome and ...

Refresh the data in a table upon clicking the menu

I am looking to develop an accordion MENU, but unsure if I should use divs or <ul>. When a submenu is clicked, I want to execute a mysql query to update the data in the table next to the menu. I'm not sure of the best approach and whether to uti ...

Methods for presenting text from an object array using Angular

I'm running into a bit of trouble with getting my text to show up properly in my code. In the HTML, I have <td>{{cabinetDetails.cabinetType}}</td> and my data source is set as $scope.cabinetDetails = [{cabinetType: 'panel'}]; De ...

Reposition the button to the right within a div

I am having trouble moving a button from the left side to the right side in Bootstrap 4. I have attempted using both mr-auto and float-right, but neither seems to be working. Here is my code: <!-- Page Content --> <div class="container"> ...

HTML Download resource

When attempting to create a download link for a file, I found that clicking the link only opened the file in my browser instead of initiating a download. This issue occurred while using Internet Explorer. Here is the code snippet I used: <html> < ...

Utilizing JavaScript within the Spring MVC form tag

Can you please assist me with the following question? I am currently working on a project using JSP, where we are utilizing Spring form tags. My issue involves creating two radio buttons that, when clicked, will display different options and pass the sele ...

Initiating Firebase Configuration

Currently, I have integrated Firebase as the back-end for my app. Here is how my firebase configuration looks: const firebaseConfig = { apiKey: 'xx', authDomain: "xx", databaseURL: "xx", ...

Tips for accessing values from a bs4 result set in Beautiful Soup?

Is there a way to extract all the title values from this bs4 result set? [<span class="zaman" title="16.3.2022 15:22:44">1 hf.</span>, <span class="hide zaman pull-right ml-5 mt--1">( Message Deleted )</sp ...

Strategies for preventing XML caching using pure JavaScript

Looking for a way to prevent XML caching, I came across a potential solution: How to force browser to reload updated XML file?. However, as a beginner, I found that no concrete example was provided. I suspect that the issue lies in this section of my code ...

"PHP and jQuery working together seamlessly with Ajax to achieve

[{ "SchoolId": "015-08-0034-009-37", "SubjectId": "08-0034-00613", "StudentId": "T-15981", "StudentName": "John" },{ "SchoolId": "015-08-0034-009-37", "SubjectId": "08-0034-00613", "StudentId": "T-15982", "StudentName": "Pa ...

Issue with Bootstrap 5.1 scrollspy not activating on list group items

Looking for a solution to a bootstrap scroll spy issue. Despite copying the example directly from the documentation, I can't seem to get it to work properly! https://getbootstrap.com/docs/5.1/components/scrollspy/ The anchor links are functioning co ...

Encountering module error 'internal/fs' after updating to Node 7

We have encountered some challenges after attempting to update our build server to node v7.0.0. Specifically, the application build task fails at the "bower_concat" step with the following error message: Loading "bower-concat.js" tasks...ERROR Error: Cann ...

What is the best way to execute the app functions, such as get and post, that have been defined

After creating a file that sets up an express middleware app and defines the app function in a separate file, you may be wondering how to run the app function. In your app.js file: const express = require('express') const cors = require('c ...

Tips for increasing the width of a button within an HTML table heading

I'm attempting to make a button within a table <th> expand to the full width and height of the header column, even if a table cell in the same column is larger than the text. If I set the width to 100% in CSS, the button ends up matching the siz ...

Is it possible to include edit links to local files in an HTML report that I am creating?

Looking to enhance the readability of py.test reports that look like this: self = <test_testcenter_views.TestSiteViews testMethod=test_testcenter> def test_testcenter(self): "Test the tctr_update view." > r = self.client.get(&a ...

Tips for making Google search results include query strings in the returned links

I need help figuring out how to make Google search results show a URL containing a query string. Here's an example from the project I am currently working on: Instead of this link, Google search returns: If anyone has any suggestions for fixing this ...