如何在 JQuery 中使用 Sortable 对 div 进行水平排序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2544143/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to horizontally sort divs using Sortable in JQuery
提问by Tahir Akram
I am looking to sort my divs horizontally in a container div.
I found an exampleon JQuery website but that is vertical sorting. I want it horizontal.
我希望在容器 div 中水平排序我的 div。
我在 JQuery 网站上找到了一个例子,但那是垂直排序。我想要水平的。
I want to do it sorting in #sortable
<div>
.
我想在#sortable
<div>
.
Will you please guide me how can I convert this vertical sorting in horizontal manner.
请指导我如何以水平方式转换这种垂直排序。
CSS
CSS
<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>
JavaScript
JavaScript
<script type="text/javascript">
$(function() {
$("#sortable").sortable({
revert: true
});
});
</script>
HTML
HTML
<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>
回答by Nick Craver
You can just add this CSS style:
你可以添加这个 CSS 样式:
#sortable>div { float: left; }
And they'll be horizontal and still sortable. You can see a demo of it in action here.
它们将是水平的并且仍然可以排序。 你可以在这里看到它的演示。
回答by kdelmonte
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...
虽然float:left
有效,但在这里我宁愿display:inline-table
用于 div,这样您就不会丢失 div 的音量...
回答by osselosse
just add to your CSS : display: inline-block;
只需添加到您的 CSS 中: display: inline-block;