Creating a two-column image gallery inside a div:

I need to organize a group of thumbnails into two columns with four thumbnails in each column, solely using CSS. The thumbnails are all structured as follows:

<a href="..."><img /></a>

Is it possible to achieve this layout through CSS rules?

I am utilizing XSLT to generate the list of thumbnails in Umbraco using the provided script. While I can modify the script, XSLT is not my strong suit - so any guidance on either CSS or XSLT would be greatly appreciated.

Gallery.xslt:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
<xsl:stylesheet 
    version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" 
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets">


<xsl:output method="xml" omit-xml-declaration="yes"/>

<xsl:param name="currentPage"/>

 <xsl:variable name="mediaFolderId" select="number($currentPage/mediaFolderId)" />
    <xsl:variable name="thumbWidth" select="number(58)" />
    <xsl:variable name="thumbHeight" select="number(58)" />
    <xsl:variable name="imageW" select="number(300)" />
    <xsl:variable name="imageH" select="number(300)" /> 
        <xsl:variable name="i" select="number(-1)" />

    <xsl:template match="/">

        <!-- Displays all images from a folder in the Media Library -->

        <xsl:if test="number($mediaFolderId)">

        <ul class="bxslider">           
            <xsl:for-each select="umbraco.library:GetMedia($mediaFolderId, true())/Image">
                <xsl:if test="umbracoFile !=''">
                    <li><a href="{umbracoFile}" title="{@nodeName}" class="gal"><img src="/imageGen.ashx?image={umbraco.library:UrlEncode(umbracoFile)}&amp;width={$imageW}&amp;height={$imageH}" width="{$imageW}" height="{$imageH}" alt="{@nodeName}" title="{@nodeName}" /></a></li>
                </xsl:if>
            </xsl:for-each>
        </ul>
        <div id="bx-pager">         
            <xsl:for-each select="umbraco.library:GetMedia($mediaFolderId, true())/Image">
                <xsl:if test="umbracoFile !=''">
                    <xsl:call-template name="section" />            
                </xsl:if>
            </xsl:for-each>         
        </div>
        </xsl:if>

</xsl:template>
        <xsl:template name="section">           
            <a href="javascript:void(0);" data-slide-index="{0 + count(preceding-sibling::Image)}"><img src="/imageGen.ashx?image={umbraco.library:UrlEncode(umbracoFile)}&amp;width={$thumbWidth}&amp;height={$thumbHeight}&amp;=t" width="{$thumbWidth}" height="{$thumbHeight}" alt="{@nodeName}" title="{@nodeName}" /></a>             
        </xsl:template>
</xsl:stylesheet>

Answer №1

If your column size doesn't fit your needs, you can easily adjust it using float and display properties:

Check out the DEMO here

For single images:

img:nth-child(odd) {
  float:left;
  clear:left;
  margin-bottom:0.2em;
}
img {
  display:block;
    margin:0 0.2em 0.2em 0;
}

When dealing with links, the concept remains the same - make sure to style them accordingly by setting their size or changing their display property from block to table.

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 best way to change the default info color in bootstrap 5.0 to match the info color in bootstrap 3?

Back in the days of bootstrap 3, the sweet info color was #d9edf7. Whenever you used bg-info or alert-info, that trusty old background color was #d9edf7 like clockwork. I'm on a mission to make bootstrap 5.0 behave the same way with the info color. S ...

Is it possible to maintain child divs in a single line?

Despite trying numerous recommendations (many involving white-space:nowrap and display:inline-block), I have been unsuccessful in keeping these child divs on a single line with horizontal scrolling. This is my code: <div id="list"> < ...

Integrating foundation-sites with webpack, unable to apply styles

Delving into the world of webpack for the first time has been quite a daunting experience! I'm attempting to set up the foundation for sites, but I feel completely lost when it comes to configuring it properly. Here is my Webpack configuration: var ...

Converting CSS specific to a particular vendor: A step-by-step

Looking for a method to adapt a CSS file containing only -moz-css-property references to include compatibility with Chrome, Safari, and other browsers. Ideally seeking a user-friendly web application that can perform this task seamlessly. ...

Sleek and versatile sidebar reaching full height

Is there a way to make my sidebar cover the full height of the screen without using position: fixed? The code I've tried doesn't seem quite right. Any tips? JSFindle: http://jsfiddle.net/Pw4FN/57/ if($(window).height() > $('#page-contai ...

Tips for modifying the icon of a div with a click event using vanilla JavaScript

My goal is to create a functionality where clicking on a title will reveal content and change the icon next to the title. The concept is to have a plus sign initially, and upon clicking, the content becomes visible and the icon changes to a minus sign. C ...

Aligning input fields vertically and horizontally within a div container

Struggling with this frustrating piece of code for hours now. I've lost nearly 2 hours trying to get it to work properly. My goal is to center an input field vertically and horizontally inside a horizontal bar. Take a look at the simplified code belo ...

Align title text to the right within the Material Design Card

I have implemented a Material Design (MDL) card to showcase numeric values in the title. However, I am facing an issue where the values are left aligned by default and I want them to be right aligned. Despite trying various styles, they are being ignored ...

Tips for defining a relative path in the base URL with AngularJS

Encountering an issue with AngularJS routes related to file paths. The folder structure is as follows: js -> Angular -> css -> Bootstrap -> index.html Routes work fine when hosted on a server like IIS. However, copying and pasting the direct ...

Error TS7053 occurs when an element is given an 'any' type because a 'string' expression is being used to index an 'Object' type

When attempting to post data directly using templateDrivenForm and retrieve data from Firebase, I encountered the following type error message. Here are the relevant parts of my code: // Posting data directly using submitButton from templateDrivenForm onC ...

Issue with Dotless MVC bundling occurring when attempting to import a specific less file multiple times

Trying to achieve a specific structure using dotless: styles/variables.less - contains all variables like this @color:green; styles/component1.less - random component specific style importing variables.less @import "variables"; body { ba ...

Assign position values to an element inside a DIV container using JavaScript, Cascading Style Sheets, and

I am currently creating some visual representations of journal issues. I am looking to showcase blocks of text using basic DIVs or other elements inside another DIV, mirroring the organization of the issue page. In order to achieve this, I need to positi ...

Bootstrap allows you to create a responsive grid

I need assistance with making my bootstrap grid responsive for multiple input search filters on mobile devices. Currently, the layout is not showing correctly on mobile phones. On desktop, the output looks fine: https://i.stack.imgur.com/bKPUv.png Howev ...

Struggling to align text to the far left within a text area using Bootstrap

When I accidentally place my cursor earlier in the text area, it starts writing from that point, leaving some unwanted spaces at the beginning. I prefer it to start from the extreme left, similar to how it behaves in input boxes. Below is the code snippet ...

I am encountering an issue with the Link tag from next/link that is throwing an error. The error message states: "React.Children.only expected to receive a single React element

Hey everyone, I've come across an issue with using next/link in my code. Every time I replace the anchor tag with the "Link" tag, I encounter an error. I've searched for a solution but haven't found one yet. Any help would be greatly appreci ...

Increase the parent height by 100% when the child element expands

I am attempting to create a full-screen website with 100% height and no scrollbar. I have a div that takes up 90% of the page height and I want to dynamically add elements inside it. However, when there are too many elements inside this div, they expand th ...

Issue with CSS styling on a content slider causing the last picture to display incorrectly

I recently updated a Content Slider and tweaked the styles to my preference. Check out the changes I made on this link. In addition, I included an extra Thumbnail Picture on the right (7th one) along with the Main Picture. Oddly enough, the Slider seems ...

What is the reason for the absence of styles in index.html when accessing the local server?

When using node.js to open the server, I encountered an issue where the styles are not displaying. Strangely, when opening index.html directly in the browser, all the styles show up correctly. What could be causing this discrepancy? index.html <!doctyp ...

site with scrolling options in various directions

Someone recently asked me if I could create a multi-directional scrolling website similar to the one found at COS, but using WordPress. At first, I assumed it might be done with Flash, but the source code suggests it could actually be more simple, possibly ...

Can a time duration be applied to the background image of a DIV element?

Is there a way to set different time spans for background images of a DIV? Has anyone tried using jQuery for this task? I'm looking to have the first image displayed for 20 seconds, then switch to the second image for 5 seconds. Is it possible to ach ...