Arranging divs in a row using jQuery sortable technique

Greetings! I have been attempting to achieve horizontal sorting for two divs but have encountered a couple of issues. Firstly, the divs do not align correctly upon initial page load and secondly, while they can be dragged around, the sortable functionality is not functioning as expected.

I tried modifying the jQuery example by including a float:left property on my two div elements.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Sortable - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <style>
  #sortable { list-style-type: none; margin: 0; padding: 0; width: 60%; }
  #sortable li { margin: 0 3px 3px 3px; padding: 0.4em; padding-left: 1.5em; font-size: 1.4em; width:200px;cursor:pointer;}
  #sortable li span { position: absolute; margin-left: -1.3em; }
  </style>
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $( function() {
    $( "#myColumns" ).sortable();
    $( "#sortable" ).disableSelection();
  } );
  </script>
</head>
<body>

<ul id="myColumns">
  <li>
    <div style="border:1px solid green;height:300px;width:200px;float:left;"></div>
  </li>
  <li>
    <div style="border:1px solid red;height:300px;width:200px;float:left;"></div>
  </li>
</ul>


</body>
</html>

Do you have any suggestions or solutions?

LATEST UPDATE I decided to try using bootstrap.css and here is the revised code that incorporates nested sortables in both horizontal and vertical orientations.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Sortable - Portlets</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="bootstrap.css">
  <style>
  .myCol {
  height: 200px;
  width: 250px;
  border: 1px solid;  
  margin:20px;
  padding:10px;
  border-radius:5px;
  overflow-y:auto;
  background-color:#E6E6E6;
}

  </style>
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $(function() {
  $("#myColumns").sortable({
  handle:".handle"
  });
  $("#board1").sortable();
  $("#board2").sortable();
  $("#board3").sortable();
  $("#board4").sortable();
  $("#sortable").disableSelection();
});
  </script>
</head>
<body>

 <table>
 <tR>
 <td style="padding-top:10px;padding-left:40px;">

<div id="myColumns" class="row">
  <div class="myCol">
    <table width="100%">
    <tr>
    <td class="handle" bgcolor="gray">AA</td>
    </tR>
    <tr>
    <td>
    <ul id="board1">
      <li>A</li>
      <li>B</li>
      <li>C</li>
    </ul>
    </td>
    </tr>
    </table>
  </div>
  <div class="myCol">
  <table width="100%">
  <tr>
  <td class="handle" bgcolor="gray">BB</td>
  </tr>
  <tr>
  <td>
  <ul id="board2">
      <li>D</li>
      <li>E</li>
      <li>F</li>
    </ul>
    </td>
    </tr>
    </table>
  </div>
  <div class="myCol">
  <table width="100%">
  <tr>
  <td class="handle" bgcolor="gray">CC</td>
  </tr>
  <tr>
  <td>
  <ul id="board3">
      <li>G</li>
      <li>H</li>
      <li>I</li>
    </ul>
    </td>
    </tr>
    </table>
  </div>
  <div class="myCol">
  <table width="100%">
  <tr>
  <td class="handle" bgcolor="gray">DD</td>
  </tr>
  <tr>
  <td>
  <ul id="board4">
      <li>E</li>
      <li>F</li>
      <li>J</li>
    </ul>
    </td>
    </tr>
    </table>
  </div>
</div>

</td>
</tR>
</table>


</body>
</html>

Answer №1

To achieve this layout, you can utilize the grid system provided by Bootstrap in the following manner:

HTML

<div id="myColumns" class="row">
  <div class="col-sm-4">Col1</div>
  <div class="col-sm-4">Col2</div>
  <div class="col-sm-4">Col3</div>
</div>

JS

$(function() {
  $("#myColumns").sortable();
  $("#sortable").disableSelection();
});

View Online demo (jsFiddle)

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

jQuery - Enlarge Tree View to the level of the selected node

I am struggling to figure out how to expand the tree view up to a selected node level. If anyone has any ideas on how to accomplish this, please let me know. For instance, if we click on 'Parent d' in the 'Category list', I want to exp ...

How can you align two div elements side by side, if the first div is spanning across two lines?

I'm looking to position two divs next to each other, with the second div starting right where the first one ends. I came across a similar question on Stack Overflow, but unfortunately, it didn't have the answer I needed. <div id="wrapper"> ...

The tree expansion does not activate the CSS transition

Currently, I am in the process of creating a TreeView using only CSS and JS. My goal is to include a subtle transition effect when expanding or collapsing a node. The transition effects are successfully implemented for collapsing nodes, however, they do no ...

Tips for incorporating jQuery UI into Angular 6

No matter how many methods I have tried from StackOverflow, I cannot seem to get jquery-ui to work in my angular 6 component. Here's what I've attempted: I went ahead and ran npm install jquery jquery-ui to install both jquery and jquery-ui. ...

Second attempt at initiating Ajax request fails

My ajax/php structure works perfectly when selecting one image. However, if I click on "selecteer" to perform the same code for the second time, no images are displayed. The "ajax" page loads correctly each time. Here's the setup: Article page: Disp ...

Step-by-step guide to displaying the dropdown menu button content at the top of the page in main.html by using the frameset tag

The layout of my main.html involves displaying menu.htm and welcome.htm using frameset. One issue that arises is with the drop-down menu buttons "Admin..." and "Scheduler...". When hovering over these buttons, the dropdown content does not display properly ...

Enhance your website navigation with Bootstrap Scrolling Nav: maintain consistent section heights and highlight the active

Can you help me with an issue I'm having when clicking on the <a> link in the navigation? The anchor point seems to be misplaced as the section headline (<h2>) is not visible. Is there a way to highlight the <a> links, perhaps by add ...

Struggling to implement custom media queries in a bootstrap theme

I've customized the Twitter Bootstrap layout for my website, and everything is looking great except for the @media queries. Can anyone help me figure out what's going wrong? HTML: <section id="lessons" class="bg-black no-padding lesson-conte ...

Get the username from Parse instead of using the ObjectID

When using angular and Parse for JavaScript, I have implemented a search field where an admin can input the objectid of a user to display their details. However, I would like to modify this functionality so that the admin can enter the username instead of ...

How to position text in the center of a video using CSS

My attempt to center the name of my blog on top of a video background was not successful, even though I tried positioning it absolutely with 50% from the top. Can someone assist me in vertically and horizontally centering the text over the video? Here is ...

Deselect a checkbox by selecting a radio button with just Javascript code

Hey there! I'm currently delving into the world of pure JavaScript and could really use some guidance on a particular issue. Here's what I'm aiming to accomplish: I'd like to design a checkbox that triggers the opening of a window whe ...

Position elements flush to the left and right

Is it possible to align the text in divs so that it perfectly lines up along the edges? .name { margin: 0 0 5px 10px; font-weight: bold; font-size: 14px; } .row { margin: 0 0 5px 10px; width: 500px; justify-content: space-between; } < ...

Assistance Needed with XPATH and CSS for Selenium Automation

Can anyone assist me in finding the appropriate XPATH/CSS locator to extract text from the structure below? <div class="page-header song-wrap"> <div class="art solo-art"> <div class="meta-info"> <h1 class="page-title"> Zehnaseeb I ...

Enhancing text display and spacing in Safari versions 5 to 6, as well as Chrome

After creating an introductory animation using jquery, I noticed that it displays correctly on my machine in Firefox, Chrome, and Safari. However, when viewing it on the client's devices, the animation is not working properly. The client provided a s ...

What is the way to retrieve an array property in a typescript interface?

Imagine a scenario with three interfaces structured as follows: registration-pivot.ts export interface RegistrationPivot { THead: RegistrationPivotRow; TBody: RegistrationPivotRow[]; } registration-pivot-row.ts export interface RegistrationPivotR ...

Is there a way to adjust my input value to correspond to December of 2022?

I am working on a project where I need to set a default month and year that the user cannot modify. They should only be able to change the date in December months. Any tips on how I can achieve this? <input id="input_date" type="date&qu ...

Looking to incorporate Bootstrap Icons within Semantic UI?

I'm in need of assistance. My current project involves using Semantic UI, but there's a requirement to incorporate Bootstrap icons from . However, I'm facing difficulty copying the svg information directly into the code for the sake of reada ...

"Despite receiving a response code of 200 in Rails using jQuery ajax, the data is still

I'm attempting to display a partial in a bootstrap modal. Although I am receiving a 200 response, the JavaScript code within show.haml is not functioning correctly. I have added an alert message for testing purposes, but it does not trigger. In the GE ...

Placing an element in a fixed position behind a non-fixed element

I am facing a challenge with an element that has two children, one of them is absolutely positioned. My goal is to position this absolutely placed element behind its sibling. Unfortunately, the z-index property doesn't seem to be working as expected. ...

Exploring jQuery Mobile - What Causes an Empty State?

Using $.mobile.navigate("#test-page", {id:123}) for navigation to a secondary page seems to be successful. The transition between pages is smooth.... but the state remains empty! According to the documentation, the state should contain all necessary info ...