Tips for preventing flex items from having equal height when collapsing

When I try to place elements from an array in a list with display flex, the height of other elements gets modified when one is collapsed.

I have attempted different display and inline placement on li elements but nothing has worked so far.

Is there a way to keep elements in a list inline and independent in height?

.dragscroll {
  display: flex;
  overflow-x: auto;
}

.rectangle-holder {
  border: 1px solid black;
}

ul {
  list-style-type: none;
}
<!DOCTYPE html>
<html>

<head>
  <title></title>
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>

<body>
  <div class="container-fluid p-0">
    <div class="row">
      <div class="col-12">
        <ul class="dragscroll">
          <li class="rectangle-holder">
            <div class="row">
              <div class="col-12">
                <p>Hello</p>
              </div>
              <div class="col-12">
                <button class="btn btn-primary" data-target="#comment1" data-toggle="collapse" type="button">Collapse</button>
              </div>
            </div>
            <div class="row">
              <div class="col-12">
                <div class="collapse" id="comment1">
                  <p>Collapsable!</p>
                </div>
              </div>
            </div>
          </li>
          
          <!-- More list items here -->

        </ul>
      </div>
    </div>
  </div>
</body>
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

</html>

Answer №1

To achieve the desired layout, include the CSS property align-items: flex-start;. This property dictates how flex items are arranged along the cross axis within the current line. Specifically, using flex-start will position the cross-start margin edge of the items at the beginning of the cross-start line.

.dragscroll {
    display: flex;
    overflow-x: auto;
    align-items: flex-start;
}

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

Tips for customizing a link element that routes to a React component

App.js: import './App.css'; import logo from './images/logo.png'; import Home from './components/Home'; import About from './components/About'; import Calculators from './components/Calculators'; import Cla ...

CSS3 Animation for Enrollment Progress Bar

https://i.sstatic.net/aYwHP.png How can I best incorporate this functionality? <div class="container"> <h2>Simple Progress Bar</h2> <div class="progress"> <div class="progress-bar" role="progressbar" aria-valuenow="70" ...

Strategies for removing duplicate vertices in geometry through Three.js updates

Currently, I am facing an issue with changing vertex positions in my mesh using three js. It appears that three js stores duplicates for each vertex in the mesh. In my specific scenario, I have 4 duplicates of a vertex, and when I modify one using mesh.g ...

How can I alter the appearance of HTML text when hovering over the enclosing div?

I want the text to change color and zoom when the cursor is near it (when the mouse enters the area of the div containing the text). Currently, I am able to change the text color only when hovering directly over it. Below is a snippet of the code. HTML: & ...

The Problem of Unspecified Return Type in Vue 3 Functions Using Typescript

Here is the code snippet I am working with: <template> <div> <ul v-if="list.length !== 0"> {{ list }} </ul> </div> </template> < ...

Execute with jQuery using Multiple Attribute Selector

I am attempting to input numeric values using a keyboard. My issue is as follows: the keyboard has an "Accept" button, and I have multiple text fields. I want to assign a different action for each text field. I attempted to use multiple attribute selector ...

A Guide to Setting the HTML Lang Attribute on a Specific Page in Next.js

I have a website built with Next.js that consists of several pages. Most of the pages are in English, but there is one page that is in French and does not have an English version. How can I assign the lang attribute to the HTML tag for this specific page ...

A dynamic 3-column layout featuring a fluid design, with the middle div expanding based on the

Sorry for the vague title, I'm struggling to explain my issue clearly, so let me elaborate. I am using flexbox to create a 3-column layout and want the middle column to expand when either or both of the side panels are collapsed. Here is a screenshot ...

Is there a way to prevent text from being automatically linked after using an <a> tag?

Whenever I attempt to input text into the div tag below, it mysteriously appears hyperlinked, even though there is no "a" tag enclosing it. HTML: <html> <head> <link href = "https://fonts.googleleapis.com/css?family=Work+Sans:3 ...

What is the best way to display an image right in the middle of the header?

My project consists of three main files - an HTML, a CSS, and a JS file. I have developed the HTML using the Bootstrap 5.1.3 framework. The issue I am facing pertains to the alignment of the clothing brand logo within the header section. Despite multiple ...

Exploring the depths of Vue.js routing through nesting

My Current Route is function route(path, view) { return { path: path, meta: meta[path], component: resolve => import(`pages/${view}View.vue`).then(resolve) } } route('/', 'Home'), route('/help', 'Help ...

Guide to implementing Vuetify tabs alongside Vue Router

I have a scenario with two Vuetify tabs in this jsfiddle, but the documentation lacks examples of using vue-router with them. After stumbling upon a helpful Medium.com post about integrating Vuetify with vue-router, I came across the following code: <d ...

Issues with the Bootstrap navbar toggle functionality

Hello there! I hope you're doing well. I've been following the Bootstrap 5 tutorial on Traversy media's YouTube channel, but I'm encountering an issue with the nav toggler. The nav is not showing up for me and I can't figure out wh ...

In what way can I modify the object in the first array when the second array includes the same object but with varying values, excluding the primary value?

This is the initial array I am working with [{"e":"24hrTicker","E":1532084622977,"s":"ETHBTC","p":"-0.00260600","P":"-4.029","w":"0.06279622", "x":"0.06465200","c":"0.06207700","Q":"0.10800000","b":"0.06207900","B":"0.58000000","a":"0.06209300", "A":" ...

The menu hover feature fails to close correctly

Hovering over the main dropdown menu expands it, thanks to CSS. I had a nested dropdown within it, but the CSS didn't work for that submenu. I had to resort to using JavaScript to make it expand on hover. However, the issue now is that the submenu doe ...

What methods can be used by the client-side to determine whether a file has been successfully downloaded or received from

When a client-side file download request is initiated, I dynamically create a form element with hidden attributes and submit it to the server via POST. During this process, I need to display a loading spinner that will be hidden once the download is comple ...

Creating a corner ribbon for a Material UI Card: A step-by-step guide

Can anyone provide pointers on incorporating a corner ribbon to a Material-UI card? Currently, I am utilizing makeStyles for styling from Material UI. ...

When the "change" event listener is added to an input element, the innerHTML is updated as the value increases but not when it decreases

My div block contains a value that I need to adjust as the input value changes. While the adjustment works when the input value increases, it does not change when the input value is decreased. It seems like there may be an oversight in my logic that I am m ...

Choosing the right framework for a web application

Currently, I am at a crossroads when it comes to deciding on the architecture of the web application I will be developing. As part of a small team, I am tasked with working on this project solo while my colleagues focus on other tasks. The front-end of th ...

Struggling to contain the image inside my div element

I'm having trouble with keeping the image inside my div element as it keeps stretching outside of it. I've tried researching for a solution but haven't been successful in finding one. Any help would be greatly appreciated! Here is the HTML/ ...