Dynamic image gallery with a flexible layout and interactive scrollbar using Flexbox

I'm looking to incorporate a scrolling image gallery into a flexbox layout so that as the browser page size changes, the gallery will scale according to the flex-grow index. My goal is to ensure all images remain accessible via a scrollbar without using absolute units. Despite attempting various methods recommended on forums and websites, I have been unsuccessful in getting the gallery to function within my flexbox layout. Any suggestions would be greatly appreciated.

Example1: The desired behavior of the image gallery when the browser page size is smaller than the displayed images:

<!DOCTYPE html>
<html>
    <head>
        <style>
            html, body {
                background-color: dimgray;
                height: 100%;
                overflow: hidden;
                margin: 0;
                padding: 0;
            }
            .gallery {
                flex: 1 1 50%;
                white-space: nowrap;
                overflow: scroll;
            }
        </style>
    </head>
    <body>
        <div class="gallery">
            <img src="https://via.placeholder.com/100x100" alt="Tile1">
            <img src="https://via.placeholder.com/100x100" alt="Tile2">
            <img src="https://via.placeholder.com/100x100" alt="Tile3">
            <img src="https://via.placeholder.com/100x100" alt="Tile4">
                                ...
        </div>
    </body>
</html>

Example2: Flexbox layout where the image gallery should be integrated:

<!DOCTYPE html>
<html>
    <head>
        <style>
            html, body {
                background-color: dimgray;
                height: 100%;
                overflow: hidden;
                margin: 0;
                padding: 0;
            }
            .container {
                display: flex;
                flex-direction: column;
                height: 100%;
            }
            /************************/
            .column {
                display: flex;
                flex-flow: column nowrap;
                border: 1px solid black;
                padding: 10px;
            }
            .column:nth-child(1) {
                flex: 4 0 40%;
            }
            .column:nth-child(2) {
                flex: 3 0 30%;
            }
            /************************/
            .row {
                display: flex;
                flex-direction: row;
                flex-flow: row nowrap;
            }
            .row:nth-child(1) {
                flex: 1;
            }
            /************************/
            .sub-row {
                border-bottom: 1px solid black;
                padding: 5px 0;
                color: white;
            }
            .sub-row:last-child {
                border-bottom: none;
            }
            /************************/
            #row-middle-col-left1,
            #row-middle-col-left2 {
                flex-grow: 4;
            }
            #row-middle-col-right1 {
                flex-grow: 10;
            }
            #row-middle-col-right2 {
                /*max-width: 800px;*/
            }
            /************************/
            .gallery {
                flex: 1 1 50%;
                white-space: nowrap;
                overflow-x: scroll;
                min-width: 0;
            }
        </style>
    </head>
    <body>
        <div class="container">
            <div class="row" id="row-middle">
                <div class="column" id="row-middle-col-middle">
                    <div class="sub-row" id="row-middle-col-left1">M1</div>
                    <div class="sub-row" id="row-middle-col-left2">M2</div>
                </div>
                <div class="column" id="row-middle-col-right">
                    <div class="sub-row" id="row-middle-col-right1">R1</div>
                    <div class="sub-row" id="row-middle-col-right2">R2
                        <div class="gallery">
                            <img src="https://via.placeholder.com/100x100" alt="Image1">
                            <img src="https://via.placeholder.com/100x100" alt="Image2">
                            <img src="https://via.placeholder.com/100x100" alt="Image3">
                            <img src="https://via.placeholder.com/100x100" alt="Image4">
                                            ...
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </body>
</html>

Answer №1

When looking for a solution, I came up with this approach: I fixed the size of the gallery and then deducted it from the flex-basis:

#row-middle-col-right2 {
    display: inline-flex;
    flex-flow: row nowrap;
    flex: 1 1 (10% - 500px);
    overflow-x: scroll;
}
.gallery {
    display: flex;
    flex-flow: row nowrap;
    width: 500px;
}

The complete code is as follows:

<!DOCTYPE html>
<html>
    <head>
        <style>
            HTML, body {
                background-color: dimgray;
                overflow: hidden;
                height: 100%;
                width: 100%;
                margin: 0px;
                padding: 0px;
            }
            .container {
                display: inline-flex;
                height: 100%;
                width: 100%;
            }
            .column {
                display: inline-flex;
                flex-flow: column nowrap;
                border: 1px solid black;
                padding: 10px;
            }
            .column:nth-child(1) {
                flex: 2 2 20%;
            }
            .column:nth-child(2) {
                flex: 3 3 30%;
            }
            .row {
                display: inline-flex;
                flex-flow: row nowrap;
            }
            .row:nth-child(1) {
                flex: 1 1 100%;
            }
            .sub-row {
                display: inline-flex;
                flex-flow: row nowrap;
                border-bottom: 1px solid black;
            }
            .sub-row:last-child {
                border-bottom: none;
            }
            #row-middle-col-left1,
            #row-middle-col-left2 {
                display: flex;
                flex: 2 2 20%;
                flex-flow: row nowrap;
            }
            #row-middle-col-right1 {
                display: flex;
                flex-flow: row nowrap;
                flex: 6 6 60%;
            }
            #row-middle-col-right2 {
                display: inline-flex;
                flex-flow: row nowrap;
                flex: 1 1 (10% - 500px);
                overflow-x: scroll;
            }
            .gallery {
                display: flex;
                flex-flow: row nowrap;
                width: 500px;
            }

            .gallery img {
                white-space: nowrap;
                padding: 10px;
            }
        </style>
    </head>
    <body>
        <!-- Not working like expected-->               
        <div class="container">
            <div class="row" id="row-middle">
                <div class="column" id="row-middle-col-middle">
                    <div class="sub-row" id="row-middle-col-left1">M1</div>
                    <div class="sub-row" id="row-middle-col-left2">M2</div>
                </div>
                <div class="column" id="row-middle-col-right">
                    <div class="sub-row" id="row-middle-col-right1">R1</div>
                    <div class="sub-row" id="row-middle-col-right2">R2
                        <div class="gallery">
                            <img src="https://via.placeholder.com/100x100" alt="Image1">
                            <img src="https://via.placeholder.com/100x100" alt="Image2">
                            <img src="https://via.placeholder.com/100x100" alt="Image3">
                            <img src="https://via.placeholder.com/100x100" alt="Image4">
                            <img src="https://via.placeholder.com/100x100" alt="Image5">
                            <img src="https://via.placeholder.com/100x100" alt="Image6">
                            <img src="https://via.placeholder.com/100x100" alt="Image7">
                            <img src="https://via.placeholder.com/100x100" alt="Image8">
                            <img src="https://via.placeholder.com/100x100" alt="Image9">
                            <img src="https://via.placeholder.com/100x100" alt="Image10">
                            <img src="https://via.placeholder.com/100x100" alt="Image11">
                            <img src="https://via.placeholder.com/100x100" alt="Image12">
                            <img src="https://via.placeholder.com/100x100" alt="Image13">
                            <img src="https://via.placeholder.com/100x100" alt="Image14">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </body>
</html>

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

Revealing Transition Element on mouseover

My side-menu consists of icons that display text to the right upon hovering over them. I want the text to show up and the div to expand smoothly with a sliding transition, ideally without the need for additional JavaScript. Is there a way to achieve this? ...

What is the best way to make an HTML form show fields depending on certain conditions?

Initially, I created an index page containing a form with various fields. The utility was built to handle all the fields, but now there's been a change in requirements. What I need is for only the Controller Type and Test Type fields to be displayed f ...

Create a new division directly underneath the bootstrap column

Imagine having a bootstrap table like this: https://i.sstatic.net/kXHiP.jpg Now, if you want to click on a column and open a div with more details below it, is it achievable with CSS or JavaScript? https://i.sstatic.net/HIfkK.jpg I tried using the Metr ...

Error message appearing repeatedly and submit button functioning only after second click

I am currently working on my CS50 Final Project, where I am in the process of designing a web app using Flask. Specifically, this issue arises in the login/register page where I am attempting to verify if the username is already taken (through jsonify) and ...

What is the best way to spin an element around its center?

I'm faced with a challenge where I have an element that needs to be rotated using JavaScript. The rotation is currently functional, but it's rotating around points other than its center. My goal is to rotate the element around its own center. ...

Validating HTML Forms Using PHP

I am experimenting with a basic HTML login form, but I can't seem to get it to function properly. This is all new to me as I am just starting out with PHP programming. Any assistance would be greatly appreciated! <?php $correctPassword = 'ho ...

The pure css overlay does not display correctly on Chrome

Could you take a look at the link provided below (just widen the result window a bit) and let me know why there are white lines on top and on the sides of the boxes when the hover overlay is fully loaded? Even when I use a background image for those divs, ...

What is the best way to modify the underline style of a tab in Material UI?

I'm trying to customize the underline of: https://i.stack.imgur.com/J2R1z.png Currently, I am using material ui version 4.12.3 The code snippet for generating my tabs is below: function renderTabs(): JSX.Element { return ( <Tabs className={cla ...

Having trouble hiding scrollbar in specific page with React MUI v5

I attempted to conceal the vertical scrollbar on a specific page (component) only. I am utilizing "react": "^18.2.0" and "@mui/material": "5.10.4" (MUI v5). The last method I tried involved styling the parent div - ...

What is the best way to combine two sections in html/css/bootstrap?

I've been trying to create a simple webpage with a navigation bar and a section below it, but I keep running into an issue where there's unwanted white space between the nav bar and the next section in blue. Is there a way to eliminate this gap a ...

Aligning images in a table grid of 300px by 300px dimensions

I've included my code below and I am searching for the most effective method to use CSS to center an image both horizontally and vertically within a 300 by 300 pixel square. If the image is larger, it should be resized to fit within the square, while ...

Verify the visibility of the toggle, and eliminate the class if it is hidden

I have implemented two toggles in the code snippet below. I am trying to find a solution to determine if either search-open or nav-open are hidden, and if they are, then remove the no-scroll class from the body element. $(document).ready(function() { ...

Issues with hover functionality in Javascript, CSS, and HTML

Seeking assistance with my JavaScript, HTML, and CSS development, I ran into an issue while trying to create a hovering function for my webpage. Despite my efforts, the links are not displaying anything when hovered over, and the divs meant for specific ho ...

Having trouble with input event listeners in JavaScript?

I've been attempting to trigger the keyup event using EventListener for an input tag, but it doesn't seem to be working and I'm unsure why. Here is the code I have: document.getElementById("ajax").addEventListener("keyup", function() { ...

Ways to verify the presence of a Div element within an iframe

Hello everyone. I am looking to determine if the element DIV test is present within an iframe, and if it is, I want to display an alert. <html> <body> <div id="test">test</div> </body> </html> I have loaded thi ...

What could be the reason for the discrepancy between my get_token() function and the value obtained from request.META.get("CSRF_COOKIE")?

Can anyone shed light on why I'm facing this particular issue? I am currently exploring the integration of Angular 17 as a Frontend with Django as a Backend. While validating a form, I encountered an issue where the token obtained from Django does no ...

Here's a unique version: "A guide on using jQuery to dynamically adjust the background color of table

I need some assistance with changing the background color of td elements based on the th class. Specifically, I want to target all td elements under the bots class in the HTML code provided below. <table border="1" class="CSSTableGenerator" id="myTab ...

Alter the content of an HTML page depending on whether a user is logged in two times on the same page

Currently, I am in the process of developing a login system for my website. Everything seems to be functioning correctly so far. However, I have an idea to enhance the user experience by displaying their name with a 'Manage' button next to it whe ...

Invalid argument type and beyond acceptable range: file:///c:/Tools/MYScript.hta

My task involves creating a script to query an MSSQL database and display its content. However, I keep encountering the error message stating Argument wrong type and that it is out of acceptable range. Can someone please assist me with this issue? Below i ...

Set the DIV element to match the height of its container

I'm currently using this HTML code, and it's functioning correctly. However, I would like the height of the div to adjust dynamically based on the tab's content, rather than specifying a fixed height of 200px. Using a percentage value for th ...