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

What is the process for mediating a SWF-Flash file with a PHP mediating, also known as an HTTP-Pseudostreaming script?

I am currently developing a mini context media platform that utilizes HTTP Pseudostreaming. This involves using a PHP script to manage the media file, ensuring proper access and linking to the correct directory. Below are the key components of my code: // ...

Incorporate an ASP table within an ASP table to enhance data organization and presentation

Is it possible to create a dynamic ASP.NET table structure similar to the one demonstrated below by nesting tables inside table cells? <table> <tr> <td>[Image]</td> <td> <table> <tr> ...

Issues with Bootstrap's hamburger menu not functioning properly when clicked

Can't seem to get my hamburger button working. I've followed the bootstrap documentation and ensured that Bootstrap and jQuery are in the correct order, but still no luck. Any suggestions on what could be causing this issue? Are my links misplace ...

PHP Ajax not updating variable as expected

Apologies for the repetitive questions, but I have tried numerous solutions and cannot seem to figure out why this particular one is not working. I am invoking ajax through a click function, but I am unable to retrieve the jList value and update the variab ...

Updating the value of a rails parameter with JavaScript

I am trying to enhance my search form by pre-populating the fields with the "last searched values" when a user submits a search. The search form and results are displayed on the same page, and if there is no previous search, the fields should show placehol ...

Alter the class generated by ng-repeat with a click

I currently have a dynamically generated menu displayed on my website, and I am looking to apply a specific class to the active menu item based on the URL (using ngRoutes). The menu items are generated from a $scope.menu object, so my initial thought was t ...

Expanding the height of an image in a multi-select dropdown using CSS

I have an image that is included in all text fields and drop downs like so: However, when it comes to a multiple select drop down box, the image appears differently: I would like the image to display as shown above for multiple select drop downs. I atte ...

What are some ways I can customize the appearance of a canvas element?

After discovering a canvas animation, I decided to customize it for my own needs. However, due to the fact that a canvas and its shapes are not DOM elements, I am struggling to style it properly. You can view my current progress here. When you hover over ...

Exploring Angular 4's Capabilities: Navigating a Multi-Dimensional Array

I am currently working with a multi-dimensional array that has two keys, and it is structured as follows: user: any = {}; // The index is incremented within a for loop to add values to the user object (this part is functioning correctly) this.user[index++ ...

Interactive HTML and PHP form designed to compute and display the result of a straightforward mathematical equation

I'm looking to add a dynamic HTML/php form on my webpage that can solve the following formula instantly without any page refresh. I am confused about the best approach and the code required to make it happen. The formula I want to implement is as fol ...

What is the best way to create a fixed positioning for a div within a Material-UI table container?

When using the Material UI Table, I encountered an issue with applying the sticky property. The table itself works fine, but I also have a button inside the TableContainer that should be sticky alongside the table head. I attempted to achieve this by using ...

Why is the camera access permission dialog not showing up in the WeChat app?

Why is it that when I attempt to open the following links for the first time, Chrome asks for camera permission, but when I access them through WeChat's in-app browser, the camera permission dialog does not appear? Can someone shed some light on this ...

Using JavaScript values retrieved from a database to dynamically adjust the options in the second dropdown menu based on the selection made in the

I am currently working on a feature that involves populating two dropdown menus with values from a database. The idea is that when an option is selected in the first dropdown, the second dropdown should dynamically display relevant values based on that s ...

Adjusting specific sections of a container in real-time

Fiddle: https://jsfiddle.net/1b81gv7q/ Sorry for the slightly cryptic title; I couldn't come up with a better way to phrase it. Imagine this scenario: there's a container with content that needs to be dynamically replaced. If I wanted to repla ...

What steps do I need to take in order to transform my standard filter form that uses a submit button, into one

Currently, there is a table of venues displayed on the index page. Users can filter these venues by area and type using a form with a submit button that triggers a page reload. After filtering, all the matched venues are shown, and the form automatically ...

Child element failing to resize along with parent container

Here is the HTML structure I have for a template.php page within my website. <!DOCTYPE html> <html lang="en"> <head> <title></title> ...... </head> <body> <div id="container"> ...

Transformation effect when hovering over an SVG polygon as it transitions between two states

const createTransitionEffect = (navLI, startCoord, endCoord) => { const changeRate = 0.1; let currentY = startCoord; const animateChange = () => { if (currentY !== endCoord) { currentY += (endCoord - startCoord) * cha ...

Maintain scrolling at the bottom with React.js

Is there a way to make a div element increase in height through an animation without extending beyond the viewable area, causing the window to automatically scroll down as the div expands? I am looking for a solution that will keep the scroll position lock ...

Load data into a table in HTML after a successful jQuery event

I'm facing an issue with populating an HTML table dynamically. Below is the structure of my HTML table: <table class="flexme" id="table" border="1"> <thead> <tr> <th width="100">Usuario</th> <th wid ...