If you're looking to style elements using only CSS, there's a way to select half of them... with a catch.
The only downside is that you need to know the exact total number of items in advance. It may work for 150 elements, but not for 151.
Check out this demo: http://jsfiddle.net/tcK3F/ (*)
Here's the basic CSS code:
/* Selecting half or more items. Up to 6 */
li:first-child:last-child,
li:nth-child(n+2):nth-last-child(-n+2),
li:nth-child(n+3):nth-last-child(-n+3),
li:nth-child(n+4):nth-last-child(-n+4),
li:nth-child(n+5):nth-last-child(-n+5),
li:nth-child(n+6):nth-last-child(-n+6) {
color: white;
background: darkblue;
}
/* Selecting half or less items. Up to 6 */
li:nth-child(n+2):last-child,
li:nth-child(n+3):nth-last-child(-n+2),
li:nth-child(n+4):nth-last-child(-n+3),
li:nth-child(n+5):nth-last-child(-n+4),
li:nth-child(n+6):nth-last-child(-n+5),
li:nth-child(n+7):nth-last-child(-n+6){
font-style: italic;
border: 2px solid red;
}
Inspired by:
This technique was inspired by André Luís and shared by Lea Verou in her post: Styling elements based on sibling count. I've tailored it for selecting specific portions of elements.
Quick breakdown:
Using :nth-last-child(-n+3)
selects the last 3 items within a parent; while :nth-child(n+3)
picks all items except the first 3. Combine them to target elements purely through CSS based on their position relative to others (or the number of children in a parent). However, be prepared to write out 75 of these selectors separated by commas if you want this method to apply to 150 elements... :)
Compatible with IE9+ (JS polyfills available)
(*)
first part of HTML code: even number of list items;
second part: odd number of list items
first CSS rule: targets the last N from a set of 2N items or the last N+1/2 items from 2N+1, styling them in white on blue (e.g., 3 items out of 5 or 6).
second CSS rule: will pick the last N from 2N items or last N-1/2 items from 2N+1 and style them with a red border and italic formatting (e.g., 2 items out of 4 or 5)