What is the best way to extend the lower row items in a flex box to accommodate additional content when clicked?

My latest project involved designing an HTML flex-box to showcase images retrieved from an API. Here is a sneak peek of the layout: [![Preview of the flex-box layout][1]][1]

However, I am now seeking to enhance user experience by adding functionality that allows for displaying extra data when a specific div element is clicked. This will prompt the lower divs to move down, creating room for an expanded section. [![Example of creating space for additional content][2]][2]

Answer №1

Is it feasible to add a placeholder flex row beneath each specific flex data row?

I have developed a demo where you can execute this code and click on each row to determine its functionality:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>

    <style>
        ul,
        li {
            list-style: none;
            margin: 0;
            padding: 0;
        }

        .flex-box {
            width: 800px;
            display: flex;
            flex-direction: column;
        }

        .flex-box__nav {
            display: flex;
        }

        .flex-box__item {
            flex: 1;
            border: 1px solid black;
        }

        .flex-box__collapse {
            display: none;
            background: red;
        }
    </style>
    <div class="flex-box">
        <ul class="flex-box__nav">
            <li class="flex-box__item">click me
                <img src="">
            </li>
            <li class="flex-box__item">click me
                <img src="">
            </li>
            <li class="flex-box__item">click me
                <img src="">
            </li>
            <li class="flex-box__item">click me
                <img src="">
            </li>
            <li class="flex-box__item">click me
                <img src="">
            </li>
            <li class="flex-box__item">click me
                <img src="">
            </li>
        </ul>
        <div class="flex-box__collapse">
            collapsed area
        </div>
        <ul class="flex-box__nav">
            <li class="flex-box__item">click me
                <img src="">
            </li>
            <li class="flex-box__item">click me
                <img src="">
            </li>
            <li class="flex-box__item">click me
                <img src="">
            </li>
            <li class="flex-box__item">click me
                <img src="">
            </li>
            <li class="flex-box__item">click me
                <img src="">
            </li>
            <li class="flex-box__item">click me
                <img src="">
            </li>
        </ul>
        <div class="flex-box__collapse">
            collapsed area
        </div>
    </div>
    <script>
        function clickHanlder() {
            var isCollapse = true;
            return function () {
                this.nextSibling.nextSibling.style.display = isCollapse ? "block" : "none";
                isCollapse = !isCollapse;
            }
        }

        document.querySelectorAll(".flex-box__nav").forEach(function (val) {
            val.onclick = clickHanlder();
        });
    </script>
</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

Slideshow not displaying properly after an Ajax request due to CSS not being applied

My goal is to dynamically load data when reaching the bottom of a page using the onScroll event handler. The data to be loaded mainly consists of slideshows and, behind each one, within a separate div, there is an iframe with embedded vimeo content. Initi ...

What could be causing my Bootstrap navbar menu item to move to the line beneath it when there is centered text?

I've implemented a basic Bootstrap navbar from the example provided on the Bootstrap website at . However, when I tried to add custom text to the center of the navbar, it caused the "Contact Us" menu item to break onto two lines instead of staying on ...

What are some creative ways to customize and animate the cursor or caret within an input field?

Just to clarify, I am working with React and Material-UI. I have a task at hand where I need to modify the appearance of the caret within an input element by adding an animation to it. I have managed to change its color using caret-color and set a default ...

How can I transform an HTML element into a textarea using CSS or JavaScript?

While browsing a webpage, I discovered a <div> element with the class .plainMail and I want to find a way to easily select all its text by simply pressing Ctrl+A. Currently using Firefox 22, I am considering converting the div.plainMail into a texta ...

react-scripts: command missing within the React application

While running my react-app on localhost, an unexpected error occurred. Even though I have installed all the necessary dependencies using npm install, it seems to be unable to locate the react-scripts command for some unknown reason. https://i.sstatic.net/ ...

Constructing the necessary gulp configuration file

When using Gulp and Gulp-sass, with the use of 'gulp.watch', how can I retrieve the directory name of the modified item on the watchlist in order to compile the sass to css? Currently, the setup only compiles the sass files from theme 1. If ther ...

Tables that adapt to different screen sizes, displaying perfectly on desktop but with slight variations on mobile devices

I recently experimented with a demo to enhance the performance of tables on my website in development. The demo worked flawlessly on my desktop when I resized using a responsive tester extension for Chrome: https://i.stack.imgur.com/KzFiR.jpg However, u ...

When the CSS style sheet is not embedded within the HTML document, it fails

I'm facing an issue while trying to apply currency formatting to an HTML table in order to have it display correctly when opened in Excel. Initially, I tried doing this inline and it worked fine, like so: <td style="mso-number-format:$\##&bso ...

Tips for showing various tooltip text when iterating through a list?

I am currently working on a project where I am looping through a list and attempting to assign different tooltip text to various icons. However, I am struggling with the implementation. Here is a snippet of my code: <React.Fragment key={sv.key ...

Retrieving Information from Website Components in JavaFX Web View

I am currently developing a Java FX program that loads a folder containing HTML/CSS/JS files with 3 different websites. While the websites are displaying correctly in the webview, I am looking for a way to capture user interactions, such as checkbox selec ...

Express/NodeJS encountering a CORS problem, causing services to be inaccessible in Internet Explorer

Currently, I am working on a REST-based service implemented in Express/NodeJS. The code includes CORS (Cross Origin Resource Sharing) implementation to allow services to be consumed from browsers like Chrome and Firefox. However, there seems to be an issue ...

ACF alternating number repeater

I want to create a two-column layout using ACF repeater fields, where the content alternates between left and right columns based on whether the row is even or odd. Here's how the output will be structured: Row 1: Image (left column), Description (r ...

Determine if a specific identifier is already present using Javascript or Jquery

Is there a way to determine if an html tag with its specific id is present more than once in the code? This is my pseudocode for checking: if($('#myId').length > 1) { // It exists twice } ...

The type 'Navigator' does not have the property 'userAgentData' in its definition

Since I'm looking to minimize the information provided by navigator.userAgent, I decided to migrate to User-Agent Client Hints. However, I've encountered an error while attempting to do so: https://i.stack.imgur.com/lgIl7.png Could someone plea ...

Not enough resources error in ajax code for live update clock functionality

Recently, I developed a real-time clock that updates every second. Surprisingly, when I tested it on my local environment, everything worked perfectly without any errors. However, the situation drastically changed when I decided to upload it to my web host ...

Using a Hook inside a React function is not possible

I encountered an error message known as the "invalid hook call error" while using the useEffect hook in my code. According to the documentation, this issue usually arises due to either a version mismatch or incorrect function calls. Could someone kindly r ...

Display loading images using the Bxslider plugin

Currently, I have implemented a Bxslider on my website with the following HTML markup: <div class="slide"> <a target="_blank" href="#"><img src="image.jpg"/></a> </div> <div class="slide"> <a target="_blank" href= ...

Responsive issue identified with Bootstrap navbar hamburger menu upon clicking

My website has an issue on mobile where the hamburger menu appears but doesn't respond when clicked. I'm unsure what's causing this problem in my code. <nav class="navbar navbar-expand-lg navbar-light bg-light"> <a ...

Obtain a numerical output from a selection of numbers

I am facing a simple problem that I can't solve due to my lack of knowledge and have not been able to find any solution online. What I want to achieve is: Create a "value 1" from an array of integers. Generate a random "value 2". Check if the rando ...

What is the best way to incorporate a sliding effect into my cookie form?

I created a cookie consent form for my website and I'm looking to include a sliding effect when it first appears and when it disappears after the button is clicked. How can I implement this sliding effect into the form? Here's the HTML, CSS, and ...