Sort Floated UL into columns

Developer
Size
1,950 Kb
Views
44,528

How do I make an sort floated ul into columns?

Giving list items float: left and width: 50% is an easy way to columnize the list, but then you end up with the data in rows instead of columns. This bit of javascript rearranges the list items to fix that.. What is a sort floated ul into columns? How do you make a sort floated ul into columns? This script and codes were developed by Matthew Chase on 25 July 2022, Monday.

Sort Floated UL into columns Previews

Sort Floated UL into columns - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Sort Floated UL into columns</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <ul> <li>List Item #1</li> <li>List Item #2</li> <li>List Item #3 with a long title</li> <li>List Item #4</li> <li>List Item #5</li> <li>List Item #6</li> <li>List Item #7</li> <li>List Item #8</li> <li>List Item #9</li> <li>List Item #10</li>
</ul> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Sort Floated UL into columns - Script Codes CSS Codes

UL{ width: 320px; list-style: none; margin: 0; padding: 0;
}
LI{ float: left; width: 50%;
}
LI:nth-child(2n+1){ clear: left;
}

Sort Floated UL into columns - Script Codes JS Codes

$(function(){ $("UL").each(function(){	var list = $(this),	items = list.find("LI"),	total_items = items.length,	half = Math.ceil(total_items / 2);	$("LI:lt("+half+")", list).each(function(index, li){	$(li).after(list.find("LI:eq("+(index + half)+")"));	});	});
});
Sort Floated UL into columns - Script Codes
Sort Floated UL into columns - Script Codes
Home Page Home
Developer Matthew Chase
Username antishow
Uploaded July 25, 2022
Rating 3
Size 1,950 Kb
Views 44,528
Do you need developer help for Sort Floated UL into columns?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Matthew Chase (antishow) Script Codes
Create amazing art & images with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!