I'm struggling to resolve an issue where my list, #cardHolder, moves down when I drag an item within it. It seems to be a CSS-related problem that I can't figure out on my own. Any assistance would be greatly appreciated.
$(document).ready(function () {
$( "#cardHolder, #hand" ).sortable({
connectWith: ".connectedSortable",
receive: function(event, ui) {
var $this = $(this);
if ($this.children('li').length > 1 && $this.attr('id') != "hand") {
console.log('Only one per list!');
$(ui.sender).sortable('cancel');
}
}
}).disableSelection();
});
#trumpHolder{
border: 5px solid #ccc;
padding: 5px;
height: 250px;
width: 150px;
margin-top: 5px;
margin-bottom: 5px;
margin-left: auto;
margin-right: auto;
}
#holderWrapper{
width: 100%;
text-align: center;
}
#cardHolder {
border: 5px solid #ccc;
padding: 5px;
height: 250px;
width: 150px;
margin: 5px 5px 5px 5px;
display: inline-block;
}
#cardHolderOther{
border: 5px solid #ccc;
padding: 5px;
height: 250px;
width: 150px;
display: inline-block;
margin: 5px 5px 5px 5px;
}
.table{
display: table;
margin: 0 auto;
}
#hand {
height: 250px;
border: 5px solid #ccc;
padding: 0;
width: 100%;
clear: both;
margin-top: 5px;
}
#cardHolder li, #hand li {
margin: 7px 7px 7px 7px;
padding: 5px;
font-size: 1.2em;
width: 120px;
display: inline-block;
}
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.8.24/jquery-ui.min.js" type="text/javascript"></script>
<link href="http://code.jquery.com/ui/1.8.24/themes/blitzer/jquery-ui.css" rel="stylesheet" type="text/css" />
<script src="boerenbridge.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="boerenbridge.css">
<ul id="trumpHolder" class="connectedSortable">
</ul>
<div id="holderWrapper">
<ul id="cardHolder" class="connectedSortable">
</ul>
<ul id="cardHolderOther" class="connectedSortable">
</ul>
</div>
<div class="table">
<ul id="hand" class="connectedSortable">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
</ul>
</div>
The provided code is as follows:
HTML
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Boerenbridge</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.8.24/jquery-ui.min.js" type="text/javascript"></script>
<link href="http://code.jquery.com/ui/1.8.24/themes/blitzer/jquery-ui.css" rel="stylesheet" type="text/css" />
<script src="boerenbridge.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="boerenbridge.css">
</head>
<body>
<ul id="trumpHolder" class="connectedSortable">
</ul>
<div id="holderWrapper">
<ul id="cardHolder" class="connectedSortable">
</ul>
<ul id="cardHolderOther" class="connectedSortable">
</ul>
</div>
<div class="table">
<ul id="hand" class="connectedSortable">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
</ul>
</div>
</body>
CSS
#trumpHolder{
border: 5px solid #ccc;
padding: 5px;
height: 250px;
width: 150px;
margin-top: 5px;
margin-bottom: 5px;
margin-left: auto;
margin-right: auto;
}
#holderWrapper{
width: 100%;
text-align: center;
}
#cardHolder {
border: 5px solid #ccc;
padding: 5px;
height: 250px;
width: 150px;
margin: 5px 5px 5px 5px;
display: inline-block;
}
#cardHolderOther{
border: 5px solid #ccc;
padding: 5px;
height: 250px;
width: 150px;
display: inline-block;
margin: 5px 5px 5px 5px;
}
.table{
display: table;
margin: 0 auto;
}
#hand {
height: 250px;
border: 5px solid #ccc;
padding: 0;
width: 100%;
clear: both;
margin-top: 5px;
}
#cardHolder li, #hand li {
margin: 7px 7px 7px 7px;
padding: 5px;
font-size: 1.2em;
width: 120px;
display: inline-block;
}
Javascript/Jquery
$(document).ready(function () {
$( "#cardHolder, #hand" ).sortable({
connectWith: ".connectedSortable",
receive: function(event, ui) {
var $this = $(this);
if ($this.children('li').length > 1 && $this.attr('id') != "hand") {
console.log('Only one per list!');
$(ui.sender).sortable('cancel');
}
}
}).disableSelection();
});