standardizing the size of thumbnails across a gallery

Is there a reason why I am unable to adjust the size of thumbnail photos? I want them all to be consistent:

 <h2>Book:</h2>

  <div class="my-gallery" itemscope itemtype="http://schema.org/ImageGallery">

    <figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
      <a href="imgur/book/2EuGD9S.jpg" itemprop="contentUrl" data-size="900x900">
          <img src="imgur/book/2EuGD9S.jpg" itemprop="thumbnail" alt="Image description" height="300" width="300" />
      </a>
                                          <figcaption itemprop="caption description">Image caption 1</figcaption>

    </figure>

    <figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
      <a href="imgur/book/Cmg3qMt.jpg" itemprop="contentUrl" data-size="900x900">
          <img src="imgur/book/Cmg3qMt.jpg" itemprop="thumbnail" alt="Image description" data-size="300x300" />
      </a>
      <figcaption itemprop="caption description">Image caption 2</figcaption>
    </figure>

    <figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
      <a href="imgur/book/DyvInMR.jpg" itemprop="contentUrl" data-size="900x900">
          <img src="imgur/book/DyvInMR.jpg" itemprop="thumbnail" alt="Image description" data-size="300x300" />
      </a>
      <figcaption itemprop="caption description">Image caption 3</figcaption>
    </figure>



  </div>

See complete code here: https://gist.github.com/monajalal/3dace3489e20e0aeeba5351a7987065a This is what I currently observe: https://i.sstatic.net/v6TWM.png

I am utilizing this resource: http://codepen.io/dimsemenov/pen/ZYbPJM

Update: Despite modifying the CSS, the margin-right property remains unaffected and when set to 200x200 there is no margin. What could be causing this? https://i.sstatic.net/z5saO.png

.my-gallery {
  width: 100%;
  float: left;
}
/*
.my-gallery img {
  width: 100%;
  height: auto;
}
*/

.my-gallery img {
  height: 150px;
  width: 150px;
  margin-right: 10px;
}
.my-gallery figure {
  display: block;
  float: left;
  margin: 0 5px 5px 0;
  width: 150px;
}
.my-gallery figcaption {
  display: none;
}

Answer №1

To achieve a specific width and height for your figure, it is recommended to assign the dimensions directly to the image element.

.my-gallery img {
  width: 200px;
  height: 200px;
  display: block;
}
.my-gallery figure {
  display: block;
  float: left;
  margin: 0 5px 5px 0;
}

By following this approach, you will get the desired display outcome: https://i.sstatic.net/QWXmE.png

Answer №2

To incorporate images within <a> tags as a background-image for the same <a> element, simply eliminate the width: 150px; property from the <figure> section. Feel free to refer to this resource on Codepen

For example:

CSS:

figure a {
  display: block;
  width: 150px;
  height: 150px;
  border: 10px solid #fff;
  background-size: cover;
}

HTML:

<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
  <a href="https://farm3.staticflickr.com/2567/5697107145_a4c2eaa0cd_o.jpg" itemprop="contentUrl" data-size="1024x1024" style="background-image: url('https://farm3.staticflickr.com/2567/5697107145_3c27ff3cd1_m.jpg')">
  </a>
  <figcaption itemprop="caption description">Image caption 1</figcaption>  
</figure>

I trust that this solution proves to be helpful!

Answer №3

Although you are setting all of them to the same width, their different dimensions will result in varying heights. To make them uniform in height, consider cropping them to matching dimensions or warping them by specifying a specific height. The existing height: auto simply maintains their original proportions.

Oh, and I must say, that's one lovely banana.

Answer №4

Here is one way to achieve the desired effect:

...

.my-gallery img {
  ...
  width: 100%;
  min-height: 100%;
}

.my-gallery figure {
  ...
  overflow: hidden;
  width: 200px;
  height: 200px;
}
...

Keep in mind that this method will result in cropping the image on the right side. Consider your preferences before implementing it.

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 causes a div to be larger than its content?

I am working on a small program for playing Quantik, and I have encountered an issue with the div#gameTable element being larger than its content. I am utilizing a CSS grid structure for layout and my goal is to display the entire game on one page without ...

What is the standard "placeholder" for a Select-box in Angular?

Currently in the process of developing a front-end web application with Angular 6, I have encountered a challenge. Specifically, I am working on creating a component that includes various select-boxes, resembling this setup: https://i.sstatic.net/6DmL9.pn ...

Can an HTML popup be designed to cover the entire screen, similar to a full screen video player?

Is there a way to create a unique experience similar to a full-screen video player, where it expands beyond the boundaries of the browser to occupy the entire height and width of the monitor? I want to achieve this using HTML as the foundation, allowing me ...

Sending chosen selection in a scrollable dropdown menu in Angular

Here is the HTML code that I'm working with: <div class="container"> <div> <h1 class="table-title">Employees</h1> <table class="table"> <thead class="thead-dark"& ...

Tips on expanding the background beyond the boundaries of a parent container with a specific width limit

Could you please take a look at the code snippet below? I am dealing with a situation where I have a container with a fixed width, and inside that container, there are rows whose width exceeds that of the parent container. Some of these rows have a backgro ...

Utilize a dynamically generated href to execute a C# function

I am currently in the process of creating a dropdown menu using HTML ul & li tags. Everything is working smoothly so far, but I have encountered an issue. Whenever there is an anchor tag (as indicated by the in-line comment), I would like to call a f ...

How can we make shadowing take center stage?

I have a design with two stacked divs, and I'm trying to create the illusion that one is behind the other using shadow effects. When I add a shadow to the left side of the right div, it works perfectly. However, when I try to add a shadow to the right ...

Embed numerous HTML pages within a designated DIV by utilizing a list of hyperlinks

I'm currently facing an issue and can't seem to figure out the solution. I am looking for a way to achieve this without using PHP or JAVA as I am not proficient in those languages yet. The scenario is that I have 18 products/links and a single d ...

Automatically Format Date Input and Block Alphabetic Characters

I am in need of an HTML form that has two distinct sections. The first part requires the user to input their date of birth in a specific format. I have successfully implemented the auto-formatting feature that adds slashes as the user types. However, I am ...

Using Google Maps API v3 to Convert User-Input Coordinates into LatLng Points

I'm a beginner when it comes to using Google Maps and I'm having trouble with turning coordinates input by a user into moving a marker on my map. The goal is for the marker to pan to the specific coordinates entered by the user. Unfortunately, my ...

Ensure the background image is optimized for viewing on screens of any size

I am facing an issue with an image on my website that serves as the background for some elements. The image is wider than it is tall, causing problems for users viewing the site on phones. Is there a way to cut off the sides of the image and ensure it fits ...

Enabling the option to follow a link once the script has completed execution

Is there a way to make the second link clickable only after a specific function has executed successfully? I have an EJS template with two links inside paragraphs. When the first link ("Run python") is clicked, a script is activated that takes some time to ...

Editable content within a div will reposition when there is no content present

Take a look at this example: http://jsfiddle.net/nojv18wf/ <div> <div class="display">Blah blah blah?</div> <div class="input" contenteditable="true"></div> </div> <br /><br /><br /><br /&g ...

Initiating a sequential CSS launch using JQuery

Looking for a way to create a dynamic animation using JQuery and .css? This code will rotate letters left, then right, then left, then right again while moving up. $('.envelope').click(function() { $(this).find('.list') .animat ...

PHP - display the modified page with the updates applied

I currently have an HTML page where users can input information and submit a form to change database information. Typically, the submit button calls a PHP file on the server to process the data. However, I am looking for a way for this PHP file to return t ...

What are the steps to make a unique and eye-catching text underline animation?

I'm encountering an issue while attempting to create a hover animation for an <a> tag with an underline effect, similar to the example showcased on this particular webpage. Even though the tutorial is readily available, my implementation seems t ...

Employing ngModel in an option dropdown

I am having trouble passing an attribute from an API call to a submit function. I suspect it might have something to do with either the option select or how the input is being formatted. Encountering the error Error: No value accessor for form control wit ...

CSS: The enigma of :nth-child - what eludes my understanding?

I have 2 divs which are similar to 2 td's in a table. My goal is to have 2 red divs, followed by 2 blue divs and so on. However, my current code doesn't seem to be working. Can someone point out what I am missing: <style> .irow :nth-child( ...

CSS failing to acknowledge specified div background

After successfully configuring the featured-top and footer elements in my CSS, I encountered an issue with a persistent white line appearing between them. Despite inspecting the elements in Google Chrome, I couldn't identify the source of this problem ...

The CSS form appears to be too large for the page

On every single one of my pages, the content fits perfectly within the body: However, when I have forms on the page, they extend beyond the footer and the body doesn't resize accordingly: Where could the issue be coming from? ...