Hello,
I would like your advice on this. I need to display inline unknown numbers of elements in a width fixed container. (let’s say 940px) There is a gap between these elements of 20px (with a margin-right) Problem is the last element in line jumps to the bottom even if there is visually enought place, because of that margin.
As I dont know the number of elements, I can’t play with .alpha/.omega css classes, or nth-child css rules…
Any possibility to achieve this ?
Thanks a lot!
You can use: ul li:last-child
or the .last() function in jQuery
or a javascript like this:
function highlightLastLI()
{
var liList, ulTag, liTag;
var ulList = document.getElementsByTagName("ul");
for (var i = 0; i < ulList.length; i++)
{
ulTag = ulList[i];
liList = ulTag.getElementsByTagName("li");
liTag = liList[liList.length - 1];
liTag.className = "lastchild";
}
}
Hope this works for you.
Hi,
This wont help, because I have only one UL, and I have a last element per line, not only last element. But I don’t know how to trace the supposed last element of every row.
ANy idea? Thank you
It should be better if you come up with a link, or a screenshot of your code 
A simple trick I use it to set a negative margin on the parent element, the same size as the gutter. So in your case, you should set a margin-right of -20px to your UL (if it has no fixed width). Thus the right margin of the last element of each line will fit into this space.
As far as I tested this, it works fine in all major browsers, but there may be some cases where it doesn’t.
Hope this helps! 
displayinline said
A simple trick I use it to set a negative margin on the parent element, the same size as the gutter. So in your case, you should set a margin-right of -20px to your UL (if it has no fixed width). Thus the right margin of the last element of each line will fit into this space.As far as I tested this, it works fine in all major browsers, but there may be some cases where it doesn’t.
Hope this helps!![]()
+1, I am using the same technique
Nth child Maybe? Works for me
Try to solve it with masonry(isotope).
rvision_ said
displayinline said+1, I am using the same technique
A simple trick I use it to set a negative margin on the parent element, the same size as the gutter. So in your case, you should set a margin-right of -20px to your UL (if it has no fixed width). Thus the right margin of the last element of each line will fit into this space.As far as I tested this, it works fine in all major browsers, but there may be some cases where it doesn’t.
Hope this helps!![]()
+2. Me too.
