Tips for automatically floating elements to the right or left

I am currently working on a page that displays orders dynamically generated by Flask when a customer places an order.

https://i.sstatic.net/W8f1s.png

When clicking to expand an order, everything works smoothly if the order is on the left side. However, strange behavior occurs when expanding an order located on the right side. https://i.sstatic.net/C9Saz.png

I'm trying to figure out why this happens and if there is a solution to resolve it. Here is the code snippet:

<!-- An Order -->
<div class="an-order">
  <img src="./delivery-truck.png">
  <div>
    <h5 class="">#232451</h5>
  </div>
  <h6>total: $000.00</h6>
  <div class="order-footer">
    <span>expand me</span>
    <span>!</span>
    <hr class="line">
    <!-- Additional Information -->
    <div class="additional-info">
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do 
         eiusmod tempor incididunt ut labore et dolore magna aliqua... 
         (long lorem text)
    </div><!-- /.Additional Information -->
  </div>
</div><!-- /.An Order -->
<script src="./jquery-3.3.1.min.js"></script>
<script>
  $( document ).ready(function() {
    // All orders' additional information must be toggled at first
    $(".additional-info").slideToggle(0);
    // Each order's additional information will show on click based on its 
    // $this value!
    $(".an-order").on("click", function () {
      var additionalInfo = $(this)["0"].children[3].childNodes[9]
      $(additionalInfo).slideToggle(1000);
    });
  });
</script>

Here is the CSS styling used:

.an-order {
  padding:10px;
  margin:10px;
  width: 286px;
  float: left;

  background:#f1f1f1;
  color:#666;
  border: 2px solid black;
}

.order-footer {
  padding: 0.75rem .75rem;
  display: inline-block;
  width: 90%;

  background-color: rgba(0, 0, 0, 0.05);
  border-top: 1px solid rgba(0, 0, 0, 0.125);
}

Answer №1

The issue lies in the configuration of the height and float properties of the div, causing complications. Unfortunately, a CSS-only solution may not resolve this problem.

An alternative approach would involve utilizing column-count for such a layout (Note that modifying the HTML structure may be necessary)...

...Alternatively, you could explore using jQuery libraries like

  • Masonry
  • Isotope
  • Salvattore

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 ensure that text fields remain hidden upon page load until the appropriate drop down option is chosen?

Is it possible to initially hide text fields and only reveal them when a specific drop down option is selected? The current JavaScript code somewhat achieves this, but I would like the input fields to remain hidden by default. <script language=" ...

Efficient jQuery Algorithm for Calculating Image Viewport Sizes Without Scrollbars

I am trying to create an image hover effect, but I am encountering an issue. When I hover over certain images, unwanted scrollbars appear, and I would like to find a way to prevent this from happening. It seems to be related to the viewport and calculation ...

Indent the text within a span element that is displayed as an inline block

I am in search of a solution using only CSS for the following issue. Take into account the HTML below: <p> <span>Some text</span> <span>Some text</span> </p> Both <span> elements are set as inline-block. ...

Generate a new nested div if there is already a different child present at the specified coordinates (x, y)

My goal is to add a textarea to a sidebar on the right whenever a click is made on the page. The current code I have is as follows: $('#page_to_be_clicked').click(function(e){ var offset = $(this).offset(); var comment_box_y_coord = e.pa ...

Display fixed information in a separate tab using express and ejs

I have an Express app that is running smoothly with a MongoDB backend, and it's able to render tables with data flawlessly. However, I've encountered an issue when trying to export a table from my database. The exported table looks something like ...

How can we limit the display of reCAPTCHA 2.0 to only show after a certain number of failed attempts or when

After searching around and finding no specific information on implementing recaptcha 2.0, I'm reaching out for some assistance. I'm in the process of setting up a signup/login page with multiple forms and want to enhance security by adding recap ...

Arrange images with haphazard placement

Can someone guide me on creating a block of images when working with an array of random items? https://i.sstatic.net/qEcQy.png ...

Console output shows that the function results in undefined

When I pass a string parameter to a function, I expect the console to display "reff", but it is showing "undefined" instead. Here is the code snippet: var _ref; function foo(_ref='reff') { var bar = _ref.bar; return console.log(bar); } foo ...

Hide the paragraph element when the navigation link is being hovered over

Is there a way to hide a <p> element when hovering over a link? My website is built with Drupal and uses the Superfish module for the navigation bar. When I hover over the links, a secondary nav bar drops down. I want the slogan of the website to di ...

Sending parameters dynamically in AJAX chosen

I am completely new to the world of Jquery and need some help. Here are the codes I currently have: $target.ajaxChosen({ type: 'GET', url: '<s:url action="getFilterValueJSON" namespace="/cMIS/timetable"></s:url> ...

The issue with the data backdrop not functioning properly in Angular 6 is ongoing and

My issue lies with the data-backdrop attribute in my Bootstrap 4 modal. It does not function as expected. The intended behavior is for the modal to close when clicked outside of it, but this is not happening. I am using Angular 6: I have attempted setting ...

How to prevent selection of specific months in Bootstrap datepicker

I've been attempting to disable specific months in a datepicker using the datesDisabled option. Even though the documentation states that it should work by passing an array of strings, I haven't been able to make it function properly. Here' ...

What is the best way to insert text in a TextBox on a webpage using a WebBrowser and then proceed to click a Button on the same site?

Testing out a group link that I recently opened. Check out my group here Here is the code snippet within the constructor: webBrowser1.ScriptErrorsSuppressed = true; webBrowser1.Navigate("https://www.facebook.com/groups/993071237423013/"); Next, in ...

Retrieving data from Mysql based on selected checkboxes in HTML

Is it possible to get multiple return values for checkboxes? Currently, the code provided only echoes a single value even when multiple checkboxes are selected. How can this be resolved? $q2 = mysqli_query($conn,"SELECT product_img_url FROM temp_img"); ...

Trigger a JavaScript/jQuery event using code instead of user interaction

Exploring the source code of a website has sparked my curiosity about how to programmatically activate the ajax autocomplete feature on a specific text box. Here is the snippet of relevant code that I have been examining: html: <div class="input-text ...

The functionality of Bootstrap Scrollspy seems to be malfunctioning as it fails to navigate or scroll through the content

I've been struggling to get ScrollSpy up and running. I have a fixed menu on the left side that sticks as the user scrolls down, but for some reason, ScrollSpy just won't cooperate. I've tried numerous methods to make it work, even with the ...

Making a jquery ajax call to send a request to a specific domain

Is it possible to send a request using AJAX? Can we use the domain name along with the file in URL property of AJAX? If not, what should be used instead? $.ajax({ url:'http://www.domain.com/myfile.php', }) Thank you. https://i.stack.imgur. ...

Template ID not found

I've been experimenting with integrating Knockout.js to merge an HTML view on a web page with HTML code stored in a database table. Although the database code is successfully appended to the DOM, Knockout seems unable to locate the specified ID. Here ...

Obtain base64 representation of a file using plupload file uploader

I am currently utilizing the Plupload Uploader. My objective is to convert the uploaded file to base64 and transmit it within a SOAP envelope. I have successfully created the envelope and utilized my web-service. However, I am wondering how I can retrieve ...

CSS grid is organizing itself neatly on larger screens

I'm currently facing an issue with displaying a CSS grid on my page. When viewed on desktop, the grid appears stacked up instead of in separate columns. I've tried various methods like dividing it into 4 columns and using spans for width but noth ...