1. It should be in a list (and wrap freely)
2. Elements should always be centered.
3. By default, 3 elements per row.
4. Flexible enough for 6-8 elements.
5. It should be responsive.
The list seems simple enough, but in reality, items 1 and 5 are contradictory.
The original homepage had two rows of three elements (there were only 6 elements at the time), which were responsive, but overflowed their rows. The result was that each row of three elements rendered as two elements pushed to the left, and one lone element wrapped on the next line.
My fix for this was to throw all the elements in a list, so that they wrapped freely, maximizing the number of elements in a row. But this caused difficulties in centering elements.
The (lame) solution was to simply fix the over-flow problem, and have two rows of responsive elements. However this looks strange on a very wide monitor, as you have three super long elements in each row.
The ultimate solution would probably to use jQuery or MVC-templating to dynamically determine how many elements to put in each row based on the screen size, and handle margins accordingly. However, I felt like the PM might view this as "hackish" or too time-consuming, and so avoided it.
The Latest Build |
Mobile view |
A cool trick that I picked up this week was the use CSS selectors
:nth-child({ number expression | odd | even })
and
:nth-of-type(
{ number expression | odd | even })
I'll direct you here for a more detailed explanation and some nice samples:
http://css-tricks.com/the-difference-between-nth-child-and-nth-of-type/
But essentially they let you (in CSS) select elements of a parent using values and expressions. Notably, they let you select every other, every third, or every nth element. In my case, I used them to select the seventh element and give it a margin-left: 20%. This essentially centers the last row of elements. Neat right?
Link to the file in question:
http://kukuicup-rui.googlecode.com/svn/trunk/Bloggable/4-17-2012/home.html
and the CSS file:
http://kukuicup-rui.googlecode.com/svn/trunk/Bloggable/4-17-2012/css/home.css
No comments:
Post a Comment