Adaptable layout: Utilize fancybox thumbnail gallery to automatically resize and position images at the center of the wrapper, ensuring they are both vertically

I have noticed that there are many questions like mine on SO, but I haven't found a single solution that fully meets my needs.

Currently, I am utilizing the fancybox jQuery plugin to create a thumbnail gallery (non-responsive version: here - the gallery is located on the right side) of images and slideshows.

The problem arises with the thumbnail gallery - as images of varying aspect ratios are uploaded and displayed. The wrapper element (.project_gallery a - an inline anchor made to display as block) for each image has dimensions of 195x195px;

I want the images to stretch to fully occupy the div and be centered both vertically and horizontally.

If further explanation is needed regarding the last sentence above, I will provide it below:

If the width of the uploaded image is smaller than its height, the width should be set to fill the wrapper element entirely in the horizontal direction. Even if the image's width is resized to match that of the wrapper, the height of the image may still not fill the entire height of the wrapper. Thus, the image width should continue to be enlarged while maintaining the aspect ratio. Once the image's height fits the full wrapper height, but the image's width exceeds the wrapper width, the image needs to be centered within the wrapper horizontally. This might result in parts of the left and right sides of the image getting cropped or becoming invisible. The opposite effect should occur if we switch the height and width from the previously described scenario.

All these adjustments need to be done in a responsive design manner.

EDIT: The HTML mark-up for the image gallery is as follows. There will be multiple a elements serving as image wrappers and many images will be present.

<div class="project_gallery">

 <a class="fancybox" href="some_href_here" data-fancybox-group="gallery" title="Project"><img src="assets/img/projects/img_name "   class="inline_block"  alt="image project"/></a>
 ...
</div>

EDIT2: The responsive version being developed can be viewed here.

EDIT 3: If you prefer not to visit any particular site, you can simply read the question in full below:

Responsive design thumbnail gallery: how can I resize and position images with randomly varying aspect ratios at the center of identically sized wrapper divs (img_wrapper) both vertically and horizontally, making sure no part of the wrapper remains unused? Below is the HTML markup and some CSS:

HTML:

<div id="gallery">

    <div class="img_wrapper"><img src="..." alt="img"/></div> 

    //the above line will repeat as many images as are there.

    </div><!-- end of id gallery-->

CSS:

<style>
#gallery{
width:70%
}

.img_wrapper{

width:25%;
float:left;
}
</style>

Answer №1

Here are some suggestions to help you get started:

CSS

.fancybox img.inline_block{
 margin-left:0 !important;
}


.project_gallery a{
 width:100%;
}

.project_right img:first-child{
 margin-left:0;
}

.project_gallery a{
 width: 100%;
 height: 100%;
}  

You may need to consider adding !important or additional selectors to certain rules in order for them to override the existing defaults.

In terms of achieving the desired background image filling the entire div, the current background-image:cover; setting should do the job. If not, ensure your images are sufficiently large to fill the div.

You mentioned wanting this to be responsive. However, your page design doesn't seem responsive as the top slider image is hardcoded at 1050px, hindering the page from collapsing effectively. Transitioning from your current fancy box plugin to something like a lightbox might make it easier to achieve a responsive gallery.

Best of luck!

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

Refresh the database records by clicking the submit button

Is there a way to update a database by entering text into a text box and submitting it, with the data being sent to the database with a specific id? The code snippet below outlines what needs to be done, but it seems to trigger a 403 error: Access forbid ...

Ways to conceal Bootstrap-designed elements behind a fullscreen overlay

I'm attempting to create a transparent layer to conceal the entire content of my page behind it. It works fine without the Bootstrap columns, but as soon as I add the columns for responsive design, it stops working (or maybe I'm just not understa ...

Choosing a Radio Button with a Labeled Option

I'm experimenting with a method to style radio buttons by concealing them and inserting an alternative image as the background of the corresponding label (similar to this technique). In my test, I attempted to apply CSS to the radio button label: inp ...

The property cannot be set for an undefined element in Jquery UI slider tabs

There seems to be some extra space at the bottom of the slider tabs between the navigators and content. Additionally, I am facing a challenge in making the page responsive as the content size does not adjust when I resize the window. To see the changes, I ...

Utilize PHPMailer to send pre-designed email templates

Apologies for the recurring queries. I'm still struggling to find a solution to this issue. Here's my Query: I have a form that allows users to choose between predefined and custom templates. The select option determines which template is displ ...

Having issues with the background-image style not displaying correctly in the header of an

Trying to update the "background-image:" of a CSS class upon button click. JQuery: $(function() { $('button').on('click', function() { $('.masthead2').css('background-image', 'url("../img/whitehead ...

Troubleshooting Node.js and Express: Adding to array leads to displaying "[object Object]"

As a newcomer to web development and currently enrolled in a course for it, I am in the process of creating a test web server before diving into my main project. In this test scenario, my goal is to extract the value from a text block and add it to a respo ...

smoothly slides into view and playfully bounces

http://jsfiddle.net/E6cUF/ The concept involves a grey box sliding left from behind a green box after the page is fully loaded, with a slight bouncing effect if possible. Update: I created a new version inspired by modifications made by others on the jsf ...

Aligning a div within another div with an image

My current setup looks like this: HTML: <div class="wrapper"> <img src="image.jpg" /> <div class="circle"> X </div> </div> CSS: .circle { width:50px; height:50px; border-radius:50%; background: #FF0000; } ...

Select element's width decreases by 2 pixels following the application of width adjustment via jQuery

After browsing through numerous pages, I finally managed to adjust the width of my textbox and select element using jQuery 2.0. Snippet of Code from my Project: $(document).ready(function(){ $("#Text2").css('width','20 ...

adjusting label widths using jQuery mobile

I am currently using jQuery mobile to develop my user interface, however I am facing an issue with adjusting the width of my labels. Can anyone provide guidance on how to set the width of all my labels to 108px? http://jsfiddle.net/GZaqz/ Check out the c ...

objects continue to escape the confines of the container

While working on this dashboard design, I've encountered an issue where the content items jump out of their designated container. I'm using Bootstrap and have tried various solutions like setting the class to container-fluid, changing tags from & ...

Coding in HTML for the Font Awesome Plus/Minus Icon Toggle

In my role as a knowledge base manager, I primarily use Adobe RoboHelp and rarely need to utilize HTML outside of the standard editor. However, I am currently working on implementing a dropdown feature that involves changing the font awesome icon from fa-p ...

utilize dynamic variables in post-css with javascript

Question: Is it possible to dynamically set or change variables from JavaScript in post-css? I have a react component with CSS3 animations, and I want to set dynamic delays for each animation individually within each component. I've found a similar s ...

Creating a flipbook out of a PDF file

I am looking for a cost-effective solution to convert my numerous PDF files into flipbooks for easy reading. I have been unable to find a free tool for this purpose, so I am curious if it is possible to create a flipbook using only HTML, CSS, and JavaScr ...

Is there a way to center li elements evenly on mobile devices, regardless of the text length?

Take a look at these two images showcasing my website on different devices: Mobile: https://i.sstatic.net/spsYj.png Desktop: https://i.sstatic.net/AvFiN.png I have organized the content using simple ul and li tags. How can I adjust the layout so that ea ...

Deleting alternate child nodes from a DOM table while leaving other children untouched

I am currently programming in PHP and I have an HTML string that includes a table. My goal is to remove all the rows from the table, however, I am facing an issue where only every other row is being deleted. $html_string = <<<HTML <div class=&q ...

Spots on a spinning wheel

I created a simple carousel design: .index { background-color: var(--color-blue); } .container { display: flex; overflow: auto; outline: 10px solid black; flex: none; } .container.x { width: 100%; flex-flow: row nowrap; } .x.mandatory-s ...

Is there a way to generate PDF files from rrdcgi output?

I have developed an rrdcgi script to showcase system performance data through graphs. I am now seeking a way to allow users to generate PDFs on the spot, containing the current page's images and information along with header and footer details. Additi ...

Updating class after refresh of ng-repeat in AngularJS/Javascript

I am currently using angularJs in conjunction with cordova. Within my ng-repeat loop, each item has an ng-click event that stores the value of the item in an array. Additionally, when I click on an item, it toggles a class on the corresponding div (using ...