Skip to content
This repository has been archived by the owner on Jun 19, 2019. It is now read-only.

Support CSS' :nth-child pseudo-class #48

Closed
aidansteele opened this issue Mar 6, 2014 · 2 comments
Closed

Support CSS' :nth-child pseudo-class #48

aidansteele opened this issue Mar 6, 2014 · 2 comments

Comments

@aidansteele
Copy link
Contributor

One neat feature that the-other-styling-framework (:smile:) has is support for CSS's :nth-child pseudo-class. It comes in particularly handy for e.g. when giving alternating background colours to UITableViewCell.

What I am currently doing is something like

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;
{
  Subclass *c = (Subclass *)cell;
  [cell setBackgroundColor:[indexPath row] % 2 ? [c firstColor] : [c secondColor]];
}

And the stylesheet has:

Subclass {
    first-color: #fff;
    second-color: #ddd;
}

It'd be great if there was a better way to do this!

@keithnorm
Copy link
Contributor

The way web devs did this before :nth-child was invented was to append a class of "even" to the even table rows and define the styles for .even in your CSS file. Could do the same with Classy and would be more in line with what I think is great about the separation between style and content that Classy provides. I can work up an example if you want more details.

@dnedrow
Copy link
Member

dnedrow commented Oct 19, 2017

@keithnorm comment added to wiki.

@dnedrow dnedrow closed this as completed Oct 19, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants