What is the best way to make an element "jump to the top" when the parent element has reached its maximum height?

I have a parent div containing 6 child divs. The height of the internal divs changes dynamically based on the data. The outer div has a fixed height set. I want the internal divs to move to a new column inside the parent div when they no longer fit in terms of height.

Here is a brief snippet illustrating my situation:

 #outer {
  min-width: 100px;
  width: 100px;
  max-width: 200px;
  height: 96px;
  max-height: 96px;
  background-color: #ddd;
  position: relative;
}

#outer div {
  width: 100px;
  height: 30px;
  border: 1px solid black;
  text-align: center;
}
  <div id="outer">
    <div>Item1</div>
    <div>Item2</div>
    <div>Item3</div>
    <div>Item4</div>
    <div>Item5</div>
    <div>Item6</div>
  </div>

And here is how I would like it to be displayed:

 #outer {
 float:left;
  min-width: 100px;
  width: 100px;
  max-width: 200px;
  height: 96px;
  max-height: 96px;
  background-color: #ddd;
  position: relative;

}

#outer div {
  width: 100px;
  height: 30px;
  border: 1px solid black;
  text-align: center;
}
  <div id="outer">
    <div>Item1</div>
    <div>Item2</div>
   <div>Item3</div>
   </div>
     <div id="outer">
   <div>Item4</div>
   <div>Item5</div>
   <div>Item6</div>
  </div>

Any suggestions are welcome!

Thank you

Answer №1

To tackle this issue, consider using flex wrapping.

[When working with bootstrap, there's no need to duplicate the CSS written in '*' selector]

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

#outer {
    display: flex;
    flex-wrap: wrap;
    width: 200px;
    height: 90px;
    background-color: #ddd;
    position: relative;
}
  
#outer div {
    width: 100px;
    height: 30px;
    border: 1px solid black;
    text-align: center;
}
<div id="outer">
    <div>Item1</div>
    <div>Item2</div>
    <div>Item3</div>
    <div>Item4</div>
    <div>Item5</div>
    <div>Item6</div>
</div>

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

Adding a modified (id) content inline template element to another element: A step-by-step guide

In the given scenario, I am looking to achieve a function where each time the add button is clicked, the content within the template div should be appended to the element with the landingzone class. Additionally, it is important that the NEWID changes for ...

Retrieving data using a class in an AJAX form submission

I am attempting to use AJAX to submit an HTML form. Here is my HTML: <form class="lyrics"> <input type="text" value="" id="song" name="song"> <button type="submit" class="btn btn-info lirik">lyrics</button> </form> ...

Completely shrink the middle row first when resizing the browser before shrinking the other rows

Utilizing a simple three row structure: <div class="EditorHeaderWrapper"> <h1>Title</h1> </div> <div class="EditorMainRowWrapper"> // Content of the main row goes here </div> <div class="EditorFooterWrapper"> ...

Delivering static HTML content on Google App Engine using Python

I'm struggling to load static .html pages for my Python application. Every time I try to access a link like index.html, the page remains blank and the server log shows a 404 error. This issue persists with other static .html files such as about.html. ...

Incorporate jQuery's reload function inside another function with the syntax $(function

I have a JavaScript application that loads when the page is loaded. var lang = 'en'; i18n.setLng(lang, function(err, t) { /* loading done */console.log('loaded ' + lang) }); $(function() { Mirador({ "id": "vi ...

kineticjs equivalent to jquery sortable

Could someone recommend a kineticjs plugin or script that works with jquery's "sortable" function? I am trying to create a list of shapes where I can drag and drop them, and when one element moves, the other elements shift into place. ...

Update the session's data

Situation : I am working on a basic php form for calculations and pricing. I have set up the add, edit, and delete functions using a switch statement. Within my session, data is stored using $_POST. Issue with Edit Function : if (isset($_POST[&apo ...

Utilize JavaScript to create a toggle menu feature that can target multiple variables with just one click function

I am attempting to create a collapsing menu on click functionality with additional modifications. One of the changes I would like to implement is altering the background of another element when the menu collapses. Currently, the code snippet only works fo ...

Retrieve the Vue.js JavaScript file from the designated static directory

This is my inaugural attempt at creating a web application, so I am venturing into Vue.js Javascript programming as a newcomer. I have chosen to work with the Beagle Bootstrap template. Within my Static folder, I have a file named app-charts-morris.js whi ...

Close the modal when the submit button is clicked and the Ajax request is successful

I have encountered a similar issue to others on StackOverflow, but I am struggling to implement the suggested solutions in my specific case. Currently, I have a modal in my view: <div id="createFolderModal" class="modal"> <div class="modal-dialo ...

"Using jQuery to locate an image's title attribute and switch the class of the corresponding list item

I am working on a project that involves a list of images with title attributes and a separate list of names. My goal is to toggle a CSS class on a list item in the name list when hovering over an image. To do this, I need to extract the value of the curr ...

Choosing from a dropdown menu by pressing keys

When I press the first letter of an option in my dropdown list, it works fine. However, if I try to press two, three, or four letters consecutively, the control vanishes. For example, if the option is 'Jquery' and I press J only, it works but pre ...

Retrieving a specific attribute pair from a JSON object

Currently, I am trying to retrieve the temperature data and display it on my webpage. Since these are objects with no specific order, I am struggling to understand how to access them without using an index. { "response": { "version": "0.1", "termsofServic ...

Can someone explain how to implement an onclick event for a div element inside an iframe using jquery or javascript?

Understanding the HTML Structure <iframe src="#" scrolling="no" id="gallery-frame"> <div class="gv_filmstrip"> <div class="gv_frame"> <div class="gv_thumbnail current"> <img src="images/grandstand-padang-right/1.jpg"> </d ...

Struggling with the installation of SimpLESS

I encountered an issue while attempting to install SimpLESS on my Windows 7 64bit PC. Upon running the installer, I was met with an error message stating: "Could not query info: Invalid HTTP Status Code (403)". Despite my efforts to search for a solution o ...

Utilizing Ajax to dynamically populate table columns

I have an HTML table with specific labels and styles. I am looking for a way to update the table by using the unique 'id' of each row/element and populate the data using Ajax. Can anyone provide a solution or suggestion? <table border="0" ...

Tips for alternating the color of <li> or <tr> elements consecutively

Looking to alternate the background color of li or tr elements consecutively. Please note: A static class will not work as I need to call this in a while loop. The desired output should look like: <li>line1</li> //white background <li> ...

The integration of Angular CLI with SCSS is no longer a separate process -

It seems like I might be overlooking something very straightforward here. After a fresh installation of angular-cli, I created a new website with SCSS. I input the SCSS in the global style.scss as well as some in a component SCSS file. However, when I se ...

JavaScript code encounters difficulties parsing HTML source

I'm attempting to reconstruct the WhateverOrigin service, which can be found at this link: Nevertheless, when I try running it in my web browser, this code that functioned perfectly with WhateverOrigin no longer functions properly with my imitation s ...

The functionality of two-way binding in a distinct controller is not functioning properly when integrated with angular-wizard

I've been working hard to integrate this amazing wizard controller into my project: However, I've hit a roadblock with two-way binding not functioning as expected outside of the <section> attribute: http://plnkr.co/edit/N2lFrBRmRqPkHhUBfn ...