Divs that can be sorted are being shifted downwards within the swim lanes

JavaScript code snippet here...
CSS code snippet here...
HTML code snippet here...

Answer №1

Make sure to include vertical-align: top; in the styling of .item-box

$(function() {
      $(".swim-lane-wrapper")
        .sortable({
        axis: "Y",
        handle: ".category-box",
        connectWith: ".swim-lane-wrapper",
      })
        .disableSelection();
    });
    
    $(function() {
      $(".sortable")
        .sortable({
        connectWith: ".sortable",
      })
        .disableSelection();
    });
.swim-lane {
      display: inline-block;
      white-space: nowrap;
      float: left;
      width: 90%;
      height: 100px;
      border: 1px solid red;
    }
    
    .category-box {
      display: inline-block;
      white-space: nowrap;
      float: left;
      background-color: #FFF3CC;
      border: #DFBC6A 1px solid;
      width: 75px;
      height: 50px;
      margin: 5px;
      padding: 10px;
      font-size: 12px;
      white-space: normal;
      text-align: center;
      box-shadow: 2px 2px 2px #999;
      cursor: move;
    }
    
    .item-box {
      display: inline-block;
      vertical-align: top;
      background-color: #edf3ff;
      border: #6d71db 1px solid;
      width: 75px;
      height: 50px;
      margin: 5px;
      padding: 10px;
      font-size: 12px;
      white-space: normal;
      text-align: center;
      box-shadow: 2px 2px 2px #999;
      cursor: move;
    }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.js"></script>
<link rel="stylsheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.css">

    <div class="swim-lane-wrapper">
    
      <!-- Row One -->
      <div class="swim-lane">  
        <div class="category-box">"Category 1"</div>
        <div class="sortable">
          <div class="item-box">"Wrap this long string of text please!"</div>
          <div class="item-box">"Wrap this long string of text please!"</div>
          <div class="item-box">"Wrap this long string of text please!"</div>
        </div>
      </div>
    
      <!-- Row Two -->
      <div class="swim-lane">
        <div class="category-box">"Category 2"</div>
        <div class="sortable">
          <div class="item-box">"Wrap this long string of text please!"</div>
          <div class="item-box">"Wrap this long string of text please!"</div>
          <div class="item-box">"Wrap this long string of text please!"</div>
        </div>
      </div>
    
    </div>

Answer №2

While I agree with the answer provided by @manuel, I wanted to offer some insight into why this issue occurs. In the UI sortable feature, a temporary placeholder is utilized with the class name .ui-sortable-placeholder in place of the item being moved. This hidden element matches the dimensions of the original element and does not have any additional styling applied to it, nor is it defined in the UI CSS file.

To control the height of this invisible placeholder element and prevent neighboring elements from shifting out of place, you can use the following somewhat unconventional style:

 .ui-sortable-placeholder {
    display: inline-block;
    height: 1px;
   }

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

Splitting the string into individual characters using string.split("").map may cause layout issues on small devices

Shoutout to @pratik-wadekar for the amazing help in creating a working text animation. However, I encountered an issue when testing it on various screen sizes and mobile devices - the animated word plants breaks into pieces like PLA on one line and NTS on ...

Guide for inserting a Date variable into MySQL using JSON

In my database, there is a table with a Date field. I noticed that when I try to insert a date using Postman through the API like this: { "registerDate" : "2014-06-02" } It successfully inserts the date. However, when I attempt to do the same using ...

Ways to eliminate additional whitespace in CSS Grid styling techniques

Currently, I am utilizing material ui to establish a grid system for showcasing videos in 2 rows. While I have successfully set up the general layout, I am facing difficulty in eliminating the white space/padding between the elements. Despite trying nowrap ...

Utilizing Sequelize with Typescript for referential integrity constraints

After defining these two Sequelize models: export class Users extends Model<Users> { @HasMany(() => UserRoles) @Column({ primaryKey: true, allowNull: false, unique: true }) UserId: string; @Column({ allowNull: false, unique: tru ...

When working with AngularJS, you can enhance your application by implementing a global AJAX error handler if one has

Is there a way to set a global AJAX handler that will only be called if an error handler is not already defined for a specific AJAX call? Some of my AJAX calls need to execute certain logic if an error occurs (such as re-enabling a button), while others s ...

Interactive Bootstrap 4 button embedded within a sleek card component, complete with a dynamic click event

I am trying to create a basic card using bootstrap 4 with the following HTML code. My goal is to change the style of the card when it is clicked, but not when the buttons inside the card are clicked. Currently, clicking on the test1 button triggers both ...

Utilizing Multiple Columns for Labels in Twitter Bootstrap

In my form, I have the following code: <div class="row"> <div class="col-md-12"> <div class="form-group"> <label class="control-label"> States ...

Presentation Slider (HTML, CSS, JavaScript)

Embarking on my journey of creating webpages, I am eager to replicate the Windows 10 start UI and its browser animations. However, my lack of JavaScript knowledge presents a challenge. Any help in reviewing my code for potential issues would be greatly app ...

Undisclosed iFrame technique for uploading files - issue with nested forms

This question seems to be more related to JavaScript/jQuery/DOM rather than Rails, but it's all linked to how I integrated it in Rails. I'm currently working on allowing users to upload multiple photos while creating a new object (auction). The c ...

Implementing a dialog box pop-up from a separate React file

My journey with React is just beginning, so forgive me if this question seems basic. I have a delete icon in one of my files, and when it's clicked, I want to display a confirmation dialog box. I found an example on the official Material-UI website: h ...

Filtering a string that contains commas using another string that also contains commas

I need help with removing elements from one comma-separated string based on another. String 1: 6,2 String 2: 1,2,4,5,6,7,9,12,13 Is there a function or method that can accomplish this task for me? ...

Controlling User Roles within a React JS Application

Which libraries do you rely on for managing user roles in your React projects? All suggestions and advice are appreciated. Specifically, I am interested in controlling the visibility of different application components based on the user's role. ...

The opacity of the background should not impact the visibility of the image

I applied an opacity effect to the white background of each post with the following CSS: .post{ background: white; opacity: 0.75; border-radius: 0px 0px 6px 0px; } However, this opacity effect is also affecting the images in each post, which ...

"Enhance Your Table Design with Zebra Cells Using CSS in rich:data

How can I achieve a zebra color effect in every other cell of a rich:dataTable using CSS? <rich:dataTable value="#{uploader.files}" var="_data" id="files"> <rich:column> <f:facet name="header"> <h:outputText ...

Leveraging Github CI for TypeScript and Jest Testing

My attempts to replicate my local setup into Github CI are not successful. Even simple commands like ls are not working as expected. However, the installation of TypeScript and Jest appears to be successful locally. During the Github CI run, I see a list ...

What is the best way to make my background image adapt to different screen sizes

I am currently working on updating my webpage and facing a few challenges that I would appreciate some assistance with: One issue is that the images on my page do not adjust to the size of the browser window. As a result, when I resize the window, the i ...

Responsive Navigation Menu using Bootstrap Framework for mobile devices

I am encountering an issue with my bootstrap navbar where the button does not appear on the mobile version. This is happening while testing on my Windows Phone. Below is the code for my navbar: <nav class="navbar navbar-default navbar-fixed-top" ro ...

Adjust the size of child divs in relation to their parent divs using jQuery

I am working with 4 divs and trying to adjust the size of the inner divs in relation to the parent divs dynamically. I have added a .top class, but I'm unsure if it is necessary or beneficial. Here is my fiddle for testing purposes: http://jsfiddle.n ...

Implementing Enter key functionality to add items to a Todo list using pure DOM manipulation

var listLis=document.getElementById('list'); const addbutton=document.querySelector('.fa-plus') const inputBar=document.querySelector('.show') function showInput(e){ inputBar.classList.toggle('show') } addbutt ...

Problem with disabling dates on jQuery datepicker

After spending several days trying to solve this issue, I've decided to seek help. The problem at hand is disabling dates in my bootstrap datepicker using the following HTML code: <head> <!-- Required meta tags --> <meta charset="utf-8 ...