I am looking to sort my divs horizontally in a container div.
I found an example on JQuery website but that is vertical sorting. I want it horizontal.
I want to do it sorting in #sortable
<div>
.
Will you please guide me how can I convert this vertical sorting in horizontal manner.
<style type="text/css">
#draggable1 { width: 150px; height: 35px; padding: 0.5em; }
#draggable2 { width: 150px; height: 35px; padding: 0.5em; }
#draggable3 { width: 150px; height: 35px; padding: 0.5em; }
#sortable { width: 700px; height: 35px; padding: 0.5em; }
</style>
<script type="text/javascript">
$(function() {
$("#sortable").sortable({
revert: true
});
});
</script>
<div class="demo">
<div id="sortable" class="ui-state-default">
<div id = "draggable1" class="ui-state-default">Home</div>
<div id = "draggable2" class="ui-state-default">Contact Us</div>
<div id = "draggable3" class="ui-state-default">FAQs</div>
</div>
</div>
You can just add this CSS style:
#sortable>div { float: left; }
And they'll be horizontal and still sortable. You can see a demo of it in action here.
Although float:left
works, here I would rather use display:inline-table
for the divs, so that you don't lose the volume of your divs...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With