I need to arrange a list of images in ascending order based on the index
attribute using CSS. The challenge is that the index values will change dynamically and new images will be added through Ajax, so I want them to automatically update in the correct order without any manual intervention.
.img_container {
width: 100%;
border: 2px black solid;
}
.img_container img {
margin-bottom: 5px;
margin-right: 5px;
}
<div class="img_container">
<img src="https://dummyimage.com/100x150/000000/ffffff&text=1" index="1">
<img src="https://dummyimage.com/100x150/000000/ffffff&text=10" index="10">
<img src="https://dummyimage.com/110x150/000000/ffffff&text=11" index="11">
<img src="https://dummyimage.com/140x150/000000/ffffff&text=14" index="14">
<img src="https://dummyimage.com/200x150/000000/ffffff&text=2" index="2">
<img src="https://dummyimage.com/120x150/000000/ffffff&text=12" index="12">
<img src="https://dummyimage.com/130x150/000000/ffffff&text=13" index="13">
<img src="https://dummyimage.com/300x150/000000/ffffff&text=3" index="3">
<img src="https://dummyimage.com/400x150/000000/ffffff&text=4" index="4">
<img src="https://dummyimage.com/150x150/000000/ffffff&text=15" index="15">
<img src="https://dummyimage.com/500x150/000000/ffffff&text=5" index="5">
<img src="https://dummyimage.com/400x150/000000/ffffff&text=6" index="6">
<img src="https://dummyimage.com/170x150/000000/ffffff&text=17" index="17">
<img src="https://dummyimage.com/300x150/000000/ffffff&text=7" index="7">
<img src="https://dummyimage.com/160x150/000000/ffffff&text=16" index="16">
<img src="https://dummyimage.com/200x150/000000/ffffff&text=8" index="8">
<img src="https://dummyimage.com/180x150/000000/ffffff&text=18" index="18">
<img src="https://dummyimage.com/200x150/000000/ffffff&text=9" index="9">
</div>
Is there a simple way to achieve this sorting with CSS?